Compartir a través de


operator== (<iterator>)

Comprueba si el objeto de iterador en el lado izquierdo del operador es igual al objeto de iterador en el lado derecho.

template<class RandomIterator1, class RandomIterator2>
    bool operator==(
        const move_iterator<RandomIterator1>& _Left,
        const move_iterator<RandomIterator2>& _Right
    );
template<class RandomIterator1, class RandomIterator2>
    bool operator==(
        const reverse_iterator<RandomIterator1>& _Left,
        const reverse_iterator<RandomIterator2>& _Right
   );
template<class Type, class CharType, class Traits, class Distance>
   bool operator==(
      const istream_iterator<Type, CharType, Traits, Distance>& _Left,
      const istream_iterator<Type, CharType, Traits, Distance>& _Right
   );
template<class CharType, class Tr>
   bool operator==(
      const istreambuf_iterator<CharType, Traits>& _Left,
      const istreambuf_iterator<CharType, Traits>& _Right
);

Parámetros

  • _Left
    Un objeto de iterador con tipo.

  • _Right
    Un objeto de iterador con tipo.

Valor devuelto

true si los objetos de iterador son iguales; false si los objetos de iterador no son iguales.

Comentarios

Un objeto de iterador es igual a otro si dirigen los mismos elementos en un contenedor.Si el punto de dos iteradores a distintos elementos en un contenedor, a ellas no son iguales.

Los dos primeros operadores de la plantilla devuelve true solo si _Left y _Right almacenan el mismo iterador.El tercer operador de la plantilla devuelve true solo si _Left y _Right almacenan el mismo puntero de secuencia.el cuarto operador de la plantilla devuelve _Left.equal (_Right).

Ejemplo

// iterator_op_eq.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 ( 2 * i );
   }
   
   vector <int>::iterator vIter;

   cout << "The vector vec is: ( ";
   for ( vIter = vec.begin( ) ; vIter != vec.end( ); vIter++)
      cout << *vIter << " ";
   cout << ")." << endl;

   // Initializing reverse_iterators to the last element
   vector <int>::reverse_iterator rVPOS1 = vec.rbegin ( ), 
           rVPOS2 = vec.rbegin ( );
   
   cout << "The iterator rVPOS1 initially points to the first "
        << "element\n in the reversed sequence: "
        << *rVPOS1 << "." << endl;

   if ( rVPOS1 == rVPOS2 )
      cout << "The iterators are equal." << endl;
   else
      cout << "The iterators are not equal." << endl;

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

   if ( rVPOS1 == rVPOS2 )
      cout << "The iterators are equal." << endl;
   else
      cout << "The iterators are not equal." << endl;
}
  
  
  
  
  

Requisitos

encabezado: <iterador>

espacio de nombres: std

Vea también

Referencia

Biblioteca de plantillas estándar