hash_map::key_comp

备注

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

检索在 hash_map 使用的顺序对密钥进行比较对象的副本。

key_compare key_comp( ) const;

返回值

返回 hash_map 使用对其元素的函数对象。

备注

存储的对象定义成员函数

bool operator(const Key& _Left**, const Key&** _Right);

如果 _Left 之前和与 _Right 不相等按排序顺序,则返回

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

示例

// hash_map_key_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> > >::key_compare 
      kc1 = hm1.key_comp( ) ;

   // Operator stored in kc1 tests order & returns bool value
   bool result1 = kc1( 2, 3 ) ;   
   if( result1 == true )   
   {
      cout << "kc1( 2,3 ) returns value of true,"
           << "\n where kc1 is the function object of hm1"
           << " of type key_compare." << endl;
   }
   else   
   {
      cout << "kc1( 2,3 ) returns value of false"
           << "\n where kc1 is the function object of hm1"
           << " of type key_compare." << endl;
   }

   hash_map <int, int, hash_compare<int, greater<int> > > hm2;
   hash_map <int, int, hash_compare<int, greater<int> > >
      ::key_compare kc2 = hm2.key_comp( );

   // Operator stored in kc2 tests order & returns bool value
   bool result2 = kc2( 2, 3 ) ;
   if( result2 == true )
   {
      cout << "kc2( 2,3 ) returns value of true,"
           << "\n where kc2 is the function object of hm2"
           << " of type key_compare." << endl;
   }
   else   
   {
      cout << "kc2( 2,3 ) returns value of false,"
           << "\n where kc2 is the function object of hm2"
           << " of type key_compare." << endl;
   }
}

Output

kc1( 2,3 ) returns value of true,
 where kc1 is the function object of hm1 of type key_compare.
kc2( 2,3 ) returns value of false,
 where kc2 is the function object of hm2 of type key_compare.

要求

标头: <hash_map>

命名空间: stdext

请参见

参考

hash_map Class

标准模板库