备注
此 API 已过时。替代为 unordered_set 类。
哈希检索的字符复制对象用于散列和按 hash_set 元素的键值。
key_compare key_comp( ) const;
返回值
返回 hash_set 使用对元素,是函数模板的参数的 Traits对象。
有关Traits 的更多信息,请参见主题hash_set 类 。
备注
存储的对象定义成员函数:
bool operator(_xVal 的const Key&, const Key&_yVal);
如果后者返回 true,_xVal 之前和与排序顺序的 _yVal 不等于。
注意和 key_comparevalue_compare 是模板参数 特征的同义词。 两个类型。hash_set 和 hash_multiset 类提供,它们用于 hash_map 和类 hash_multimap 的兼容性是相同的,因此,这些不同的。
在Visual C++ .NET 2003中,成员<hash_map> 和 <hash_set> 头文件不再在std命名空间,而是已经进入了stdext命名空间。 有关更多信息,请参见 stdext 命名空间。
示例
// hash_set_key_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> > >::key_compare kc1
= hs1.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 hs1."
<< endl;
}
else
{
cout << "kc1( 2,3 ) returns value of false "
<< "where kc1 is the function object of hs1."
<< endl;
}
hash_set <int, hash_compare < int, greater<int> > > hs2;
hash_set<int, hash_compare < int, greater<int> > >::key_compare
kc2 = hs2.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 hs2."
<< endl;
}
else
{
cout << "kc2( 2,3 ) returns value of false, "
<< "where kc2 is the function object of hs2."
<< endl;
}
}
Output
kc1( 2,3 ) returns value of true, where kc1 is the function object of hs1.
kc2( 2,3 ) returns value of false, where kc2 is the function object of hs2.
要求
Header: <hash_set>
**命名空间:**stdext