Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
iterator
advance
back_inserter
distance
front_inserter
inserter
iterator
iterator_traits
iterator categories:
BidirectionalIterator
ForwardIterator
InputIterator
OutputIterator
RandomAccessIterator
predefined iterators:
back_insert_iterator
front_insert_iterator
insert_iterator
istreambuf_iterator
istream_iterator
ostreambuf_iterator
ostream_iterator
reverse_iterator
reverse_iterator
reverse_iterator::reverse_iterator
member functions:
base
operator*
operator+
operator++
operator+=
operator-
operator--
operator-=
operator->
operator[]


reverse_iterator

class template
<iterator>
template <class Iterator> class reverse_iterator;

Reverse iterator

This class reverses the direction a bidirectional or random access iterator iterates through a range.

A copy of the original iterator (the base iterator) is kept internally and used to reflect all operations performed on the reverse_iterator: whenever the reverse_iterator is incremented, its base iterator is decreased, and vice versa. The base iterator can be obtained at any moment by calling member base.

Notice however that when an iterator is reversed, the reversed version does not point to the same element in the range, but to the one preceding it. This is so, in order to arrange for the past-the-end element of a range: An iterator pointing to a past-the-end element in a range, when reversed, is changed to point to the last element (not past it) of the range (this would be the first element of the range if reversed). And if an iterator to the first element in a range is reversed, the reversed iterator points to the element before the first element (this would be the past-the-end element of the range if reversed).

Member types

memberdefinition in reverse_iteratordescription
iterator_categoryiterator_traits<Iterator>::iterator_categoryPreserves Iterator's category
value_typeiterator_traits<Iterator>::value_typePreserves Iterator's value type
difference_typeiterator_traits<Iterator>::difference_typePreserves Iterator's difference type
pointeriterator_traits<Iterator>::pointerPreserves Iterator's pointer type
referenceiterator_traits<Iterator>::referencePreserves Iterator's reference type
iterator_typeIteratorIterator's type

Member functions


Overloaded global operator functions

The operators ==, <, !=, >, >=, <=, + and - are overloaded for reverse_iterator as argument, each with the expected meaning for an iterator.