Partager via


operator== (hash_map)

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

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

Parameters

  • _Left
    An object of type hash_map.

  • _Right
    An object of type hash_map.

Return Value

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

Remarks

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

In Visual C++ .NET 2003, members of the <hash_map> and <hash_set> header files are no longer in the std namespace, but rather have been moved into the stdext namespace. See The stdext Namespace for more information.

Example

// hash_map_op_eq.cpp
// compile with: /EHsc
#define _DEFINE_DEPRECATED_HASH_CLASSES 0
#include <hash_map>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_map <int, int> hm1, hm2, hm3;
   int i;
   typedef pair <int, int> Int_Pair;

   for ( i = 0 ; i < 3 ; i++ )
   {
      hm1.insert ( Int_Pair ( i, i ) );
      hm2.insert ( Int_Pair ( i, i * i ) );
      hm3.insert ( Int_Pair ( i, i ) );
   }

   if ( hm1 == hm2 )
      cout << "The hash_maps hm1 and hm2 are equal." << endl;
   else
      cout << "The hash_maps hm1 and hm2 are not equal." << endl;

   if ( hm1 == hm3 )
      cout << "The hash_maps hm1 and hm3 are equal." << endl;
   else
      cout << "The hash_maps hm1 and hm3 are not equal." << endl;
}

The hash_maps hm1 and hm2 are not equal.
The hash_maps hm1 and hm3 are equal.

Requirements

Header: <hash_map>

Namespace: stdext

See Also

Concepts

<hash_map> Members

Standard Template Library