Udostępnij za pośrednictwem


operator+ (<iterator>)

Dodaje przesunięcie do iterację i zwraca move_iterator lub reverse_iterator adresowania wstawiony element w nowe położenie przesunięcia.

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

Parametry

  • _Off
    Liczba pozycji const move_iterator lub const reverse_iterator jest przesunięcia.

  • _Right
    Iteratora przesunięcia.

Wartość zwracana

Returns the sum _Right + _Off.

Przykład

// 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;
}
  
  
  

Wymagania

Nagłówek: <iterator>

Obszar nazw: std

Zobacz też

Informacje

Standardowa biblioteka szablonu