다음을 통해 공유


operator== (map)

Tests if the map object on the left side of the operator is equal to the map object on the right side.

bool operator==( 
   const map <Key, Type, Traits, Allocator>& _Left, 
   const map <Key, Type, Traits, Allocator>& _Right 
);

Parameters

  • _Left
    An object of type map.

  • _Right
    An object of type map.

Return Value

true if the map on the left side of the operator is equal to the map on the right side of the operator; otherwise false.

Remarks

The comparison between map objects is based on a pairwise comparison of their elements. Two maps are equal if they have the same number of elements and their respective elements have the same values. Otherwise, they are unequal.

Example

// map_op_eq.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
   using namespace std;
   map < int, int > m1, m2, m3;
   int i;
   typedef pair < int, int > Int_Pair;

   for ( i = 0 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i ) );
   }

   if ( m1 == m2 )
      cout << "The maps m1 and m2 are equal." << endl;
   else
      cout << "The maps m1 and m2 are not equal." << endl;

   if ( m1 == m3 )
      cout << "The maps m1 and m3 are equal." << endl;
   else
      cout << "The maps m1 and m3 are not equal." << endl;
}
The maps m1 and m2 are not equal.
The maps m1 and m3 are equal.

Requirements

Header: <map>

Namespace: std

See Also

Reference

Standard Template Library