hash_multiset::hash_multiset

注意事項注意事項

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

建構是空的或為其他 hash_multiset全部或部分的複本的 hash_multiset

hash_multiset( );
explicit hash_multiset(
   const Traits& _Comp
);
hash_multiset(
   const Traits& _Comp,
   const Allocator& _Al
);
hash_multiset(
   const hash_multiset<Key, Traits, Allocator>& _Right
);
template<class InputIterator>
   hash_multiset(
      InputIterator _First,
      InputIterator _Last
   );
template<class InputIterator>
   hash_multiset(
      InputIterator _First,
      InputIterator _Last,
      const Traits& _Comp
   );
template<class InputIterator>
   hash_multiset(
      InputIterator _First,
      InputIterator _Last,
      const Traits& _Comp,
      const Allocator& _Al
   );
hash_multiset(
   hash_multiset&& _Right
};

參數

參數

描述

_Al

為這 hash_multiset 物件所要使用的儲存體配置器類別,預設值為 Allocator

_Comp

用於型別 const Traits 的比較函式以 hash_multiset的項目,預設為 hash_compare

_Right

建構的 hash_multiset 是複本的 hash_multiset

_First

第一個項目位置要複製到的元素範圍內的。

_Last

第一個項目位置要複製之項目範圍的。

備註

所有建構函式所儲存的配置器物件型別處理 hash_multiset 的記憶體儲存,並可藉由呼叫 hash_multiset::get_allocator後傳回。配置器參數在用於類別宣告和前置處理器巨集通常省略替代替代的配置器。

所有建構函式初始化其 hash_multisets。

所有建構函式中用於建立可在 hash_multiset 索引鍵中的命令,並且可以藉由呼叫 hash_multiset::key_comp後傳回型別 Traits 的函式物件。如需 Traits 資訊請參閱 hash_multiset Class 主題。

指定空的初始 hash_multiset,第二個指定的比較函式 (_Comp) 的型別用來建立項目和三個命令明確指定配置器類型 (_Al) 的前三個建構函式會使用。關鍵字 explicit 隱藏特定種類的自動型別轉換。

第四個建構函式指定 hash_multiset_Right的複本。

接下來的三個建構函式複製範圍 [_First,_Last) 的 hash_multiset 隨著在指定類別的比較函式型別的明確的加入比較和配置器。

最後建構函式移動 hash_multiset_Right。

項目實際順序雜湊的設定容器的取決於雜湊函式、排序函式和雜湊資料表的目前大小,且無法,一般而言,被預測,因為它可能與集合容器,個別排序函式取決於它。

範例

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

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_multiset <int>::iterator hms1_Iter, hms3_Iter, hms4_Iter,
      hms5_Iter, hms6_Iter, hms7_Iter;
   hash_multiset <int, hash_compare <int, greater<int> > >::iterator
      hms2_Iter;

   // Create an empty hash_multiset hs0 of key type integer
   hash_multiset <int> hs0;

   // Create an empty hash_multiset hms1 with the key comparison
   // function of less than, then insert 4 elements
   hash_multiset <int, hash_compare <int, less<int> > > hms1;
   hms1.insert( 10 );
   hms1.insert( 20 );
   hms1.insert( 30 );
   hms1.insert( 40 );

   // Create an empty hash_multiset hms2 with the key comparison
   // function of geater than, then insert 2 elements
   hash_multiset <int, hash_compare <int, greater<int> > > hms2;
   hms2.insert( 10 );
   hms2.insert( 20 );

   // Create a hash_multiset hms3 with the 
   // allocator of hash_multiset hms1
   hash_multiset <int>::allocator_type hms1_Alloc;
   hms1_Alloc = hms1.get_allocator( );
   hash_multiset <int> hms3( hash_compare <int, less<int> >( ),
      hms1_Alloc );
   hms3.insert( 30 );

   // Create a copy, hash_multiset hms4, of hash_multiset hms1
   hash_multiset <int> hms4( hms1 );

   // Create a hash_multiset hms5 by copying the range hms1[_First, _Last)
   hash_multiset <int>::const_iterator hms1_bcIter, hms1_ecIter;
   hms1_bcIter = hms1.begin( );
   hms1_ecIter = hms1.begin( );
   hms1_ecIter++;
   hms1_ecIter++;
   hash_multiset <int> hms5( hms1_bcIter, hms1_ecIter );

   // Create a hash_multiset hms6 by copying the range hms4[_First, _Last)
   // and with the allocator of hash_multiset hms2
   hash_multiset <int>::allocator_type hms2_Alloc;
   hms2_Alloc = hms2.get_allocator( );
   hash_multiset <int> hms6( hms4.begin( ), ++hms4.begin( ), 
      less<int>( ), hms2_Alloc );

   cout << "hms1 = ";
   for ( hms1_Iter = hms1.begin( ); hms1_Iter != hms1.end( );
         hms1_Iter++ )
      cout << *hms1_Iter << " ";
   cout << endl;
   
   cout << "hms2 = " ;
   for ( hms2_Iter = hms2.begin( ); hms2_Iter != hms2.end( );
         hms2_Iter++ )
      cout << *hms2_Iter << " ";
   cout << endl;

   cout << "hms3 = ";
   for ( hms3_Iter = hms3.begin( ); hms3_Iter != hms3.end( );
         hms3_Iter++ )
      cout << *hms3_Iter << " ";
   cout << endl;

   cout << "hms4 = ";
   for ( hms4_Iter = hms4.begin( ); hms4_Iter != hms4.end( );
         hms4_Iter++ )
      cout << *hms4_Iter << " ";
   cout << endl;

   cout << "hms5 = ";
   for ( hms5_Iter = hms5.begin( ); hms5_Iter != hms5.end( );
         hms5_Iter++ )
      cout << *hms5_Iter << " ";
   cout << endl;

   cout << "hms6 = ";
   for ( hms6_Iter = hms6.begin( ); hms6_Iter != hms6.end( );
         hms6_Iter++ )
      cout << *hms6_Iter << " ";
   cout << endl;

    // Create a copy, hash_multiset hms7, of hash_multiset hms1 by moving
    hash_multiset <int, hash_compare <int, less<int> > >
        hms7(move(hms1);
    cout << "hms7 =";
    for (hms7_Iter = hms7.begin(); hms7_Iter != hms7.end(); hms7_Iter++)
        cout << " " << hms7_Iter -> second;
    cout << endl;
}

Output

hms1 = 40 10 20 30 
hms2 = 10 20 
hms3 = 30 
hms4 = 40 10 20 30 
hms5 = 40 10 
hms6 = 40 
hms7 = 40 10 20 30 

需求

標題: <hash_set>

命名空間: stdext

請參閱

參考

hash_multiset Class

標準樣板程式庫