public member function
<iterator>
reverse_iterator& operator--();reverse_iterator operator--(int);
Decrement iterator position
Decreases the reverse_iterator by one position.
Internally, the pre-decrement version (1) increments the base iterator kept by the object (as if applying operator++ to it).
The post-decrement version (2) is implemented with a behavior equivalent to
1 2 3 4 5
|
reverse_iterator operator--(int) {
reverse_iterator temp = *this;
--(*this);
return temp;
}
|
参数
none (the second version overloads the post-decrement operator).
返回值
The pre-decrement version (1) returns *this
.
The post-decrement version (2) returns the value *this
had before the call.
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
// 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);
typedef std::vector<int>::iterator iter_type;
std::reverse_iterator<iter_type> rev_begin (myvector.end());
std::reverse_iterator<iter_type> rev_end (myvector.begin());
std::reverse_iterator<iter_type> rev_iterator = rev_begin;
while ( rev_iterator != rev_end )
std::cout << *rev_iterator++ << ' ';
std::cout << '\n';
while ( rev_iterator != rev_begin )
std::cout << *(--rev_iterator) << ' ';
std::cout << '\n';
return 0;
}
|
输出
9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9
|
数据竞争
修改对象。
返回的迭代器可用于访问或修改指向的元素。
异常安全
Provides the same level of guarantee as increasing (and copying, for (2)) the base iterator.