set::key_comp
Pobiera kopię obiektu porównania używany do kluczy zamówienia w zestawie.
key_compare key_comp( ) const;
Wartość zwracana
Zwraca obiekt funkcji używany przez zestaw do zamówienia jego elementów, który jest parametr szablonu Traits.
Aby uzyskać więcej informacji dotyczących Traits, zobacz temat set — Klasa.
Uwagi
Obiektu przechowywana definiuje funkcję członka:
bool operator()(const Key& _xVal, const Key& _yVal);
która oblicza true Jeśli _xVal poprzedza i nie jest równa _yVal w kolejności sortowania.
Należy zauważyć, że zarówno key_compare i value_compare są synonimami dla parametru szablonu cechy.Oba typy są przewidziane zestaw i zestaw wielokrotny klas, gdzie są one identyczne, dla zachowania zgodności z mapy i klasy multimap, jeżeli są one różne.
Przykład
// set_key_comp.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main( )
{
using namespace std;
set <int, less<int> > s1;
set<int, less<int> >::key_compare kc1 = s1.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 s1."
<< endl;
}
set <int, greater<int> > s2;
set<int, greater<int> >::key_compare kc2 = s2.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 s2."
<< endl;
}
else
{
cout << "kc2( 2,3 ) returns value of false, "
<< "where kc2 is the function object of s2."
<< endl;
}
}
Wymagania
Nagłówek: <set>
Przestrzeń nazw: std