hash_multiset::key_comp

注意事項注意事項

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

擷取在 hash_multiset 用來解析順序索引鍵比較物件的複本。

key_compare key_comp( ) const;

傳回值

傳回 hash_multiset 樣板參數 Traits,包含函式物件用於雜湊和排序容器的項目。

如需 Traits 資訊請參閱 hash_multiset Class 主題。

備註

儲存物件定義成員函式:

bool operator( _xValconst Key&const Key& _yVal);

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

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

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

範例

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

int main( )
{
   using namespace std;
   using namespace stdext;
   
   hash_multiset <int, hash_compare < int, less<int> > >hms1;
   hash_multiset<int, hash_compare < int, less<int> > >::key_compare kc1
          = hms1.key_comp( ) ;
   bool result1 = kc1( 2, 3 ) ;
   if( result1 == true )
   {
      cout << "kc1( 2,3 ) returns value of true, "
           << "where kc1 is the function object of hms1."
           << endl;
   }
   else
   {
      cout << "kc1( 2,3 ) returns value of false "
           << "where kc1 is the function object of hms1."
        << endl;
   }

   hash_multiset <int, hash_compare < int, greater<int> > > hms2;
   hash_multiset<int, hash_compare < int, greater<int> > >::key_compare
         kc2 = hms2.key_comp( ) ;
   bool result2 = kc2( 2, 3 ) ;
   if( result2 == true )
   {
      cout << "kc2( 2,3 ) returns value of true, "
           << "where kc2 is the function object of hms2."
           << endl;
   }
   else
   {
      cout << "kc2( 2,3 ) returns value of false, "
           << "where kc2 is the function object of hms2."
           << endl;
   }
}

Output

kc1( 2,3 ) returns value of true, where kc1 is the function object of hms1.
kc2( 2,3 ) returns value of false, where kc2 is the function object of hms2.

需求

標題: <hash_set>

命名空間: stdext

請參閱

參考

hash_multiset Class

標準樣板程式庫