Compartilhar via


operator+ (<iterator>)

Adds an offset to an iterator and returns a move_iterator or a reverse_iterator addressing the inserted element at the new offset position.

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
    );

Parameters

  • _Off
    The number of positions the const move_iterator or const reverse_iterator is to be offset.

  • _Right
    The iterator to be offset.

Return Value

Returns 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

See Also

Reference

Standard Template Library

Other Resources

<iterator> Members