共用方式為


hash_set::value_comp

注意事項注意事項

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

擷取在 hash_set 用來解析命令項目值比較物件的複本。

value_compare value_comp( ) const;

傳回值

傳回 hash_set 使用排序其項目,是樣板參數 Compare的函式物件。

如需 Compare資訊,請參閱 hash_set Class 主題的<備註>一節。

備註

儲存物件定義成員函式:

bool operator(_xVal 的const Key&const Key& _yVal);

要傳回 true ,如果 _xVal 前面並與在排序次序中的 _yVal 不相等。

請注意 value_comparekey_compare 是樣板參數的 Compare同義資料表。 兩個型別為 hash_set 和 hash_multiset 類別提供,因此對於使用 hash_map 和 hash_multimap 類別的相容性相同,,它們是不同的。

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

範例

// hash_set_value_comp.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   
   hash_set <int, hash_compare < int, less<int> > > hs1;
   hash_set <int, hash_compare < int, less<int> >  >::value_compare
      vc1 = hs1.value_comp( );
   bool result1 = vc1( 2, 3 );
   if( result1 == true )
   {
      cout << "vc1( 2,3 ) returns value of true, "
           << "where vc1 is the function object of hs1."
           << endl;
   }
   else
   {
      cout << "vc1( 2,3 ) returns value of false, "
           << "where vc1 is the function object of hs1."
           << endl;
   }

   hash_set <int, hash_compare < int, greater<int> > > hs2;
   hash_set<int, hash_compare < int, greater<int> > >::value_compare
      vc2 = hs2.value_comp( );
   bool result2 = vc2( 2, 3 );
   if( result2 == true )
   {
      cout << "vc2( 2,3 ) returns value of true, "
           << "where vc2 is the function object of hs2."
           << endl;
   }
   else
   {
      cout << "vc2( 2,3 ) returns value of false, "
           << "where vc2 is the function object of hs2."
           << endl;
   }
}

Output

vc1( 2,3 ) returns value of true, where vc1 is the function object of hs1.
vc2( 2,3 ) returns value of false, where vc2 is the function object of hs2.

需求

標題: <hash_set>

命名空間: stdext

請參閱

參考

hash_set Class

標準樣板程式庫