operator+ (<iterator>)
Aggiunge un offset a un iteratore e restituisce move_iterator o reverse_iterator destinato all'elemento inserito nella nuova posizione offset.
template<class RandomIterator, class Diff>
move_iterator<RandomIterator> operator+(
Diff _Off,
const move_iterator<RandomIterator>& _Right
);
template<class RandomIterator>
reverse_iterator<RandomIterator> operator+(
Diff _Off,
const reverse_iterator<RandomIterator>& _Right
);
Parametri
_Off
Il numero di posizioni il move_iterator const o il reverse_iterator const deve essere sottoposto a offset._Right
Un iteratore da compensare.
Valore restituito
Restituisce la somma _Right + _Off.
Esempio
// 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;
}
Requisiti
intestazione: <iterator>
Spazio dei nomi: deviazione standard