operator== (<iterator>)

测试在运算符的左侧的迭代器对象是否等于在运算符右侧的迭代器对象。

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

参数

  • _Left
    类型迭代器对象。

  • _Right
    类型迭代器对象。

返回值

true,则迭代器对象相等;false,则迭代器对象不等于。

备注

如果解决这些问题在容器元素相同的元素,一个迭代器对象相等到另一个。 如果对不同元素的两个迭代器指向容器中,则它们不相等。

只有当 _Left 和 _Right 存储同一迭代器,那么两个模板运算符返回 true。 只有当 _Left 和 _Right 相同流存储指针,第三个模板运算符返回 true。 第四模板运算符返回 _Left.equal (_Right)。

示例

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

要求

头文件: <iterator>

命名空间: std

请参见

参考

标准模板库