It does not. However, reverse iterators provide a base()
method to obtain a forward iterator. Take note that the returned forward iterator points to the element following the element the reverse iterator points to.
Or, to put it another way, .rbegin().base() == .end()
and .rend().base() == .begin()
So the fixed code would look like this:
some_vector.erase(
(++(some_vector.rbegin())).base(),
some_vector.rbegin().base()
);
Note that we have to swap the order of the iterators around since they are reverse iterators; the second argument must be an iterator that follows the first iterator in the sequence, but without swapping the order of the reverse iterators this wouldn't be true. So if we have two reverse iterators a
and b
, and b >= a
then we can use this idiom for erase()
:
container.erase(b.base(), a.base());
More generally, it holds for the range of reverse iterators [a, b) that the range [b.base(), a.base()) iterates the same sequence of elements in the opposite order.