Compartir a través de


hash_multimap::key_comp

Note

This API is obsolete. The alternative is unordered_multimap Class.

Retrieves a copy of the comparison object used to order keys in a hash_multimap.

key_compare key_comp( ) const;

Return Value

Returns the function object that a hash_multimap uses to order its elements.

Remarks

The stored object defines the member function

bool operator(const Key& _Left**, const Key&** _Right**);**

which returns true if _Left precedes and is not equal to _Right in the sort order.

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_multimap_key_comp.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   
   hash_multimap <int, int, hash_compare<int, less<int> > > hm1;
   hash_multimap <int, int, hash_compare<int, less<int> > 
      >::key_compare kc1 = hm1.key_comp( ) ;
   bool result1 = kc1( 2, 3 ) ;
   if( result1 == true )
   {
      cout << "kc1( 2,3 ) returns value of true,\n"
           << "where kc1 is the function object of hm1.\n"
           << endl;
   }
   else   
   {
      cout << "kc1( 2,3 ) returns value of false,\n"
           << "where kc1 is the function object of hm1.\n"
           << endl;
   }

   hash_multimap <int, int, hash_compare<int, greater<int> > > hm2;
   hash_multimap <int, int, hash_compare<int, greater<int> > 
      >::key_compare kc2 = hm2.key_comp( );
   bool result2 = kc2( 2, 3 ) ;
   if( result2 == true )
   {
      cout << "kc2( 2,3 ) returns value of true,\n"
           << "where kc2 is the function object of hm2."
           << endl;
   }
   else   
   {
      cout << "kc2( 2,3 ) returns value of false,\n"
           << "where kc2 is the function object of hm2."
           << endl;
   }
}

Output

kc1( 2,3 ) returns value of true,
where kc1 is the function object of hm1.

kc2( 2,3 ) returns value of false,
where kc2 is the function object of hm2.

Requirements

Header: <hash_map>

Namespace: stdext

See Also

Reference

hash_multimap Class

Standard Template Library