multimap::value_comp

成员函数返回通过比较其键值确定元素的顺序与基于的函数对象。

value_compare value_comp( ) const;

返回值

返回基于使用对其元素的比较函数对象。

备注

对于基于 m,因此,如果两个元素 e1(k1d1)和 e2(k2,d2)是类型 value_type对象,k1k2是类型 key_type 各自的密钥,并 d1和 d2是类型 mapped_type它们的数据,然后 *m.*value_comp(e1e2)与 *m.*key_comp(k1k2)是等效的。

示例

// multimap_value_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> >::value_compare vc1 = m1.value_comp( );
   multimap<int,int>::iterator Iter1, Iter2;
   
   Iter1= m1.insert ( multimap <int, int> :: value_type ( 1, 10 ) );
   Iter2= m1.insert ( multimap <int, int> :: value_type ( 2, 5 ) );

   if( vc1( *Iter1, *Iter2 ) == true )   
   {
      cout << "The element ( 1,10 ) precedes the element ( 2,5 )."
           << endl;
   }
   else   
   {
      cout << "The element ( 1,10 ) does "
           << "not precede the element ( 2,5 )."
           << endl;
   }

   if( vc1( *Iter2, *Iter1 ) == true )   
   {
      cout << "The element ( 2,5 ) precedes the element ( 1,10 )."
           << endl;
   }
   else   
   {
      cout << "The element ( 2,5 ) does "
           << "not precede the element ( 1,10 )."
           << endl;
   }
}
  
  

要求

标头: <map>

命名空间: std

请参见

参考

multimap Class

标准模板库