How do you insert with a reverse_iterator

Essentially, you don't. See 19.2.5 in TCPPPL.

The reverse_iterator has a member called base() which will return a "regular" iterator. So the following code would work in your example:

l.insert(reverse.base(), 10);

Be careful though because the base() method returns the element one after the orginal reverse_iterator had pointed to. (This is so that reverse_iterators pointing at rbegin() and rend() work correctly.)


l.insert(reverse.base(), 10); will insert '10' at the end, given your definition of the 'reverse' iterator. Actually, l.rbegin().base() == l.end().

Tags:

C++

Stl