Compartilhar via


reverse_iterator::operator-=

Subtrai um deslocamento especificado de reverse_iterator.

reverse_iterator<RandomIterator>& operator-=(
   difference_type _Off
);

Parâmetros

  • _Off
    O deslocamento a ser subtraído de reverse_iterator.

Comentários

Essa função de membro pode ser usada apenas se reverse_iterator satisfaz os requisitos para um iterador de acesso aleatório.

O operador avalia current + _Off. então retorna *this.

Exemplo

// reverse_iterator_op_suboff.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 ( 3 * i );
   }
   
   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-=2;      // Subtraction of an offset
   cout << "After the -2 offset, the iterator rVPOS1 now points\n"
        << " to the 2nd element from the last in the reversed sequence: "
        << *rVPOS1 << "." << endl;
}
  

Requisitos

Cabeçalho: <iterator>

Namespace: std

Consulte também

Referência

Classe reverse_iterator

Biblioteca de Modelos Padrão