with difficulty
Which is exactly why they are provided by Standard
containers. Effectively they dereference the iterator value 'before'
before the one being 'held' that means when they get to the 'first'
(i.e. rend()) they stop because there is nothing before it.
Note that long before the STL, it was standard practice in C to use half
open intervals -- the standard loop over an array, for example, was:
for ( int i = 0 ; i < arraySize ; i ++ )
doSomethingWith( array[ i ] ) ;
Applying this logic to reverse "iterators" (where iterator is used to
mean anything used to designate an element, including indexes): the
iterator designates the top end, which is the open open end of the
interval. Thus, the standard reverse loop was:
for ( int i = arraySize ; i > 0 ; i -- )
doSomethingWith( array[ i - 1 ] ) ;
At least, that was the way I always wrote it, even back in my C days.
In the case of a while loop, when iterating up, the incrementation is at
the end of the loop; when iterating down, the decrementation is the
first instruction in the loop.
All of this seems something trivially obvious to me. The while loop
handling was the standard procedure in Pascal and Modula-2 (before I
started using C) -- for loops are somewhat limited in those languages,
and aren't used much.
What's the point in starting array indexes at 0 otherwise?
Anyway, reverse iterators in the STL only encapsulate this standard
technique. They are nice syntactic sugar, but there's hardly any "with
difficulty" -- they just use the standard idioms that every one has used
for ages.