multiset::key_comp
Recupera una copia dell'oggetto di confronto utilizzato alle chiavi di ordinamento in un multi-insieme.
key_compare key_comp( ) const;
Valore restituito
Restituisce l'oggetto funzione che un multi-insieme utilizza per ordinare gli elementi, che è il parametro di template Compare.
Per ulteriori informazioni su Compare, vedere la sezione relativa alle osservazioni dell'argomento multiset Class.
Note
L'oggetto memorizzato definisce la funzione membro:
bool operator(**const Key&const Key&**x,y);
quali restituisce true se la x precede rigorosamente y ordinati.
Si noti che sia key_compare che value_compare sono sinonimi per il parametro di template Compare.Entrambi i tipi sono forniti per le classi e impostare il multi-insieme, dove sono identici, per la compatibilità con il mapping e il multimap di classi, in cui sono diversi.
Esempio
// multiset_key_comp.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main( )
{
using namespace std;
multiset <int, less<int> > ms1;
multiset <int, less<int> >::key_compare kc1 = ms1.key_comp( ) ;
bool result1 = kc1( 2, 3 ) ;
if( result1 == true )
{
cout << "kc1( 2,3 ) returns value of true, "
<< "where kc1 is the function object of s1."
<< endl;
}
else
{
cout << "kc1( 2,3 ) returns value of false "
<< "where kc1 is the function object of ms1."
<< endl;
}
multiset <int, greater<int> > ms2;
multiset <int, greater<int> >::key_compare kc2 = ms2.key_comp( ) ;
bool result2 = kc2( 2, 3 ) ;
if( result2 == true )
{
cout << "kc2( 2,3 ) returns value of true, "
<< "where kc2 is the function object of ms2."
<< endl;
}
else
{
cout << "kc2( 2,3 ) returns value of false, "
<< "where kc2 is the function object of ms2."
<< endl;
}
}
Requisiti
intestazione: <set>
Spazio dei nomi: deviazione standard