multiset::key_comp

检索中多集用于排序关键字进行比较对象的副本。

key_compare key_comp( ) const;

返回值

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

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

备注

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

bool operatorconst Key&  const Key& (xy);

后者返回 true,则为 x 强优先于排序顺序的 y

注意和 key_comparevalue_compare 模板参数是的同义词。Compare 两个类型为类设置和多集提供,它们用于类映射和 multimap 的兼容性是相同的,因此,这些不同的。

示例

// 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 类

标准模板库