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::reverse_iterator

public member function
reverse_iterator();
explicit reverse_iterator (Iterator x)
template <class U>
  reverse_iterator (const reverse_iterator<U>& u);

Constructs reverse_iterator object

Constructs a reverse iterator object.

The first version (the default constructor) constructs an iterator pointing to no object.

The second version constructs a reverse_iterator from some original iterator. The behavior of the constructed object will be the same as the original, except that its directional interpretation will be the opposed one.

The third version constructs a reverse_iterator from some other reverse iterator. The constructed object will keep the same direction as the reverse iterator passed as constructor argument.

Parameters

x
An iterator object.
Iterator is reverse_iterator's template parameter (the type of the base iterator).
u
A reverse_iterator object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// reverse_iterator constructor example
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main () {
  vector<int> myvector;
  for (int i=0; i<10; i++) myvector.push_back(i);
  typedef vector<int>::iterator iter_int;
                                                   // ? 9 8 7 6 5 4 3 2 1 0 ?
  iter_int begin (myvector.begin());               //   ^                    
                                                   //         ------>
  iter_int end (myvector.end());                   //                       ^
                                                   //                      
  reverse_iterator<iter_int> rev_end (begin);      // ^                    
                                                   //         <------     
  reverse_iterator<iter_int> rev_iterator (end);   //                     ^
  while (rev_iterator < rev_end)
    cout << *rev_iterator++ << " ";
  cout << endl;
  return 0;
}



9 8 7 6 5 4 3 2 1 0

See also