Поделиться через


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 который возвращает true предшествует и не равно _Right в порядке сортировки.

В Visual C++ .NET 2003 <hash_map> элементы файлов заголовков и <hash_set> больше не находятся в пространстве имен std, но скорее перейти на пространство имен 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

Стандартная библиотека шаблонов