hash_multiset::key_comp

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

key_compare key_comp( ) const;

Return Value

Returns the hash_multiset template parameter Traits, which contains function objects that are used to hash and to order the elements of the container.

For more information on Traits see the hash_multiset Class topic.

Remarks

The stored object defines a member function:

bool operator(const Key& _xVal, const Key& _yVal);

which returns true if _xVal precedes and is not equal to _yVal in the sort order.

Note that both key_compare and value_compare are synonyms for the template parameter Traits. Both types are provided for the hash_multiset and hash_multiset classes, where they are identical, for compatibility with the hash_map and hash_multimap classes, where they are distinct.

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_multiset_key_comp.cpp
// compile with: /EHsc
#define _DEFINE_DEPRECATED_HASH_CLASSES 0
#include <hash_set>
#include <iostream>

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

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

Output

kc1( 2,3 ) returns value of true, where kc1 is the function object of hms1.
kc2( 2,3 ) returns value of false, where kc2 is the function object of hms2.

Requirements

Header: <hash_set>

Namespace: stdext

See Also

Reference

hash_multiset Class

Standard Template Library

Other Resources

hash_multiset Members