operator+ (<iterator>)
Adds an offset to an iterator and returns a reverse_iterator addressing the inserted element at the new offset position.
template<class RandomIterator>
reverse_iterator<RandomIterator> operator+(
typename reverse_iterator<Iterator>::difference_type _Off,
const reverse_iterator<RandomIterator>& _Right
);
Parameters
_Off
The number of positions the const reverse_iterator is to be offset._Right
The const reverse_iterator that is to be offset.
Return Value
The sum _Right + _Off.
Example
// iterator_op_insert.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
int i;
vector<int> vec;
for (i = 0 ; i < 6 ; ++i ) {
vec.push_back ( 2 * i );
}
vector <int>::iterator vIter;
cout << "The initial vector vec is: ( ";
for ( vIter = vec.begin( ) ; vIter != vec.end( ); vIter++)
cout << *vIter << " ";
cout << ")." << endl;
vector <int>::reverse_iterator rVPOS1 = vec.rbegin ( );
cout << "The iterator rVPOS1 initially points to "
<< "the first element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
vector<int>::difference_type diff = 4;
rVPOS1 = diff +rVPOS1;
cout << "The iterator rVPOS1 now points to the fifth "
<< "element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
}
The initial vector vec is: ( 0 2 4 6 8 10 ).
The iterator rVPOS1 initially points to the first element
in the reversed sequence: 10.
The iterator rVPOS1 now points to the fifth element
in the reversed sequence: 2.
Requirements
Header: <iterator>
Namespace: std