multiset::key_comp

检索在多个集使用的顺序对密钥进行比较对象的副本。

key_compare key_comp( ) const;

返回值

返回多个集使用对其元素,是模板参数 Compare的函数对象。

有关 Compare的更多信息,请参见 multiset Class 主题的"备注"节。

备注

存储的对象定义成员函数:

bool operator(**const Key&**x, **const Key&**y);

后者返回true,则 x 强前面 y 按排序顺序。

请注意 key_comparevalue_compare 是模板参数的 Compare同义词。两个类型为设置的选件类提供,并且多级集,两者相同,与选件类兼容的映射和基于,其中它们是不同的。

示例

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

要求

标头: <set>

命名空间: std

请参见

参考

multiset Class

标准模板库