Namespaces
Variants

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

From zh.cppreference.net

(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,
桶数量 = /* 见描述 */ ,
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) 使用范围 [ first , last ) 的内容构造容器。将 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_type 的 input_range
other - 用作源以初始化容器元素的另一容器
init - 用于初始化容器元素的初始化列表
类型要求
-
InputIt 必须满足 LegacyInputIterator 的要求。

复杂度

1-5) 常量。
6-8) 平均情况线性(即 O(N) ,其中 N 为 std:: distance ( first, last ) ),最坏情况二次,即 O(N 2 ) 。
9,10) 与 other 的大小成线性关系。
11,12) 常量。若 alloc 被指定且 alloc ! = other. get_allocator ( ) ,则为线性复杂度。
13-15) 平均情况 O(N) ( N 为 std:: size ( init ) ),最坏情况 O(N 2 ) 。
16-18) 平均情况 O(N) ( N 为 ranges:: distance ( rg ) ),最坏情况 O(N 2 ) 。

异常处理

对 Allocator::allocate 的调用可能抛出异常。

注解

在容器移动构造(重载 (4))后,原本指向 other 中元素的引用、指针和迭代器仍然有效,但指向现在位于 *this 中的元素。当前标准通过 [container.reqmts]/67 中的总括性声明提供了此保证,并且通过 LWG issue 2321 正在考虑更直接的保证。

虽然直到 C++23 才被正式要求,但一些实现已经将模板参数 Allocator 在早期模式中放入 非推导语境。

功能测试宏 值 标准 功能
__cpp_lib_containers_ranges 202202L (C++23) Ranges感知构造和插入;重载 (16-18)

示例

缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。

DR 适用版本 发布时的行为 正确行为
LWG 2193 C++11 默认构造函数 ( 1 ) 为 explicit 改为非 explicit
LWG 2230 C++11 重载 ( 13 ) 的语义未指定 已指定

另请参阅

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