Freigeben über


hash_map::key_comp

Hinweis

Diese API ist veraltet.Die Alternative ist unordered_map-Klasse.

Ruft eine Kopie des Vergleichsobjekts ab, das den Reihenfolgentasten in einem hash_map verwendet wird.

key_compare key_comp( ) const;

Rückgabewert

Gibt dem Funktionsobjekt zurück, dem ein hash_map verwendet, um ihre Elemente auf.

Hinweise

Das gespeicherte Objekt definiert die Memberfunktion

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

Dies gibt true zurück, wenn _Left nicht gleich _Right in der Sortierreihenfolge vor und ist.

In Visual C++ .NET 2003 sind Member der <hash_map> und <hash_set> Headerdateien nicht mehr im STD-Namespace enthalten. Sie wurden stattdessen in den stdext-Namespace verschoben. Weitere Informationen finden Sie unter Der stdext-Namespace.

Beispiel

// 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;
   }
}

Ausgabe

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.

Anforderungen

Header: <hash_map>

Namespace: stdext

Siehe auch

Referenz

hash_map-Klasse

Standardvorlagenbibliothek