public member function
<iterator>

std::reverse_iterator::operator++

(1)
reverse_iterator& operator++();
(2)
reverse_iterator  operator++(int);
Increment iterator position
Advances the reverse_iterator by one position.

Internally, the pre-increment version (1) decrements the base iterator kept by the object (as if applying operator-- to it).

The post-increment version (2) is implemented with a behavior equivalent to:
1
2
3
4
5
reverse_iterator operator++(int) {
  reverse_iterator temp = *this;
  ++(*this);
  return temp;
}

Parameters

none (the second version overloads the post-increment operator).

Return value

The pre-increment version (1) returns *this.
The post-increment version (2) returns the value *this had before the call.

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
27
28
// reverse_iterator example
#include <iostream>     // std::cout
#include <iterator>     // std::reverse_iterator
#include <vector>       // std::vector

int main () {
  std::vector<int> myvector;
  for (int i=0; i<10; i++) myvector.push_back(i);

  typedef std::vector<int>::iterator iter_type;
                                                         // ? 9 8 7 6 5 4 3 2 1 0 ?
  iter_type from (myvector.begin());                     //   ^
                                                         //         ------>
  iter_type until (myvector.end());                      //                       ^
                                                         //
  std::reverse_iterator<iter_type> rev_until (from);     // ^
                                                         //         <------
  std::reverse_iterator<iter_type> rev_from (until);     //                     ^

  std::cout << "myvector:";
  while (rev_from != rev_until) {
    std::cout << ' ' << *rev_from;
    ++rev_from;
  }
  std::cout << '\n';

  return 0;
}

Output:

myvector: 9 8 7 6 5 4 3 2 1 0


Data races

Modifies the object.
The iterator returned can be used to access or modify pointed elements.

Exception safety

Provides the same level of guarantee as decreasing (and copying, for (2)) the base iterator.

See also