reverse_iterator::operator--
Decrements the reverse_iterator to the previous element.
reverse_iterator<RandomIterator>& operator--( );
reverse_iterator<RandomIterator> operator--( int );
Return Value
The first operator returns the predecremented reverse_iterator and the second, the postdecrement operator, returns a copy of the decremented reverse_iterator.
Remarks
This member function may only be used if the reverse_iterator satisfies the requirements for a bidirectional iterator.
Example
// reverse_iterator_op_decr.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
int i;
vector<int> vec;
for (i = 1 ; i < 6 ; ++i )
{
vec.push_back ( 2 * i - 1 );
}
vector <int>::iterator vIter;
cout << "The vector vec is: ( ";
for ( vIter = vec.begin( ) ; vIter != vec.end( ); vIter++)
cout << *vIter << " ";
cout << ")." << endl;
vector <int>::reverse_iterator rvIter;
cout << "The vector vec reversed is: ( ";
for ( rvIter = vec.rbegin( ) ; rvIter != vec.rend( ); rvIter++)
cout << *rvIter << " ";
cout << ")." << endl;
// Initializing reverse_iterators to the first element
vector <int>::reverse_iterator rVPOS1 = vec.rend ( ) - 1;
cout << "The iterator rVPOS1 initially points to the last "
<< "element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
rVPOS1--; // postdecrement, predecrement: --rVPSO1
cout << "After the decrement, the iterator rVPOS1 points\n"
<< " to the next-to-last element in the reversed sequence: "
<< *rVPOS1 << "." << endl;
}
The vector vec is: ( 1 3 5 7 9 ).
The vector vec reversed is: ( 9 7 5 3 1 ).
The iterator rVPOS1 initially points to the last element
in the reversed sequence: 1.
After the decrement, the iterator rVPOS1 points
to the next-to-last element in the reversed sequence: 3.
Requirements
Header: <iterator>
Namespace: std