set::key_comp

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

key_compare key_comp( ) const;

返回值

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

有关Traits 的更多信息,请参见主题set 类

备注

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

bool operator()const Key&  const Key& (_xVal,_yVal);

如果后者返回 true,_xVal 之前和与排序顺序的 _yVal 不等于。

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

示例

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

要求

标头: <set>

命名空间: std

请参见

参考

set 类

set::key_comp 和 set::value_comp

标准模板库