operator> (<utility>)

演算子の左側のオブジェクトがペアより大きい場合、テストは右側について説明します。

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

解説

_Leftpair のオブジェクトは _Rightpair のオブジェクトよりも厳密 _Left が等しくない場合は _Right.大きい呼びます。

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

使用例

// utility_op_gt.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 greater than the pair p2." << endl;
   else
      cout << "The pair p1 is not greater than the pair p2." << endl;

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

   if ( p1 > p4 )
      cout << "The pair p1 is greater than the pair p4." << endl;
   else
      cout << "The pair p1 is not greater than the pair p4." << endl;
}
  
  
  
  
  
  
  

必要条件

ヘッダー : <utility>

名前空間: std