public member function
<iterator>

std::reverse_iterator::operator+=

reverse_iterator& operator+= (difference_type n);
Advance iterator
Advances the reverse_iterator by n element positions.

Internally, the function decreases by n the base iterator kept by the object (as if applying operator-= to it).

Note that this function requires the base iterator to be a random-access iterator.

Parameters

n
Number of elements to offset.
Member type difference_type is an alias of the base iterator's own difference type.

Return value

The reverse iterator itself (*this).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// reverse_iterator::operator+= 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);	// myvector: 0 1 2 3 4 5 6 7 8 9

  typedef std::vector<int>::iterator iter_type;

  std::reverse_iterator<iter_type> rev_iterator = myvector.rbegin();

  rev_iterator += 2;

  std::cout << "The third element from the end is: " << *rev_iterator << '\n';

  return 0;
}


Output:

The third element from the end is: 7

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 the base iterator.

See also