operator< (<iterator>)

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

template<class RandomIterator> 
   bool operator<( 
      const reverse_iterator<RandomIterator>& _Left, 
      const reverse_iterator<RandomIterator>& _Right 
   );

参数

  • _Left
    类型 迭代器对象。

  • _Right
    类型 迭代器对象。

返回值

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

请参见

参考

标准模板库