unordered_map::unordered_map
Construit un objet.
unordered_map(
const unordered_map& right);
explicit unordered_map(
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
template<class InIt>
unordered_map(
InIt first, InIt last,
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
unordered_map(
unordered_map&& right);
Paramètres
Paramètre |
Description |
InIt |
le type d'itérateur. |
al |
L'objet d'allocation dans le magasin. |
comp |
L'objet de fonction de comparaison dans le magasin. |
hfn |
L'objet de fonction de hachage dans le magasin. |
nbuckets |
Le nombre minimal de compartiments restant. |
right |
le conteneur à copier. |
Notes
le premier constructeur spécifie une copie de la séquence contrôlée par right.Le deuxième constructeur spécifie une séquence contrôlée vide.le troisième constructeur insère la séquence de valeurs d'élément [first, last).le quatrième constructeur spécifie une copie de la séquence en déplaçant right.
tous les constructeurs initialisent également plusieurs valeurs stockées.Pour le constructeur de copie, les valeurs sont obtenues à partir de right.Sinon :
le nombre minimal de compartiments est l'argument nbuckets, le cas échéant ; sinon il s'agit d'une valeur par défaut décrite ici comme valeur implémentation-définie N0.
l'objet de fonction de hachage est l'argument hfn, le cas échéant ; sinon c'est Hash().
l'objet de fonction de comparaison est l'argument comp, le cas échéant ; sinon c'est Pred().
l'objet d'allocation est l'argument al, le cas échéant ; sinon, il s'agit Alloc().
Exemple
// std_tr1__unordered_map__unordered_map_construct.cpp
// compile with: /EHsc
#include <unordered_map>
#include <iostream>
typedef std::unordered_map<char, int> Mymap;
int main()
{
Mymap c1;
c1.insert(Mymap::value_type('a', 1));
c1.insert(Mymap::value_type('b', 2));
c1.insert(Mymap::value_type('c', 3));
// display contents " [c 3] [b 2] [a 1]"
for (Mymap::const_iterator it = c1.begin();
it != c1.end(); ++it)
std::cout << " [" << it->first << ", " << it->second << "]";
std::cout << std::endl;
Mymap c2(8,
std::tr1::hash<char>(),
std::equal_to<char>(),
std::allocator<std::pair<const char, int> >());
c2.insert(Mymap::value_type('d', 4));
c2.insert(Mymap::value_type('e', 5));
c2.insert(Mymap::value_type('f', 6));
// display contents " [f 6] [e 5] [d 4]"
for (Mymap::const_iterator it = c2.begin();
it != c2.end(); ++it)
std::cout << " [" << it->first << ", " << it->second << "]";
std::cout << std::endl;
Mymap c3(c1.begin(),
c1.end(),
8,
std::tr1::hash<char>(),
std::equal_to<char>(),
std::allocator<std::pair<const char, int> >());
// display contents " [c 3] [b 2] [a 1]"
for (Mymap::const_iterator it = c3.begin();
it != c3.end(); ++it)
std::cout << " [" << it->first << ", " << it->second << "]";
std::cout << std::endl;
Mymap c4(std::move(c3));
// display contents " [c 3] [b 2] [a 1]"
for (Mymap::const_iterator it = c4.begin();
it != c4.end(); ++it)
std::cout << " [" << it->first << ", " << it->second << "]";
std::cout << std::endl;
return (0);
}
Configuration requise
en-tête : <unordered_map>
l'espace de noms : type