다음을 통해 공유


multiset::multiset

비어 있거나 모든 복사본이거나 또는 일부 다른 mutiset 부분인 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
    );

매개 변수

Parameter

설명

Al

Allocator 기본값인 이 multiset 개체에 사용할 저장소 할당자 클래스 입니다.

Comp

const Compare 종류의 비교 함수는 Compare 기본적으로 하는 복수 집합의 요소를 정렬하는데 사용됩니다.

Right

복수 집합 복사본으로 구성 된 복수 집합 입니다.

First

복사할 요소의 범위에 있는 첫 번째 요소의 위치입니다.

Last

복사할 요소의 범위를 벗어나는 첫 번째 요소의 위치입니다.

IList

요소를 복사할 initializer_list.

설명

모든 생성자는 multiset에 대한 메모리 저장소를 관리하는 할당자 개체의 형식을 저장하고 get_allocator 호출함으로써 나중에 호출될 수 있습니다. 할당자 매개 변수는 클래스 선언과 대체 할당자를 대체하는데 사용되는 전처리 매크로에서 종종 생략됩니다.

모든 생성자는 multiset을 초기화합니다.

모든 생성자는 Compare 형식의 함수 개체를 저장합니다. 그것은 multiset의 키들 사이의 순서를 설정하는데 사용되고 key_comp를 호출함으로써 나중에 반환될 수 있습니다.

처음 세 개의 생성자는 빈 초기 multiset를 지정하고, 두 번째는 요소들의 순서를 설정하는데 사용되는 비교 함수 (Comp) 형식을 지정하고 세번째는 명시적으로 할당자 형식 (Al)를 사용하기 위해 지정합니다. 키워드 explicit 는 자동 형식 변환의 특정 종류를 표시 하지 않습니다.

네 번째 생성자는 multiset Right의 사본을 지정합니다.

다섯번째 생성자는 multiset의 복사본을 Right을 이동함으로써 지정합니다.

여섯 번째, 일곱 번째 및 8 번째 생성자는 initializer_list 요소를 복사 하는 지정 합니다.

다음 세 가지 생성자는 multiset의 [First, Last) 범위를 할당자 및 비교 함수의 종류를 지정하는 명시적인 증가와 함께 복사합니다.

예제

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

Output

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

요구 사항

헤더: <설정>

네임스페이스: std

참고 항목

참조

multiset 클래스

표준 템플릿 라이브러리