Condividi tramite


hash_multimap::hash_multimap

[!NOTA]

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

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

hash_multimap( );
explicit hash_multimap(
   const Compare& _Comp
);
hash_multimap(
   const Compare& _Comp,
   const Allocator& _Al
);
hash_multimap(
   const hash_multimap& _Right
);
template<class InputIterator>
   hash_multimap(
      InputIterator _First,
      InputIterator _Last
   );
template<class InputIterator>
   hash_multimap(
      InputIterator _First,
      InputIterator _Last,
      const Compare& _Comp
   );
template<class InputIterator>
   hash_multimap(
      InputIterator _First,
      InputIterator _Last,
      const Compare& _Comp,
      const Allocator& _Al
   );
hash_multimap(
   hash_multimap&& _Right
);

Parametri

Parametro

Descrizione

_Al

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

_Comp

La funzione di confronto di tipo constTraits utilizzato per ordinare gli elementi nel mapping, che viene impostata come predefinita su Traits.

_Right

Il mapping di cui il 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 il hash_multimap e che successivamente può essere restituito chiamando 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 il hash_multimap.

Tutti i costruttori archiviano un oggetto funzione di tipo Traits utilizzato per stabilire un ordine tra le chiavi di hash_multimap e che successivamente può essere restituito chiamando key_comp.

I primi tre costruttori specificano un hash_multimap iniziale 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 del hash_multimap _Right.

I tre costruttori seguenti copia dell'intervallo [_First, _Last) di un mapping con l'aumento di chiarezza nello specificare il tipo di funzione di confronto di classe Traits e di allocatore.

l'ultimo costruttore sposta il hash_multimap _Right.

In Visual C++ .NET 2003, i membri dei file di intestazione <hash_set> e <hash_map> non sono più nello spazio dei nomi di deviazione standard, ma sono stati spostati nello spazio dei nomi di stdext.Per ulteriori informazioni, vedere lo spazio dei nomi stdext.

Esempio

// hash_multimap_hash_multimap.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   typedef pair <int, int> Int_Pair;
   hash_multimap <int, int>::iterator hm1_Iter, hm3_Iter, hm4_Iter, 
      hm5_Iter, hm6_Iter;
   hash_multimap <int, int, hash_compare <int, greater<int> > 
      >::iterator hm2_Iter;

   // Create an empty hash_multimap hm0 of key type integer
   hash_multimap <int, int> hm0;

   // Create an empty hash_multimap hm1 with the key comparison
   // function of less than, then insert 4 elements
   hash_multimap <int, int, hash_compare <int, less<int> > > hm1;
   hm1.insert( Int_Pair( 1, 10 ) );
   hm1.insert( Int_Pair( 2, 20 ) );
   hm1.insert( Int_Pair( 3, 30 ) );
   hm1.insert( Int_Pair( 4, 40 ) );

   // Create an empty hash_multimap hm2 with the key comparison
   // function of greater than, then insert 2 elements
   hash_multimap <int, int, hash_compare <int, greater<int> > > hm2;
   hm2.insert( Int_Pair( 1, 10 ) );
   hm2.insert( Int_Pair( 2, 20 ) );

   // Create a hash_multimap hm3 with the 
   // allocator of hash_multimap hm1
   hash_multimap <int, int>::allocator_type hm1_Alloc;
   hm1_Alloc = hm1.get_allocator( );
   hash_multimap <int, int> hm3( hash_compare <int, less<int> > ( ), 
      hm1_Alloc );
   hm3.insert( Int_Pair( 3, 30 ) );

   // Create a copy, hash_multimap hm4, of hash_multimap hm1
   hash_multimap <int, int> hm4( hm1 );

   // Create a hash_multimap hm5 by copying the range hm1[_First, _Last)
   hash_multimap <int, int>::const_iterator hm1_bcIter, hm1_ecIter;
   hm1_bcIter = hm1.begin( );
   hm1_ecIter = hm1.begin( );
   hm1_ecIter++;
   hm1_ecIter++;
   hash_multimap <int, int> hm5( hm1_bcIter, hm1_ecIter );

   // Create a hash_multimap hm6 by copying the range hm4[_First, _Last)
   // and with the allocator of hash_multimap hm2
   hash_multimap <int, int>::allocator_type hm2_Alloc;
   hm2_Alloc = hm2.get_allocator( );
   hash_multimap <int, int> hm6(hm4.begin( ), ++hm4.begin( ), less<int>( ), 
      hm2_Alloc);

   cout << "hm1 = ";
   for ( hm1_Iter = hm1.begin( ); hm1_Iter != hm1.end( ); hm1_Iter++ )
      cout << hm1_Iter -> second << " ";
   cout << endl;
   
   cout << "hm2 = ";
   for ( hm2_Iter = hm2.begin( ); hm2_Iter != hm2.end( ); hm2_Iter++ )
   cout << hm2_Iter -> second << " ";
   cout << endl;

   cout << "hm3 = ";
   for ( hm3_Iter = hm3.begin( ); hm3_Iter != hm3.end( ); hm3_Iter++ )
      cout << hm3_Iter -> second << " ";
   cout << endl;

   cout << "hm4 = ";
   for ( hm4_Iter = hm4.begin( ); hm4_Iter != hm4.end( ); hm4_Iter++ )
      cout << hm4_Iter -> second << " ";
   cout << endl;

   cout << "hm5 = ";
   for ( hm5_Iter = hm5.begin( ); hm5_Iter != hm5.end( ); hm5_Iter++ )
      cout << hm5_Iter -> second << " ";
   cout << endl;

   cout << "hm6 = ";
   for ( hm6_Iter = hm6.begin( ); hm6_Iter != hm6.end( ); hm6_Iter++ )
      cout << hm6_Iter -> second << " ";
   cout << endl;

    // Create a copy, hash_map hm7, of hash_multimap hm1 by moving
    hash_map<MyStr, MyInt, hash_compare<MyStr, less_str> >
        hm7(move(hm1));
    cout << "hm7 =";
    for (hm7_Iter = hm7.begin(); hm7_Iter != hm7.end(); hm7_Iter++)
        cout << " " << hm7_Iter -> second;
    cout << endl;
}

Output

hm1 = 10 20 30 40 
hm2 = 10 20 
hm3 = 30 
hm4 = 10 20 30 40 
hm5 = 10 20 
hm6 = 10 
hm7 = 10 20 30 40

Requisiti

intestazione: <hash_map>

Stdext diSpazio dei nomi:

Vedere anche

Riferimenti

hash_multimap Class

Libreria di modelli standard