To implement `iterator_to` for anything except `vector`, you have to rely on a cast like this:
struct Node {
T t;
Node *next;
};
Node *node_from_t(T *t) {
return reinterpret_cast<Node *>(t);
}
int main() {
Node n;
assert(node_from_t(&n.t) == &n);
}
I'm not sure if this is well-defined. As long as `t` is the first member of `Node`, I think it might actually be well-defined; but I wouldn't bet money on it.
Problem is, library implementors tend to be extremely loath to rely on anything smelling of UB in their implementations.
my $.02,
–Arthur