multimap::key_comp
检索中 multimap 用于排序关键字进行比较对象的副本。
key_compare key_comp( ) const;
返回值
返回 multimap 使用对元素的函数对象。
备注
存储的对象成员函数定义
bool operatorconst Key& const Key& (x,y);
后者返回 true,则为 x 强优先于排序顺序的 y。
示例
// multimap_key_comp.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
multimap <int, int, less<int> > m1;
multimap <int, int, less<int> >::key_compare kc1 = m1.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 m1."
<< endl;
}
else
{
cout << "kc1( 2,3 ) returns value of false "
<< "where kc1 is the function object of m1."
<< endl;
}
multimap <int, int, greater<int> > m2;
multimap <int, int, greater<int> >::key_compare kc2 = m2.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 m2."
<< endl;
}
else
{
cout << "kc2( 2,3 ) returns value of false, "
<< "where kc2 is the function object of m2."
<< endl;
}
}
要求
标头: <map>
命名空间: std