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