Leggere in inglese

Condividi tramite


operator<= (<iterator>)

Consente di verificare se l'oggetto iteratore sul lato sinistro dell'operatore è minore o uguale all'oggetto iteratore sul lato destro.

template<class RandomIterator> 
   bool operator<=( 
      const reverse_iterator<RandomIterator>& _Left, 
      const reverse_iterator<RandomIterator>& _Right 
   );

Parametri

  • _Left
    Un oggetto l'iteratore del tipo.

  • _Right
    Un oggetto l'iteratore del tipo.

Valore restituito

setrue l'iteratore a sinistra dell'espressione è minore o uguale a quelloiteratore sul lato destro dell'espressione; false se è maggiore dell'iteratore a destra.

Note

Un oggetto di iteratore è minore o uguale a un altro se è destinata allo stesso elemento o un elemento che si verifica nel contenitore che l'elemento indirizzato dall'altro oggetto di iteratore. Un oggetto di iteratore è superiore a un altro se è destinata a un elemento che si verifica più avanti nel contenitore che l'elemento indirizzato dall'altro oggetto di iteratore.

Esempio

// iterator_op_le.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 ( ) + 1, 
           rVPOS2 = vec.rbegin ( );
   
   cout << "The iterator rVPOS1 initially points to the "
           << "second element\n in the reversed sequence: "
           << *rVPOS1 << "." << endl;

   cout << "The iterator rVPOS2 initially points to the "
           << "first element\n in the reversed sequence: "
           << *rVPOS2 << "." << endl;

   if ( rVPOS1 <= rVPOS2 )
      cout << "The iterator rVPOS1 is less than or "
              << "equal to the iterator rVPOS2." << endl;
   else
      cout << "The iterator rVPOS1 is greater than "
              << "the iterator rVPOS2." << endl;

   rVPOS2++;
   cout << "The iterator rVPOS2 now points to the second "
           << "element\n in the reversed sequence: "
           << *rVPOS2 << "." << endl;

   if ( rVPOS1 <= rVPOS2 )
      cout << "The iterator rVPOS1 is less than or "
              << "equal to the iterator rVPOS2." << endl;
   else
      cout << "The iterator rVPOS1 is greater than "
              << "the iterator rVPOS2." << endl;
}
  

Requisiti

Intestazione: <iteratore>

Spazio dei nomi: std

Vedere anche

Riferimenti

Libreria di modelli standard