hash_map::value_comp

HinweisHinweis

Diese API ist veraltet.Die Alternative ist unordered_map Class.

Gibt ein Funktionsobjekt zurück, das die Reihenfolge der Elemente in einem hash_map bestimmt, indem es ihre Schlüsselwerte vergleicht.

value_compare value_comp( ) const;

Rückgabewert

Gibt das Vergleichsfunktionsobjekt zurück, dem ein hash_map verwendet, um die Elemente zu sortieren.

Hinweise

Ein hash_map m, wenn zwei Elemente (k1e1 und e2, d1)(k2, d2)-Objekte des Typs value_type sind, in dem k1 und k2 ihre Schlüssel des Typs key_type sind und d1 und 2 d ihre Daten des Typs mapped_type sind, dann M.value_comp() (e1, e2) ist mit M.key_comp() (k1, zu k2) entspricht.Ein gespeichertes Objekt definiert die Memberfunktion

bool operator(value_type& _Left, value_type& _Right);

das true zurückgibt, wenn der Schlüsselwert von _Left nicht dem Schlüsselwert von _Right in der Sortierreihenfolge vor und ist.

In Visual C++ .NET 2003, sind Member der <hash_map> und <hash_set> Headerdateien nicht mehr im stdnamespace, sondern sind in den stdext Namespace verschoben wurde.Weitere Informationen finden Sie unter Der stdext-Namespace.

Beispiel

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

Ausgabe

The element ( 1,10 ) precedes the element ( 2,5 ).
The element ( 2,5 ) does not precede the element ( 1,10 ).

Anforderungen

Header: <hash_map>

Namespace: stdext

Siehe auch

Referenz

hash_map Class

Standardvorlagenbibliothek