If I have the end
iterator
to a container, but I want to get a raw pointer to that is there a way to accomplish this?
Say I have a container: foo
. I cannot for example do this: &*foo.end()
because it yields the runtime error:
Vector iterator not dereferencable
I can do this but I was hoping for a cleaner way to get there: &*foo.begin() + foo.size()
.
EDIT:
This is not a question about how to convert an iterator to a pointer in general (obviously that's in the question), but how to specifically convert the end iterator to a pointer. The answers in the "duplicate" question actually suggest dereferencing the iterator. The end iterator cannot be dereferenced without seg-faulting.