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

参数

参数

说明

Al

存储分配器类在多重集合对象中使用,默认遵守 Allocator

Comp

默认遵守的类型const Compare的比较函数用来排序多重集合中的元素,不能 Compare

Right

构造的多重集合是复制的多重集合。

First

要复制的元素范围中的第一个元素的位置。

Last

要复制的元素范围之外的第一个元素的位置。

IList

从initializer_list中复制元素。

备注

所有构造函数存储了一个为多重集合管理内存存储的分配器对象的类型并且此对象能够通过调用get_allocator返回。 分配器参数通常在所使用的类声明和用于替换分配器的预处理器宏被忽略。

所有构造函数初始化它们的多重集合。

所有的构造函数存储了一个用来在多重集合的关键值中建立排序的函数比较类型对象,并且接下来可以通过调用t3xh9bt5(v=vs.120).md 返回。

初始的三个构造函数指定了空的初始多重集合, 第二个构造函数则指定了用来建立元素次序的比较函数(Comp)的类型,第三个构造函数则明确指定了使用的分配器类型 (Al) 。 关键字explicit抑制了一些种类的自动类型转换。

第四个构造函数指定了多重集合Right 的副本。

第五个构造函数通过移动Right指定了多重集合的副本。

第六,第七和第七八个构造函数指定复制元素的initializer_list。

接下来的最后三个构造函数复制了在类和分配器的比较函数中明显增长的多重集合范围 [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

要求

标头: <set>

命名空间: std

请参见

参考

multiset 类

标准模板库