共用方式為


map::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)。 所儲存的物件定義的成員函式。

bool operator(value_type&_Left, value_type&_Right);

要傳回 true ,如果 _Left 的索引鍵值前面並與 _Right 的機碼值不相等的排序順序。

範例

// map_value_comp.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
   using namespace std;
   
   map <int, int, less<int> > m1;
   map <int, int, less<int> >::value_compare vc1 = m1.value_comp( );
   pair< map<int,int>::iterator, bool > pr1, pr2;
   
   pr1= m1.insert ( map <int, int> :: value_type ( 1, 10 ) );
   pr2= m1.insert ( map <int, int> :: value_type ( 2, 5 ) );

   if( vc1( *pr1.first, *pr2.first ) == 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( *pr2.first, *pr1.first ) == 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

請參閱

參考

map Class

標準樣板程式庫