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[]


operator+

public member function
reverse_iterator operator+ (difference_type n) const;

Addition operator

Returns a reverse iterator pointing to n elements after the element the object points to.

A global overload for operator+ with the same behavior also exists for the case where the reverse_iterator is the right-hand side element of the sum:
1
2
3
4
template <class Iterator>
  reverse_iterator<Iterator> operator+ (
    typename reverse_iterator<Iterator>::difference_type n,
    const reverse_iterator<Iterator>& x);


Parameters

n
Number of elements to offset.
difference_type is a member type defined as an alias of the base iterator's own difference type (generally, a integral 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
20
// reverse_iterator::operator+ 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);	// myvector: 0 1 2 3 4 5 6 7 8 9
  typedef vector<int>::iterator iter_int;
  reverse_iterator<iter_int> rev_iterator;
  
  rev_iterator = myvector.rbegin() +3;
  cout << "The fourth element from the end is : " << *rev_iterator << endl;
  return 0;
}


Output:

The fourth element from the end is : 6

See also