Partager via


hash_set::value_comp

Retrieves a copy of the comparison object used to order element values in a hash_set.

value_compare value_comp( ) const;

Return Value

Returns the function object that a hash_set uses to order its elements, which is the template parameter Compare.

For more information on Compare, see the Remarks section of the hash_set Class topic.

Remarks

The stored object defines the 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 value_compare and key_compare are synonyms for the template parameter Compare. Both types are provided for the hash_set 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_set_value_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_set <int, hash_compare < int, less<int> > > hs1;
   hash_set <int, hash_compare < int, less<int> >  >::value_compare
      vc1 = hs1.value_comp( );
   bool result1 = vc1( 2, 3 );
   if( result1 == true )
   {
      cout << "vc1( 2,3 ) returns value of true, "
           << "where vc1 is the function object of hs1."
           << endl;
   }
   else
   {
      cout << "vc1( 2,3 ) returns value of false, "
           << "where vc1 is the function object of hs1."
           << endl;
   }

   hash_set <int, hash_compare < int, greater<int> > > hs2;
   hash_set<int, hash_compare < int, greater<int> > >::value_compare
      vc2 = hs2.value_comp( );
   bool result2 = vc2( 2, 3 );
   if( result2 == true )
   {
      cout << "vc2( 2,3 ) returns value of true, "
           << "where vc2 is the function object of hs2."
           << endl;
   }
   else
   {
      cout << "vc2( 2,3 ) returns value of false, "
           << "where vc2 is the function object of hs2."
           << endl;
   }
}

Output

vc1( 2,3 ) returns value of true, where vc1 is the function object of hs1.
vc2( 2,3 ) returns value of false, where vc2 is the function object of hs2.

Requirements

Header: <hash_set>

Namespace: stdext

See Also

Concepts

hash_set Class

hash_set Members

Standard Template Library