共用方式為


hash_map::value_comp

注意事項注意事項

這個 API 已經過時。這個選項是 unordered_map Class

傳回透過比較其索引鍵值判斷項目順序 hash_map 的函式物件。

value_compare value_comp( ) const;

傳回值

傳回使用 hash_map 排序其項目的比較函式物件。

備註

hash_map 的 m,因此,如果兩個項目 e1(k1, d1)e2(k2, d2) 是型別 value_type物件, k1k2是型別 key_type 其索引鍵,並 d不等於 d、是型別 mapped_type其資料,然後 m.value_comp() (e1, e2) 與 *m.key_comp() (k1, k2)*相同。 預存物件定義成員函式

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

要傳回 true ,如果 _Left 的索引鍵值前面並與 _Right 的索引鍵值不等於零=這個執行個體的。

在 Visual C++ .NET Pocket PC, <hash_map><hash_set> 標頭檔 (Header File) 的成員不在 std 命名空間,,而是移至 stdext 命名空間。 如需詳細資訊,請參閱 stdext 命名空間

範例

// 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;
   }
}

Output

The element ( 1,10 ) precedes the element ( 2,5 ).
The element ( 2,5 ) does not precede the element ( 1,10 ).

需求

標題: <hash_map>

命名空間: stdext

請參閱

參考

hash_map Class

標準樣板程式庫