Share via


operator<= (<utility>)

演算子の左側の pair オブジェクトが対以下である場合、テストは右側に表示します。

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

パラメーター

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

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

戻り値

演算子の左側の pair が演算子の右側の pair 以下かどうかtrue ; それ false

解説

ペアの比較では、値のいずれか 2 つがタプルの最初の要素に優先順位が最も高くなります。 その場合、比較の結果はペアの比較結果しまいます。 最初の要素の値が異なる場合、2 番目の要素の値が比較され、比較結果はペアの比較結果しまいます。

使用例

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

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

   p1 = make_pair ( 10, 2.22e-1 );
   p2 = make_pair ( 100, 1.11e-1 );
   p3 = make_pair ( 10, 1.11e-1 );
   p4 = make_pair ( 10, 2.22e-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;
   cout << "The pair p4 is: ( " << p4.first << ", " 
        << p4.second << " )." << endl << endl;

   if ( p1 <= p2 )
      cout << "The pair p1 is less than or equal to the pair p2." << endl;
   else
      cout << "The pair p1 is greater than the pair p2." << endl;

   if ( p1 <= p3 )
      cout << "The pair p1 is less than or equal to the pair p3." << endl;
   else
      cout << "The pair p1 is greater than the pair p3." << endl;

   if ( p1 <= p4 )
      cout << "The pair p1 is less than or equal to the pair p4." << endl;
   else
      cout << "The pair p1 is greater than the pair p4." << endl;
}
  

必要条件

ヘッダー: <ユーティリティ>

名前空間: std