Udostępnij za pośrednictwem


unordered_multimap::unordered_multimap

Konstruuje obiekt kontenera.

unordered_multimap(
    const unordered_multimap& Right
);
explicit unordered_multimap(
    size_type Bucket_count = N0,
    const Hash& Hash = Hash(),
    const Comp& Comp = Pred(),
    const Allocator& Al = Alloc()
);
unordered_multimap(
    unordered_multimap&& Right
);
unordered_multimap(
    initializer_list<Type> IList
);
unordered_multimap(
    initializer_list< Type > IList,
    size_type Bucket_count
);
unordered_multimap(
    initializer_list< Type > IList,
    size_type Bucket_count, 
    const Hash& Hash
);
unordered_multimap(
    initializer_list< Type > IList,
    size_type Bucket_count, 
    const Hash& Hash,
    const Key& Key
);
unordered_multimap(
    initializer_list<Type> IList,
    size_type Bucket_count, 
    const Hash& Hash,
    const Key& Key, 
    const Allocator& Al
);
template<class InputIterator>
    unordered_multimap(
        InputIterator first, 
        InputIterator last,
        size_type Bucket_count = N0,
        const Hash& Hash = Hash(),
        const Comp& Comp = Pred(),
        const Allocator& Al = Alloc()
    );

Parametry

Parametr

Opis

InputIterator

Typ iteratora.

Al

Obiekt alokatora, który ma być przechowywany.

Comp

Obiekt funkcji porównywania, który ma być przechowywany.

Hash

Obiekt funkcji mieszania, który ma być przechowywany.

Bucket_count

Minimalna liczba przedziałów.

Right

Kontener, który ma być skopiowany.

IList

Lista initializer_list, z której mają być skopiowane elementy.

Uwagi

Pierwszy konstruktor określa kopię sekwencji kontrolowanej przez Right.Drugi konstruktor określa pustą kontrolowaną sekwencję.Trzeci konstruktor określa kopię sekwencji, przesuwając Right.Konstruktory czwarty, piąty, szósty, siódmy i ósmy używają initializer_list dla elementów członkowskich.Dziewiąty konstruktor wstawia sekwencję wartości elementu [First, Last).

Wszystkie konstruktory również inicjują kilka przechowywanych wartości.Wartości dla konstruktora kopiującego są uzyskiwane z Right.W przeciwnym razie:

Minimalna liczba przedziałów jest argumentem Bucket_count, jeśli jest obecna; w przeciwnym razie jest to wartość domyślna opisana tutaj jako wartość zdefiniowana w implementacji N0.

Obiekt funkcji mieszania jest argumentem Hash, jeśli jest obecny; w przeciwnym razie jest to Hash().

Obiekt funkcji porównywania jest argumentem Comp, jeśli jest obecny; w przeciwnym razie jest to Pred().

Obiekt alokatora jest argumentem Al, jeśli jest obecny; w przeciwnym razie jest to Alloc().

Przykład

// std__unordered_map__unordered_multimap_construct.cpp 
// compile with: /EHsc 
#include <unordered_map> 
#include <iostream> 

using namespace std;

using  Mymap = unordered_multimap<char, int> ;
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 (const auto& c : c1) {
        cout << " [" << c.first << ", " << c.second << "]";
    }
    cout << endl;


    Mymap c2(8,
        hash<char>(),
        equal_to<char>(),
        allocator<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 (const auto& c : c2) {
        cout << " [" << c.first << ", " << c.second << "]";
    }
    cout << endl;

    Mymap c3(c1.begin(),
        c1.end(),
        8,
        hash<char>(),
        equal_to<char>(),
        allocator<pair<const char, int> >());

    // display contents " [c 3] [b 2] [a 1]" 
    for (const auto& c : c3) {
        cout << " [" << c.first << ", " << c.second << "]";
    }
    cout << endl;

    Mymap c4(move(c3));

    // display contents " [c 3] [b 2] [a 1]" 
    for (const auto& c : c4) {
        cout << " [" << c.first << ", " << c.second << "]";
    }
    cout << endl;

    // Construct with an initializer_list
    unordered_multimap<int, char> c5({ { 5, 'g' }, { 6, 'h' }, { 7, 'i' }, { 8, 'j' } });
    for (const auto& c : c5) {
        cout << " [" << c.first << ", " << c.second << "]";
    }
    cout << endl;

    // Initializer_list plus size
    unordered_multimap<int, char> c6({ { 5, 'g' }, { 6, 'h' }, { 7, 'i' }, { 8, 'j' } }, 4);
    for (const auto& c : c1) {
        cout << " [" << c.first << ", " << c.second << "]";
    }
    cout << endl;

    // Initializer_list plus size and hash
    unordered_multimap<int, char, tr1::hash<char>> c7(
        { { 5, 'g' }, { 6, 'h' }, { 7, 'i' }, { 8, 'j' } },
        4,
        tr1::hash<char>()
    );

    for (const auto& c : c1) {
        cout << " [" << c.first << ", " << c.second << "]";
    }
    cout << endl;

    // Initializer_list plus size, hash, and key_equal
    unordered_multimap<int, char, tr1::hash<char>, equal_to<char>> c8(
        { { 5, 'g' }, { 6, 'h' }, { 7, 'i' }, { 8, 'j' } },
        4,
        tr1::hash<char>(),
        equal_to<char>()
    );

    for (const auto& c : c1) {
        cout << " [" << c.first << ", " << c.second << "]";
    }
    cout << endl;

    // Initializer_list plus size, hash, key_equal, and allocator
    unordered_multimap<int, char, tr1::hash<char>, equal_to<char>> c9(
        { { 5, 'g' }, { 6, 'h' }, { 7, 'i' }, { 8, 'j' } },
        4,
        tr1::hash<char>(),
        equal_to<char>(),
        allocator<pair<const char, int> >()
    );

    for (const auto& c : c1) {
        cout << " [" << c.first << ", " << c.second << "]";
    }
    cout << endl;
}
  

Wymagania

Nagłówek: <unordered_map>

Przestrzeń nazw: std

Zobacz też

Informacje

<unordered_map>

unordered_multimap — Klasa

Inne zasoby

<unordered_map> Członkowie