hash_set::value_comp

说明说明

此 API 已过时。另一种方法是 unordered_set Class

检索在 hash_set 使用于顺序元素值比较对象的副本。

value_compare value_comp( ) const;

返回值

返回 hash_set 使用对其元素,是模板参数 Compare的函数对象。

有关 Compare的更多信息,请参见 hash_set Class 主题的"备注"节。

备注

存储的对象定义成员函数:

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

后者返回 true if _xVal precedes and is not equal to _yVal 不相等按排序顺序。

请注意 value_comparekey_compare 是模板参数的 Compare同义词。两个类型为 hash_set 和 hash_multiset 选件类提供,它们用于 hash_map 和 hash_multimap 选件类的兼容性是相同的,因此,它们是不同的。

在 Visual C++ .NET 2003 中,<hash_map><hash_set> 标头文件的成员中不再标准,命名空间,而是将 stdext 命名空间。有关更多信息,请参见 stdext 命名空间

示例

// hash_set_value_comp.cpp
// compile with: /EHsc
#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.

要求

标头: <hash_set>

命名空间: stdext

请参见

参考

hash_set Class

标准模板库