operator< (<iterator>)
如果在运算符左侧的迭代器对象与右侧,的迭代器对象小于测试。
template<class RandomIterator>
bool operator<(
const reverse_iterator<RandomIterator>& _Left,
const reverse_iterator<RandomIterator>& _Right
);
参数
_Left
类型 iterator对象。_Right
类型 iterator对象。
返回值
true,如果表达式左侧的迭代器比在表达式的右侧迭代器小于; false,如果它是大于或等于右侧的迭代器。
备注
一个迭代对象与另一个小于,则解决在容器大于另一个迭代器对象格地址的前的元素。 一个迭代对象与另一个不小于,则解决元素和其他迭代器对象相同或在容器大于另一个迭代器对象格地址的后面的元素。
示例
// iterator_op_lt.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;
// Initializing reverse_iterators to the last element
vector <int>::reverse_iterator rVPOS1 = vec.rbegin ( ),
rVPOS2 = vec.rbegin ( );
cout << "The iterators rVPOS1& rVPOS2 initially point to the "
<< "first element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
if ( rVPOS1 < rVPOS2 )
cout << "The iterator rVPOS1 is less than"
<< " the iterator rVPOS2." << endl;
else
cout << "The iterator rVPOS1 is not less 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"
<< " the iterator rVPOS2." << endl;
else
cout << "The iterator rVPOS1 is not less than"
<< " the iterator rVPOS2." << endl;
}
要求
标头: <iterator>
命名空间: std