in a custom reverse vector iterator you can’t see the first element

rBegin() returns an iterator to the first element:

ReverseIterator rBegin() { return ReverseIterator(data + size); }

But it’s pointing one element beyond the end and can’t be dereferenced. You need to dereference the element before it.

You could therefore adjust the dereference operator in the VectorRevIterator version:

ReferenceType operator*() const { return *std::prev(ptr); }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top