operator--
public member function
reverse_iterator& operator--();
reverse_iterator operator--(int);
Decrease iterator position
Moves the reverse_iterator backwards by one position.
This in fact moves one position forward the base iterator kept internally.
Parameters
none (the second version is for the post-increment operator).
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 21 22 23 24 25 26 27
|
// 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);
typedef vector<int>::iterator iter_int;
reverse_iterator<iter_int> rev_begin (myvector.end());
reverse_iterator<iter_int> rev_end (myvector.begin());
reverse_iterator<iter_int> rev_iterator = rev_begin;
while ( rev_iterator != rev_end )
cout << *rev_iterator++ << " ";
cout << endl;
while ( rev_iterator != rev_begin )
cout << *(--rev_iterator) << " ";
cout << endl;
return 0;
}
|
Output:
9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9
|
See also
operator++ | Increment iterator position (public member function) |
operator-= | Retrocede iterator (public member function) |
|