Partager via


multimap::multimap

Construit un mappage multiple qui est vide ou qui est une copie de l'ensemble ou une partie d'un mappage multiple.

multimap( );
explicit multimap(
    const Traits& Comp
);
multimap(
    const Traits& Comp,
    const Allocator& Al
);
map(
    const multimap& Right
);
multimap(
    multimap&& Right
);
multimap(
    initializer_list<value_type> IList
);
multimap(
    initializer_list<value_type> IList,
    const Compare& Comp
);
multimap(
    initializer_list<value_type> IList,
    const Compare& Comp, 
    const Allocator& Al
);
template<class InputIterator>
    multimap(
        InputIterator First,
        InputIterator Last
    );
template<class InputIterator>
    multimap(
        InputIterator First,
        InputIterator Last,
        const Traits& Comp
    );
template<class InputIterator>
    multimap(
        InputIterator First,
        InputIterator Last,
        const Traits& Comp,
    const Allocator& Al
    );

Paramètres

Paramètre

Description

Al

La classe d'allocateur de stockage à utiliser pour cet objet de mappage multiple, qui correspond par défaut à l'allocateur.

Comp

La fonction de comparaison du type Const Caractéristiques utilisée pour trier les éléments dans le mappage, qui correspond par défaut à Caractéristiques.

Right

Le mappage dans laquelle le set générée doit être une copie.

First

Position du premier élément dans la plage d'éléments à copier.

Last

Position du premier élément au delà de la plage d'éléments à copier.

IList

L'initializer_list depuis laquelle copier les éléments.

Notes

Tous les constructeurs stockent un type d'objet d'allocation qui gère le stockage de mémoire pour le mappage multiple et qui peut ensuite être retourné en appelant get_allocator. Le paramètre d'allocateur est souvent omis dans les déclarations de classe et les macros de prétraitement utilisées pour substituer d'autres allocateurs.

Tous les constructeurs initialisent leur mappage multiple.

Tous les constructeurs stockent un objet de fonction de type Traits qui est utilisé pour établir un ordre entre les clés du mappage multiple et qui peut ensuite être retourné en appelant key_comp.

Les trois premiers constructeurs spécifient un mappage multiple initial vide, le deuxième spécifie le type de fonction de comparaison (Comp) à utiliser pour établir l'ordre des éléments et le troisième spécifie explicitement le type d'allocateur (Al) à utiliser. Le mot clé explicit supprime certains genres de conversion de type automatique.

Le quatrième constructeur spécifie une copie du mappage multiple Right.

Le cinquième constructeur spécifie une copie du mappage multiple en déplaçant Right.

Le sixième, le septième, et le huitième constructeurs copient les membres d'un initializer_list.

Les trois constructeurs suivants copient la plage [First, Last) d'un mappage avec une explicité accrue en spécifiant le type de fonction de comparaison de la classe Caractéristiques et de l'allocateur.

Exemple

// multimap_ctor.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main()
{
    using namespace std;
    typedef pair <int, int> Int_Pair;

    // Create an empty multimap m0 of key type integer
    multimap <int, int> m0;

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

    // Create an empty multimap m2 with the key comparison
    // function of geater than, then insert 2 elements
    multimap <int, int, less<int> > m2;
    m2.insert(Int_Pair(1, 10));
    m2.insert(Int_Pair(2, 20));

    // Create a multimap m3 with the 
    // allocator of multimap m1
    multimap <int, int>::allocator_type m1_Alloc;
    m1_Alloc = m1.get_allocator();
    multimap <int, int> m3(less<int>(), m1_Alloc);
    m3.insert(Int_Pair(3, 30));

    // Create a copy, multimap m4, of multimap m1
    multimap <int, int> m4(m1);

    // Create a multimap m5 by copying the range m1[_First, _Last)
    multimap <int, int>::const_iterator m1_bcIter, m1_ecIter;
    m1_bcIter = m1.begin();
    m1_ecIter = m1.begin();
    m1_ecIter++;
    m1_ecIter++;
    multimap <int, int> m5(m1_bcIter, m1_ecIter);

    // Create a multimap m6 by copying the range m4[_First, _Last)
    // and with the allocator of multimap m2
    multimap <int, int>::allocator_type m2_Alloc;
    m2_Alloc = m2.get_allocator();
    multimap <int, int> m6(m4.begin(), ++m4.begin(), less<int>(), m2_Alloc);

    cout << "m1 =";
    for (auto i : m1)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m2 =";
    for (auto i : m2)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m3 =";
    for (auto i : m3)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m4 =";
    for (auto i : m4)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m5 =";
    for (auto i : m5)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m6 =";
    for (auto i : m6)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    // Create a multimap m8 by copying in an initializer_list
    multimap<int, int> m8{ { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 } } };
    cout << "m8: = ";
    for (auto i : m8)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    // Create a multimap m9 with an initializer_list and a comparator
    multimap<int, int> m9({ { 5, 5 }, { 6, 6 }, { 7, 7 }, { 8, 8 } }, less<int>());
    cout << "m9: = ";
    for (auto i : m9)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    // Create a multimap m10 with an initializer_list, a comparator, and an allocator
    multimap<int, int> m10({ { 9, 9 }, { 10, 10 }, { 11, 11 }, { 12, 12 } }, less<int>(), m9.get_allocator());
    cout << "m10: = ";
    for (auto i : m10)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

}

Sortie

  

Configuration requise

En-tête : <mappage>

Espace de noms : std

Voir aussi

Référence

multimap, classe

Bibliothèque STL (Standard Template Library)