hash_map::value_comp
[!UWAGA]
Ten interfejs API jest nieaktualny.Alternatywą jest unordered_map — Klasa.
Zwraca obiekt funkcji, która określa kolejność elementów w hash_map, poprzez porównanie ich wartości klucza.
value_compare value_comp( ) const;
Wartość zwracana
Zwraca obiekt funkcji porównania, który hash_map używa się w celu zamówienia jego elementów.
Uwagi
For a hash_map m, if two elements e1*(k1, d1)* and e2*(k2, d2)* are objects of type value_type, where k1 and k2 are their keys of type key_type and d1 and d2 are their data of type mapped_type, then m.value_comp( )(e1*, e2)* is equivalent to m.key_comp( ) (k1*, k2)*.Obiekt przechowywana definiuje funkcję członka
bool operator(value_type&_Left, value_type&_Right);
która oblicza true Jeśli wartość klucza _Left poprzedza i nie jest równa wartości klucza z _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_value_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> > >
::value_compare vc1 = hm1.value_comp( );
pair< hash_map<int,int>::iterator, bool > pr1, pr2;
pr1= hm1.insert ( hash_map <int, int> :: value_type ( 1, 10 ) );
pr2= hm1.insert ( hash_map <int, int> :: value_type ( 2, 5 ) );
if( vc1( *pr1.first, *pr2.first ) == 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 ( *pr2.first, *pr1.first ) == 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;
}
}
Dane wyjściowe
The element ( 1,10 ) precedes the element ( 2,5 ).
The element ( 2,5 ) does not precede the element ( 1,10 ).
Wymagania
Nagłówek: <hash_map>
Przestrzeń nazw: stdext