次の方法で共有


multimap::value_comp

このメンバー関数は、キー値を比較して multimap の要素の順序を決定する関数オブジェクトを返します。

value_compare value_comp( ) const;

戻り値

要素の並べ替えに multimap が使用する比較関数オブジェクトを返します。

解説

multimap mの場合、2 個の要素 (k1 e1d1) と e2k2 (2) は、dk1k2 がkey_type キーの d1 および 2 が d型 mapped_typeのデータである型 value_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 クラス

標準テンプレート ライブラリ