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-).

参数

n
偏移的元素数量。
Member type difference_type is an alias of Iterator's own difference type.
rev_it
Reverse iterator.

返回值

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

示例

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;
}

输出

The fourth element from the end is: 6


数据竞争

The arguments are accessed.
返回的迭代器可用于访问或修改元素。

异常安全

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

另见