Udostępnij za pośrednictwem


operator== (<iterator>)

Testy, jeśli obiekt iteratora po lewej stronie operatora jest równa obiektu iteratora po prawej stronie.

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

Parametry

  • _Left
    Obiekt typu iteratora.

  • _Right
    Obiekt typu iteratora.

Wartość zwracana

trueJeśli obiekty iteratora są równe; falseJeśli obiekty iteratora nie są równe.

Uwagi

Jeden obiekt iteratora jest równa innej, jeśli adres one te same elementy w pojemniku.Jeżeli punkt Iteratory dwóch różnych elementów w pojemniku, następnie nie są równe.

Pierwszy operatorów dwóch szablonu zwraca true, tylko jeśli oba _Left i _Right przechowywania samego iteratora.Trzeci operator szablonu zwraca wartość true, tylko jeśli oba _Left i _Right przechowywać ten sam wskaźnik strumienia.Czwarty szablonu operator zwraca _Left.equal (_Right).

Przykład

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

Wymagania

Nagłówek: <iterator>

Obszar nazw: std

Zobacz też

Informacje

Standardowa biblioteka szablonu