共用方式為


multimap::value_comp

成員函式來傳回藉由比較其索引鍵值判斷項目順序 multimap 的函式物件。

value_compare value_comp( ) const;

傳回值

傳回 multimap 使用排序其項目的比較函式物件。

備註

對於 multimap 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

標準樣板程式庫