备注
此 API 已过时。替代为 unordered_map 类。
返回通过对它们进行比较的键值确定元素在 hash_map 的函数对象。
value_compare value_comp( ) const;
返回值
返回 hash_map 使用对其元素进行比较函数对象。
备注
对于 m,如果两个元素 e1*(k1,d1)* 和 e2*(k2,d2)* 为类型的对象 value_type,其中 k1 和 k2 类型自己的键 key_type 和 d1 和 d2 are their data of type mapped_type,则 m.value_comp( )(e1*, e2)* 等于 m.key_comp( ) (k1*, k2)*。 一个存储的对象成员函数定义
bool operatorvalue_type& value_type& ###;(_Left,_Right)
后者返回 true,如果关键 _Left 值前面并与键值不相等在排序顺序的 _Right。
在Visual C++ .NET 2003中,成员<hash_map> 和 <hash_set> 头文件不再在std命名空间,而是已经进入了stdext命名空间。 有关更多信息,请参见 stdext 命名空间。
示例
// hash_map_value_comp.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int, hash_compare<int, less<int> > > hm1;
hash_map <int, int, hash_compare<int, less<int> > >
::value_compare vc1 = hm1.value_comp( );
pair< hash_map<int,int>::iterator, bool > pr1, pr2;
pr1= hm1.insert ( hash_map <int, int> :: value_type ( 1, 10 ) );
pr2= hm1.insert ( hash_map <int, int> :: value_type ( 2, 5 ) );
if( vc1( *pr1.first, *pr2.first ) == true )
{
cout << "The element ( 1,10 ) precedes the element ( 2,5 )."
<< endl;
}
else
{
cout << "The element ( 1,10 ) does not precede the element ( 2,5 )."
<< endl;
}
if( vc1 ( *pr2.first, *pr1.first ) == true )
{
cout << "The element ( 2,5 ) precedes the element ( 1,10 )."
<< endl;
}
else
{
cout << "The element ( 2,5 ) does not precede the element ( 1,10 )."
<< endl;
}
}
Output
The element ( 1,10 ) precedes the element ( 2,5 ).
The element ( 2,5 ) does not precede the element ( 1,10 ).
要求
标头: <hash_map>
**命名空间:**stdext