演算子の左側のオブジェクトがペアと等しいテストは右側について説明します。
template<class Type1, class Type2>
bool operator==(
const pair<Type1, Type2>& _Left,
const pair<Type1, Type2>& _Right
);
パラメーター
_Left
型のオブジェクト pair._Right
pair 型のオブジェクト。
戻り値
ペアが等しい場合true ; pair、がではない false。
解説
1 組は、それぞれの要素のそれぞれが等しい別のペアと同じです。関数は _Leftを返します。first の == _Right。first の && _Left。second の == _Right。second。2 セットは、1 回目または 2 番目の要素が他のペアの対応する要素と等しく等しくありません。
使用例
// utility_op_eq.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, 1.11e-1 );
p2 = make_pair ( 1000, 1.11e-3 );
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 pairs p1 and p2 are equal." << endl;
else
cout << "The pairs p1 and p2 are not equal." << endl;
if ( p1 == p3 )
cout << "The pairs p1 and p3 are equal." << endl;
else
cout << "The pairs p1 and p3 are not equal." << endl;
}
出力
The pair p1 is: ( 10, 0.111 ).
The pair p2 is: ( 1000, 0.00111 ).
The pair p3 is: ( 10, 0.111 ).
The pairs p1 and p2 are not equal.
The pairs p1 and p3 are equal.
必要条件
ヘッダー : <utility>
名前空間: std