public member function
<iterator>

std::reverse_iterator::operator-=

reverse_iterator& operator-= (difference_type n);
Retrocede iterator
Descreases the reverse_iterator by n element positions.

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

请注意,此函数要求*基迭代器*是*随机访问迭代器*。

参数

n
偏移的元素数量。
成员类型 difference_type基迭代器自身差值类型的别名。

返回值

The reverse iterator itself (*this).

示例

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.rend();

  rev_iterator -= 4;

  std::cout << "rev_iterator now points to: " << *rev_iterator << '\n';

  return 0;
}

输出

rev_iterator now points to: 3


数据竞争

修改对象。
返回的迭代器可用于访问或修改指向的元素。

异常安全

Provides the same level of guarantee as increasing the base iterator.

另见