operator< (<utility>)

演算子の左側のオブジェクトがある場合、これらのペアより小さいテストは右側について説明します。

template<class Type1, class Type2>
   bool operator<(
      const pair<Type1, Type2>& _Left,
      const pair<Type1, Type2>& _Right
   );

パラメーター

  • _Left
    演算子の左側の pair 型のオブジェクト。

  • _Right
    演算子の右側の pair 型のオブジェクト。

戻り値

演算子の左側の pair が null の場合、演算子の右側の pair 未満true ; それ false

解説

_Leftpair のオブジェクトは _Left が未満 _Right.と等しくない場合 _Rightpair のオブジェクトより厳密により小さいと呼ばれます

ペアの比較では、値の 2 段階の最初の要素で最も優先順位が最も高くなります。それらが異なる場合、比較の結果は、二つの比較の結果取得されます。最初の要素の値が異なる場合、2 番目の要素の値が比較され、比較結果は、二つの比較の結果取得されます。

使用例

// utility_op_lt.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>

int main( )
{
   using namespace std;
   pair <int, double> p1, p2, p3;

   p1 = make_pair ( 10, 2.22e-1 );
   p2 = make_pair ( 100, 1.11e-1 );
   p3 = make_pair ( 10, 1.11e-1 );

   cout.precision ( 3 );
   cout << "The pair p1 is: ( " << p1.first << ", " 
        << p1.second << " )." << endl;
   cout << "The pair p2 is: ( " << p2.first << ", " 
        << p2.second << " )." << endl;
   cout << "The pair p3 is: ( " << p3.first << ", " 
        << p3.second << " )." << endl << endl;

   if ( p1 < p2 )
      cout << "The pair p1 is less than the pair p2." << endl;
   else
      cout << "The pair p1 is not less than the pair p2." << endl;

   if ( p1 < p3 )
      cout << "The pair p1 is less than the pair p3." << endl;
   else
      cout << "The pair p1 is not less than the pair p3." << endl;
}
  
  
  
  
  

必要条件

ヘッダー : <utility>

名前空間: std