Udostępnij za pośrednictwem


multiset::multiset

Konstruuje multiset, który jest pusty lub jest kopią całości lub części innego multiset.

multiset( );
explicit multiset (
    const Compare& Comp
);
multiset (
    const Compare& Comp,
    const Allocator& Al
);
multiset(
    const multiset& Right
);
multiset(
    multiset&& Right
);
multiset(
    initializer_list<Type> IList
);

multiset(
    initializer_list<Type> IList, 
    const Compare& Comp
);

multiset(
    initializer_list<Type> IList, 
    const Compare& Comp, 
    const Allocator& Al
);

template<class InputIterator> 
    multiset (
        InputIterator First,
        InputIterator Last
    );
template<class InputIterator> 
    multiset (
        InputIterator First,
        InputIterator Last,
        const Compare& Comp
    );
template<class InputIterator>
    multiset (
        InputIterator First,
        InputIterator Last,
        const Compare& Comp,
        const Allocator& Al
    );

Parametry

Parametr

Opis

Al

Klasa przydzielania pamięci do użycia w tym obiekcie multiset, domyślnie to Allocator.

Comp

Funkcja porównywania typu const Compare używana do uporządkowania elementów w multiset, domyślnie to Compare.

Right

Multiset, którego kopią jest utworzony multiset.

First

Pozycja pierwszego elementu w zakresie elementów, który ma być skopiowany.

Last

Pozycja pierwszego elementu poza zakresem elementów, które mają zostać skopiowane.

IList

initializer_list, z której należy skopiować elementy.

Uwagi

Wszystkie konstruktory przechowują typ obiektu programu przydzielania, który zarządza pamięcią dla multiset i później może być zwrócony przez wywołanie get_allocator.Parametr programu przydzielania jest często omijany w deklaracjach klas i makra przetwarzające pierwotnie są używane do zastąpienia alternatywnych programów przydzielania.

Wszystkie konstruktory inicjują ich multiset.

Wszystkie konstruktory przechowują obiekt funkcji typu Compare, służący do ustalenia kolejności wśród kluczy multiset i który później może być zwrócony przez wywołanie key_comp.

Pierwsze trzy konstruktory określają pusty początkowy multiset, dodatkowo, drugi określający typ funkcji porównania (Comp) stosowanej przy ustalaniu kolejności elementów, a trzeci jawnie określający typ programu przydzielania (Al), który ma być użyty.Słowo kluczowe explicit powoduje pominięcie niektórych rodzajów automatycznej konwersji typów.

Czwarty konstruktor określa kopię multiset Right.

Trzeci konstruktor określa kopię multiset, przesuwając Right.

Szósty, siódmy i ósmy konstruktor określa initializer_list, z której kopiuje elementy.

Kolejne trzy konstruktory kopiują zakres [First, Last) z multiset z rosnącą jawnością w określaniu typu funkcji porównania i programu przydzielania.

Przykład

// multiset_ctor.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main()
{
    using namespace std;
    //multiset <int>::iterator ms1_Iter, ms2_Iter, ms3_Iter;
    multiset <int>::iterator ms4_Iter, ms5_Iter, ms6_Iter, ms7_Iter;

    // Create an empty multiset ms0 of key type integer
    multiset <int> ms0;

    // Create an empty multiset ms1 with the key comparison
    // function of less than, then insert 4 elements
    multiset <int, less<int> > ms1;
    ms1.insert(10);
    ms1.insert(20);
    ms1.insert(20);
    ms1.insert(40);

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

    // Create a multiset ms3 with the 
    // allocator of multiset ms1
    multiset <int>::allocator_type ms1_Alloc;
    ms1_Alloc = ms1.get_allocator();
    multiset <int> ms3(less<int>(), ms1_Alloc);
    ms3.insert(30);

    // Create a copy, multiset ms4, of multiset ms1
    multiset <int> ms4(ms1);

    // Create a multiset ms5 by copying the range ms1[_First, _Last)
    multiset <int>::const_iterator ms1_bcIter, ms1_ecIter;
    ms1_bcIter = ms1.begin();
    ms1_ecIter = ms1.begin();
    ms1_ecIter++;
    ms1_ecIter++;
    multiset <int> ms5(ms1_bcIter, ms1_ecIter);

    // Create a multiset ms6 by copying the range ms4[_First, _Last)
    // and with the allocator of multiset ms2
    multiset <int>::allocator_type ms2_Alloc;
    ms2_Alloc = ms2.get_allocator();
    multiset <int> ms6(ms4.begin(), ++ms4.begin(), less<int>(), ms2_Alloc);

    cout << "ms1 =";
    for (auto i : ms1)
        cout << " " << i;
    cout << endl;

    cout << "ms2 =";
    for (auto i : ms2)
        cout << " " << i;
   cout << endl;

   cout << "ms3 =";
   for (auto i : ms3)
       cout << " " << i;
    cout << endl;

    cout << "ms4 =";
    for (auto i : ms4)
        cout << " " << i;
    cout << endl;

    cout << "ms5 =";
    for (auto i : ms5)
        cout << " " << i;
    cout << endl;

    cout << "ms6 =";
    for (auto i : ms6)
        cout << " " << i;
    cout << endl;

    // Create a multiset by moving ms5
    multiset<int> ms7(move(ms5));
    cout << "ms7 =";
    for (auto i : ms7)
        cout << " " << i;
    cout << endl;

    // Create a multiset with an initializer_list
    multiset<int> ms8({1, 2, 3, 4});
    cout << "ms8=";
    for (auto i : ms8)
        cout << " " << i;
    cout << endl;
}

Dane wyjściowe

ms1 = 10 20 20 40
ms2 = 10 20
ms3 = 30
ms4 = 10 20 20 40
ms5 = 10 20
ms6 = 10
ms7 = 10 20
ms8= 1 2 3 4

Wymagania

Nagłówek: <set>

Przestrzeń nazw: std

Zobacz też

Informacje

multiset — Klasa

Standardowa biblioteka szablonów