Condividi tramite


hash_set::hash_set

[!NOTA]

Questo API è obsoleto.L'alternativa consiste unordered_set Class.

Costruisce hash_set che è vuoto o mediante la copia di tutto o parte di un altro hash_set.

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

Parametri

Parametro

Descrizione

_Al

La classe di allocatore di memoria da utilizzare per questo oggetto hash_set, che imposta come valore predefinito a Allocator.

_Comp

La funzione di confronto di tipo const Traits utilizzato per ordinare gli elementi in hash_set, che imposta come valore predefinito a hash_compare.

_Right

hash_set di cui hash_set 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_set e che successivamente può essere restituito chiamando hash_set::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_sets.

Tutti i costruttori archiviano un oggetto funzione di tipo Traits utilizzato per stabilire un ordine tra le chiavi hash_set e che successivamente può essere restituito chiamando hash_set::key_comp.Per ulteriori informazioni su Traits vedere l'argomento hash_set Class.

I tre costruttori seguenti illustrano hash_setiniziale 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_set_Right.

Gli ultimi tre costruttori copia dell'intervallo [_First, _Last) hash_set con l'aumento di chiarezza nello specificare il tipo di funzione di confronto dei tratti e di allocatore della classe.

l'ultimo costruttore sposta hash_set_Right.

L'ordine effettivo di elementi in un contenitore hash_set 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_set_hash_set.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_set <int>::iterator hs1_Iter, hs3_Iter, hs4_Iter,
      hs5_Iter, hs6_Iter, hs7_Iter;
   hash_set <int, hash_compare <int, greater<int> > >::iterator
      hs2_Iter;

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

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

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

   // Create a hash_set hs3 with the 
   // allocator of hash_set hs1
   hash_set <int>::allocator_type hs1_Alloc;
   hs1_Alloc = hs1.get_allocator( );
   hash_set <int> hs3( hash_compare <int, less<int> >( ),
      hs1_Alloc );
   hs3.insert( 30 );

   // Create a copy, hash_set hs4, of hash_set hs1
   hash_set <int> hs4( hs1 );

   // Create a hash_set hs5 by copying the range hs1[_First, _Last)
   hash_set <int>::const_iterator hs1_bcIter, hs1_ecIter;
   hs1_bcIter = hs1.begin( );
   hs1_ecIter = hs1.begin( );
   hs1_ecIter++;
   hs1_ecIter++;
   hash_set <int> hs5( hs1_bcIter, hs1_ecIter );

   // Create a hash_set hs6 by copying the range hs4[_First, _Last)
   // and with the allocator of hash_set hs2
   hash_set <int>::allocator_type hs2_Alloc;
   hs2_Alloc = hs2.get_allocator( );
   hash_set <int> hs6( hs4.begin( ), ++hs4.begin( ), 
      less<int>( ), hs2_Alloc );

   cout << "hs1 = ";
   for ( hs1_Iter = hs1.begin( ); hs1_Iter != hs1.end( );
         hs1_Iter++ )
      cout << *hs1_Iter << " ";
   cout << endl;
   
   cout << "hs2 = " ;
   for ( hs2_Iter = hs2.begin( ); hs2_Iter != hs2.end( );
         hs2_Iter++ )
      cout << *hs2_Iter << " ";
   cout << endl;

   cout << "hs3 = ";
   for ( hs3_Iter = hs3.begin( ); hs3_Iter != hs3.end( );
         hs3_Iter++ )
      cout << *hs3_Iter << " ";
   cout << endl;

   cout << "hs4 = ";
   for ( hs4_Iter = hs4.begin( ); hs4_Iter != hs4.end( );
         hs4_Iter++ )
      cout << *hs4_Iter << " ";
   cout << endl;

   cout << "hs5 = ";
   for ( hs5_Iter = hs5.begin( ); hs5_Iter != hs5.end( );
         hs5_Iter++ )
      cout << *hs5_Iter << " ";
   cout << endl;

   cout << "hs6 = ";
   for ( hs6_Iter = hs6.begin( ); hs6_Iter != hs6.end( );
         hs6_Iter++ )
      cout << *hs6_Iter << " ";
   cout << endl;

    // Create a copy, hash_set hs7, of hash_set hs1 by moving
    hash_set <int, hash_compare <int, less<int> > >
        hs7(move(hs1);
    cout << "hs7 =";
    for (hs7_Iter = hs7.begin(); hs7_Iter != hs7.end(); hs7_Iter++)
        cout << " " << hs7_Iter -> second;
    cout << endl;
}

Output

hs1 = 40 10 20 30 
hs2 = 10 20 
hs3 = 30 
hs4 = 40 10 20 30 
hs5 = 40 10 
hs6 = 40 
hs7 = 40 10 20 30 

Requisiti

intestazione: <hash_set>

Stdext diSpazio dei nomi:

Vedere anche

Riferimenti

hash_set Class

Libreria di modelli standard