次の方法で共有


multimap::multimap

空の multimap、または他の multimap の全体または一部のコピーである multimap を構築します。

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
    );

パラメーター

パラメーター

説明

Al

この multimap オブジェクトに使用するストレージ アロケーター クラス。既定では、Allocator です。

Comp

map 内の要素の並べ替えに使用される、const Traits 型の比較関数。既定では Traits です。

Right

構築される map のコピー元となる map。

First

コピーする要素範囲内の最初の要素の位置。

Last

コピーする要素範囲を超える最初の要素の位置。

IList

要素のコピー元の initializer_list。

解説

すべてのコンストラクターは、アロケーター オブジェクトの型を格納します。このオブジェクトは multimap のメモリ ストレージを管理し、後で get_allocator を呼び出して取得することができます。 代替アロケーターの代わりに使用されるクラス宣言やプリプロセス マクロでは、アロケーターのパラメーターが省略される場合があります。

すべてのコンストラクターは、それぞれの multimap を初期化します。

すべてのコンストラクターは、Traits 型の関数オブジェクトを格納します。このオブジェクトは multimap のキーの順序を確立するために使用され、後で key_comp を呼び出して取得することができます。

最初の 3 つのコンストラクターは、空の初期 multimap を指定します。2 番目のコンストラクターは要素の順序を確立するために使用する比較関数の型 (Comp) を指定し、3 番目のコンストラクターは使用するアロケーターの型 (Al) を明示的に指定します。 キーワード explicit は、特定の種類の自動型変換が実行されないようにします。

4 番目のコンストラクターは、multimap Right のコピーを指定します。

5 番目のコンストラクターは、Right を移動することによる multimap のコピーを指定します。

6 番目、7 番目、8 番目のコンストラクターは、initializer_list のメンバーをコピーします。

次の 3 つのコンストラクターは、map の範囲 [First, Last) をコピーします。下のコンストラクターになるほど、より明確に Traits クラスの比較関数と Allocator の型が指定されています。

使用例

// 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;

}

出力

  

必要条件

ヘッダー: <map>

名前空間: std

参照

関連項目

multimap クラス

標準テンプレート ライブラリ