hash_multiset::hash_multiset
[!NOTA]
Questo API è obsoleto.L'alternativa consiste unordered_multiset Class.
Costruisce hash_multiset che è vuoto o mediante la copia di tutto o parte di un altro 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
};
Parametri
Parametro |
Descrizione |
_Al |
La classe di allocatore di memoria da utilizzare per questo oggetto hash_multiset, che imposta come valore predefinito a Allocator. |
_Comp |
La funzione di confronto di tipo const Traits utilizzato per ordinare gli elementi in hash_multiset, che imposta come valore predefinito a hash_compare. |
_Right |
hash_multiset di cui hash_multiset viene costruito da una copia. |
_First |
La posizione del primo elemento nella sequenza di elementi da copiare. |
_Last |
La posizione del primo elemento nell'intervallo di elementi da copiare. |
Note
Tutti i costruttori archivia un tipo di oggetto allocatore che gestisce l'archiviazione di memoria per hash_multiset e che successivamente può essere restituito chiamando hash_multiset::get_allocator.Il parametro di allocatore viene omesso spesso nelle dichiarazioni di classe e nelle macro del preprocessore utilizzate per sostituire di allocatori alternativi.
Tutti i costruttori inizializzano i hash_multisets.
Tutti i costruttori archiviano un oggetto funzione di tipo Traits utilizzato per stabilire un ordine tra le chiavi hash_multiset e che successivamente può essere restituito chiamando hash_multiset::key_comp.Per ulteriori informazioni su Traits vedere l'argomento hash_multiset Class.
I primi tre costruttori specificano hash_multisetiniziale vuoto, il secondo specifica il tipo di funzione di confronto (_Comp) da utilizzare per stabilire l'ordine degli elementi e del terzo specificare in modo esplicito il tipo di allocatore (_Al) da utilizzare.La parola chiave explicit elimina determinati tipi di conversione automatica dei tipi.
Il quarto costruttore specifica una copia hash_multiset_Right.
I tre costruttori seguenti copia dell'intervallo [_First,_Last) di un hash_multiset con l'aumento di chiarezza nello specificare il tipo di funzione di confronto di classe confrontano e allocatore.
l'ultimo costruttore sposta hash_multiset_Right.
L'ordine effettivo di elementi in un contenitore impostato con hash dipende dalla funzione hash, la funzione di ordine e dalla dimensione corrente di hash presenti e non può, ad essere previsto in quanto potrebbe con il contenitore di, in cui è stato determinato dalla funzione di ordine da solo.
Esempio
// 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
Requisiti
intestazione: <hash_set>
Stdext diSpazio dei nomi: