![]() |
---|
此 API 已过时。另一种方法是 unordered_multimap Class。 |
成员函数返回通过比较其键值确定元素的顺序。hash_multimap 的函数对象。
value_compare value_comp( ) const;
返回值
返回 hash_multimap 使用对其元素的比较函数对象。
备注
为 hash_multimap m,因此,如果两个元素 e1(k1,d1) 和 e2(k2,d2) 是类型 value_type对象,k1和 k2是类型 key_type 各自的密钥,并 d1 和 d2 是类型 mapped_type它们的数据,然后 *m.*value_comp) (e1,e2) 与 *m.*key_comp) (k1,k2) 是等效的。一个单元的对象定义成员函数
bool operator(value_type&_Left, value_type& _Right);
后者返回 真,如果 _Left 的键值之前和与 _Right 的键值不相等按排序顺序。
在 Visual C++ .NET 2003 中,<hash_map> 和 <hash_set> 标头文件的成员中不再标准,命名空间,而是将 stdext 命名空间。有关更多信息,请参见 stdext 命名空间。
示例
// hash_multimap_value_comp.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_multimap <int, int, hash_compare<int, less<int> > > hm1;
hash_multimap <int, int, hash_compare<int, less<int> >
>::value_compare vc1 = hm1.value_comp( );
hash_multimap <int,int>::iterator Iter1, Iter2;
Iter1= hm1.insert ( hash_multimap <int, int> :: value_type ( 1, 10 ) );
Iter2= hm1.insert ( hash_multimap <int, int> :: value_type ( 2, 5 ) );
if( vc1( *Iter1, *Iter2 ) == 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( *Iter2, *Iter1 ) == 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