operator== (<utility>)

如果在运算符的左边对对象与右侧,对对象相等测试。

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

参数

  • _Left
    类型 **pair.**对象

  • _Right
    pair 类型的对象。

返回值

true,如果对相等; false,如果 pair的不相等。

备注

如果它们的每个单个元素相等,一个用于对相等到另一个对。函数返回 _Left。first == _Right。first && _Left。second == _Right。second。如果第一个或第二个元素的一个与其他的对应元素不相等匹配,两对不相等。

示例

// 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;
}

Output

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