std::unordered_multiset<Key,Hash,KeyEqual,Allocator>::unordered_multiset

来自cppreference.com

 
 
 
 
(1)
unordered_multiset()
    : unordered_multiset(size_type(/* 未指定 */)) {}
(C++11 起)
(C++20 前)
unordered_multiset();
(C++20 起)
explicit unordered_multiset( size_type bucket_count,

                             const Hash& hash = Hash(),
                             const key_equal& equal = key_equal(),

                             const Allocator& alloc = Allocator() );
(2)(C++11 起)
unordered_multiset( size_type bucket_count,

                    const Allocator& alloc )

    : unordered_multiset(bucket_count, Hash(), key_equal(), alloc) {}
(3)(C++14 起)
unordered_multiset( size_type bucket_count,

                    const Hash& hash,
                    const Allocator& alloc )

    : unordered_multiset(bucket_count, hash, key_equal(), alloc) {}
(4)(C++14 起)
explicit unordered_multiset( const Allocator& alloc );
(5)(C++11 起)
template< class InputIt >

unordered_multiset( InputIt first, InputIt last,
                    size_type bucket_count = /* 未指定 */,
                    const Hash& hash = Hash(),
                    const key_equal& equal = key_equal(),

                    const Allocator& alloc = Allocator() );
(6)(C++11 起)
template< class InputIt >

unordered_multiset( InputIt first, InputIt last,
                    size_type bucket_count,
                    const Allocator& alloc )
    : unordered_multiset(first, last,

                         bucket_count, Hash(), key_equal(), alloc) {}
(7)(C++14 起)
template< class InputIt >

unordered_multiset( InputIt first, InputIt last,
                    size_type bucket_count,
                    const Hash& hash,
                    const Allocator& alloc )
    : unordered_multiset(first, last,

                         bucket_count, hash, key_equal(), alloc) {}
(8)(C++14 起)
unordered_multiset( const unordered_multiset& other );
(9)(C++11 起)
unordered_multiset( const unordered_multiset& other, const Allocator& alloc );
(10)(C++11 起)
unordered_multiset( unordered_multiset&& other );
(11)(C++11 起)
unordered_multiset( unordered_multiset&& other, const Allocator& alloc );
(12)(C++11 起)
unordered_multiset( std::initializer_list<value_type> init,

                    size_type bucket_count = /* 未指定 */,
                    const Hash& hash = Hash(),
                    const key_equal& equal = key_equal(),

                    const Allocator& alloc = Allocator() );
(13)(C++11 起)
unordered_multiset( std::initializer_list<value_type> init,

                    size_type bucket_count,
                    const Allocator& alloc )
    : unordered_multiset(init, bucket_count,

                         Hash(), key_equal(), alloc) {}
(14)(C++14 起)
unordered_multiset( std::initializer_list<value_type> init,

                    size_type bucket_count,
                    const Hash& hash,
                    const Allocator& alloc )
    : unordered_multiset(init, bucket_count,

                         hash, key_equal(), alloc) {}
(15)(C++14 起)
template< container-compatible-range<value_type> R >

unordered_multiset( std::from_range_t, R&& rg,
                    size_type bucket_count = /* 见说明 */,
                    const Hash& hash = Hash(),
                    const key_equal& equal = key_equal(),

                    const Allocator& alloc = Allocator() );
(16)(C++23 起)
template< container-compatible-range<value_type> R >

unordered_multiset( std::from_range_t, R&& rg,
                    size_type bucket_count,
                    const Allocator& alloc )
    : unordered_multiset(std::from_range, std::forward<R>(rg),

                         bucket_count, Hash(), key_equal(), alloc) {}
(17)(C++23 起)
template< container-compatible-range<value_type> R >

unordered_multiset( std::from_range_t, R&& rg,
                    size_type bucket_count,
                    const Hash& hash,
                    const Alloc& alloc )
    : unordered_multiset(std::from_range, std::forward<R>(rg),

                         bucket_count, hash, key_equal(), alloc) {}
(18)(C++23 起)

从各种数据源构造新容器。可选的以用户提供的 bucket_count 为用于创建的最小桶数,以 hash 为散列函数,以 equal 为比较键的函数,并以 alloc 为分配器。

1-5) 构造空容器。设置 max_load_factor()1.0。对于默认构造函数,桶数是未指明的。
6-8) 构造具有范围 [firstlast) 的内容的容器。设置 max_load_factor()1.0
9,10)复制构造函数。构造拥有 other 内容副本的容器,一同复制加载因子、谓词和散列函数。如果没有提供 alloc,那么就会通过调用 std::allocator_traits<allocator_type>::select_on_container_copy_construction(other.get_allocator()) 获得分配器。

在用于类模板实参推导时,仅从首个实参推导模板形参 Allocator

(C++23 起)
11,12)移动构造函数。用移动语义构造拥有 other 的内容的容器。如果没有提供 alloc,那么就会通过从属于 other 的分配器进行移动构造来获得分配器。

在用于类模板实参推导时,仅从首个实参推导模板形参 Allocator

(C++23 起)
13-15)初始化器列表构造函数。构造拥有 init 的内容的容器,同 unordered_multiset(init.begin(), init.end())
16-18) 构造拥有 rg 的内容的容器。

参数

alloc-用于此容器所有内存分配器的分配器
bucket_count-初始化时用的最小桶数。若不指定,则使用未指明的默认值
hash-要用的散列函数
equal-用于进行此容器所有的键比较的比较函数
first, last-要复制的源元素范围的迭代器对
rg-容器兼容范围,即其元素可以转换为 value_typeinput_range
other-用作源以初始化容器元素的另一容器
init-用以初始化容器元素的 initializer_list
类型要求
-
InputIt 必须满足老式输入迭代器 (LegacyInputIterator)

复杂度

1-5) 常数。
6-8) 平均情况是线性(即 O(N),其中 Nstd::distance(first, last)),最坏情况是平方,即 O(N2)
9,10)other 的大小成线性。
11,12) 常数。给定 allocalloc != other.get_allocator() 时是线性。
13-15) 平均情况是 O(N)Nstd::size(init)),最坏情况是 O(N2)
16-18) 平均情况是 O(N)Nranges::distance(rg)),最坏情况是 O(N2)

异常

Allocator::allocate 的调用可能会抛出。

注解

在容器移动构造(重载 (4))后,指向 other 的引用及迭代器(除了尾迭代器)保持合法,但将指代现于 *this 中的元素。当前标准由 [container.requirements.general]/12 中的总括陈述作出此保证,而 LWG 问题 2321 正在考虑更严格的保证。

尽管在 C++23 前未正式要求,一些实现已经在较早的模式中将 Allocator 放入非推导语境

功能特性测试标准功能特性
__cpp_lib_containers_ranges202202L(C++23)按范围构造和插入; 重载 (16-18)

示例

缺陷报告

下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。

缺陷报告应用于出版时的行为正确行为
LWG 2193C++11默认构造函数是 explicit 的使之为非 explicit 的
LWG 2230C++11未指定重载 (13) 的语义指定语义

参阅

将值赋给容器
(公开成员函数)