function template
<iterator>

std::operator+ (reverse_iterator)

template <class Iterator>
  reverse_iterator<Iterator> operator+ (
             typename reverse_iterator<Iterator>::difference_type n,
             const reverse_iterator<Iterator>& rev_it);
Addition operator
Returns a reverse iterator pointing to the element located n positions away from the element pointed to by rev_it.

The function returns the same as: rev_it+n (see reverse_iterator::operator+).

This operator is also overloaded as a member function to return a reverse iterator offset by -n element positions (see reverse_iterator::operator-).

Parameters

n
Number of elements to offset.
Member type difference_type is an alias of Iterator's own difference type.
rev_it
Reverse iterator.

Return value

An iterator pointing to the element n positions away from rev_it.

Example

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

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

  std::reverse_iterator<iter_type> rev_it;

  rev_it = 3 + myvector.rbegin();

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

  return 0;
}


Output:

The fourth element from the end is: 6

Data races

The arguments are accessed.
The iterator returned can be used to access or modify elements.

Exception safety

Provides the same level of guarantee as operator+ applied on Iterator.

See also