hash_map::value_comp
[!メモ]
この API は、互換性のために残されています。代わりに unordered_map クラスです。
キー値を比較してhash_mapの要素の順序を決定する関数オブジェクトを返します。
value_compare value_comp( ) const;
戻り値
要素の並べ替えにhash_mapが使用する比較関数オブジェクトを返します。
解説
hash_map m において、もし 2 つの要素 e1*(k1, , d1)* と e2*(k2, , d2)* が value_type 型のオブジェクトの場合 (k1 と k2 が key_type のキーで、d1 と d2 が mapped_type 型の各々のデータ) は、then m.value_comp( )(e1*, e2)* は m..key_comp*( ) (k1, , k2)* と等価です。格納されているオブジェクトには、メンバー関数を定義します。
bool operator (value_type& _Left、value_type& _Right) ;
_Left のキー値が並べ替え順序の _Right のキー値と等しくない前および true を返すかが。
Visual C++ .NET 2003では、<hash_map> と <hash_set> ヘッダー ファイルのメンバーはstdの名前空間に存在しなくなりましたが、ではなくstdextの名前空間に型。詳細については、「The stdext Namespace」を参照してください。
使用例
// hash_map_value_comp.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int, hash_compare<int, less<int> > > hm1;
hash_map <int, int, hash_compare<int, less<int> > >
::value_compare vc1 = hm1.value_comp( );
pair< hash_map<int,int>::iterator, bool > pr1, pr2;
pr1= hm1.insert ( hash_map <int, int> :: value_type ( 1, 10 ) );
pr2= hm1.insert ( hash_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;
}
}
出力
The element ( 1,10 ) precedes the element ( 2,5 ).
The element ( 2,5 ) does not precede the element ( 1,10 ).
必要条件
ヘッダー: <hash_map>
名前空間: のstdext