John said:
reverse_iterators have a member function called base() which returns the
equivalent iterator. Use that.
john
From TC++PL 3:
"A reverse_iterator is implemented using an iterator called current.
That iterator can (only) point to the elements of its sequence plus its
one-past-the-end element. However, the reverse_iterator’s
one-past-the-end element is the original sequence’s (inaccessible)
one-before-the-beginning element.
Thus, to avoid access violations, current points to the element after
the one the reverse_iterator refers to. This implies that * returns the
value *(current-1) and that ++ is implemented using -- on current".
In other words the base() of reverse_iterator returns current, which is
one after the element that reverse_iterator points, under the regular
iterator point of view.
So if you want to point to the same element with reverse_iterator,
provided that reverse_iterator does not point at "one past the end"
element of its view, you can do for example:
vector<int>::reverse_iterator rp = whatever;
// Not to be used for a reverse_iterator pointing to "one past the end"
// element under its point of view.
vector<int>::iterator p = rp.base()-1;