hash_map::key_comp
[!UWAGA]
Ten interfejs API jest nieaktualny.Alternatywą jest unordered_map — Klasa.
Pobiera kopię obiektu porównania używany do kluczy zamówienia w hash_map.
key_compare key_comp( ) const;
Wartość zwracana
Zwraca obiekt funkcja hash_map używa się w celu zamówienia jego elementów.
Uwagi
Obiektu przechowywana definiuje funkcję członka
bool operator(const Key&_Left**, const Key&**_Right);
które zwraca true Jeśli _Left poprzedza i nie jest równa _Right w kolejności sortowania.
W Visual C++ .NET 2003, elementy członkowskie plików nagłówka <hash_map> i <hash_set> nie są już w przestrzeni nazw std, ale raczej zostały przeniesione do przestrzeni nazw stdext.Zobacz Przestrzeń nazw stdext, aby uzyskać więcej informacji.
Przykład
// 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;
}
}
Dane wyjściowe
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.
Wymagania
Nagłówek: <hash_map>
Przestrzeń nazw: stdext