class template
std::reverse_iterator
<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
member | definition in reverse_iterator | description |
iterator_category | iterator_traits<Iterator>::iterator_category | Preserves Iterator's category |
value_type | iterator_traits<Iterator>::value_type | Preserves Iterator's value type |
difference_type | iterator_traits<Iterator>::difference_type | Preserves Iterator's difference type |
pointer | iterator_traits<Iterator>::pointer | Preserves Iterator's pointer type |
reference | iterator_traits<Iterator>::reference | Preserves Iterator's reference type |
iterator_type | Iterator | Iterator's type |
Member functions
- base
- Return base iterator (public member function)
- operator*
- Dereference iterator (public member function)
- operator+
- Addition operator (public member function)
- operator++
- Increment iterator position (public member function)
- operator+=
- Advance iterator (public member function)
- operator-
- Subtraction operator (public member function)
- operator--
- Decrease iterator position (public member function)
- operator-=
- Retrocede iterator (public member function)
- operator->
- Dereference iterator (public member function)
- operator[]
- Dereference iterator with offset (public member function)
Overloaded global operator functions
The operators
==,
<,
!=,
>,
>=,
<=,
+ and
- are overloaded for
reverse_iterator as argument, each with the expected meaning for an iterator.