map::value_comp
멤버 함수 지도에서 요소의 순서는 키 값을 비교 하 여 결정 하는 함수 개체를 반환 합니다.
value_compare value_comp( ) const;
반환 값
지도 사용 하 여 요소를 정렬 하는 비교 함수 개체를 반환 합니다.
설명
For a map m, if two elements e1(k1, d1) and e2(k2, d2) are objects of type value_type, where k1 and k2 are their keys of type key_type and d1 and d2 are their data of type mapped_type, then *m.*value_comp(e1, e2) is equivalent to m.key_comp(k1, k2).멤버 함수는 저장 된 개체를 정의합니다.
bool operator(value_type&_Left, value_type&_Right);
반환 true 경우 키 값을 _Left 앞에 및 키 값을 1이 아닌 _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