multimap::value_comp
成員函式傳回藉由比較其索引鍵值判斷項目順序多重對應的函式物件。
value_compare value_comp( ) const;
傳回值
傳回多重對應使用排序其項目的比較函式物件。
備註
對於多重對應 m,因此,如果兩個項目 e1(k1, d1) 和 e2(k2, d2) 是型別 value_type的物件, k1和 k2屬於 key_type 型別其索引鍵,而且 d1 和 d2 是 mapped_type型別其資料,然後 *m.*value_comp(e1, e2) 以 *m.*key_comp(k1, k2)。
範例
// 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