operator<= (<iterator>)
测试在运算符的左侧的迭代器对象是否少于等于在运算符右侧的迭代器对象。
template<class RandomIterator>
bool operator<=(
const reverse_iterator<RandomIterator>& _Left,
const reverse_iterator<RandomIterator>& _Right
);
参数
_Left
类型迭代器对象。_Right
类型迭代器对象。
返回值
true,则该表达式左侧的迭代器是小于或等于迭代器在表达式的右侧;false,如果它比大于右侧的迭代器。
备注
迭代器对象一个小于或等于另一个,如果它寻址同一元素或容器中的其他迭代器对象处理的元素出现之前的元素。 一迭代器对象与另了极大,如果它寻址已在容器的其他迭代器对象处理的元素后面的元素。
示例
// iterator_op_le.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;
vector <int>::reverse_iterator rVPOS1 = vec.rbegin ( ) + 1,
rVPOS2 = vec.rbegin ( );
cout << "The iterator rVPOS1 initially points to the "
<< "second element\n in the reversed sequence: "
<< *rVPOS1 << "." << endl;
cout << "The iterator rVPOS2 initially points to the "
<< "first element\n in the reversed sequence: "
<< *rVPOS2 << "." << endl;
if ( rVPOS1 <= rVPOS2 )
cout << "The iterator rVPOS1 is less than or "
<< "equal to the iterator rVPOS2." << endl;
else
cout << "The iterator rVPOS1 is greater 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 or "
<< "equal to the iterator rVPOS2." << endl;
else
cout << "The iterator rVPOS1 is greater than "
<< "the iterator rVPOS2." << endl;
}
要求
头文件: <iterator>
命名空间: std