deduction guides for
std::unordered_map
|
定义于头文件
<unordered_map>
|
||
|
template
<
class
InputIt,
class
Hash
=
std::
hash
<
/*iter-key-t*/
<
InputIt
>>
,
|
(1) | (自 C++17 起) |
|
template
<
class
Key,
class
T,
class
Hash
=
std::
hash
<
Key
>
,
class
Pred
=
std::
equal_to
<
Key
>
,
|
(2) | (自 C++17 起) |
|
template
<
class
InputIt,
class
Alloc
>
unordered_map
(
InputIt, InputIt,
typename
/* 见下文 */
::
size_type
, Alloc
)
|
(3) | (自 C++17 起) |
|
template
<
class
InputIt,
class
Alloc
>
unordered_map
(
InputIt, InputIt, Alloc
)
|
(4) | (自 C++17 起) |
|
template
<
class
InputIt,
class
Hash,
class
Alloc
>
unordered_map
(
InputIt, InputIt,
typename
/* 见下文 */
::
size_type
, Hash,
|
(5) | (自 C++17 起) |
|
template
<
class
Key,
class
T,
typename
Alloc
>
unordered_map
(
std::
initializer_list
<
std::
pair
<
Key, T
>>
,
|
(6) | (自 C++17 起) |
|
template
<
class
Key,
class
T,
typename
Alloc
>
unordered_map
(
std::
initializer_list
<
std::
pair
<
Key, T
>>
, Alloc
)
|
(7) | (自 C++17 起) |
|
template
<
class
Key,
class
T,
class
Hash,
class
Alloc
>
unordered_map
(
std::
initializer_list
<
std::
pair
<
Key, T
>>
,
|
(8) | (C++17 起) |
|
template
<
ranges::
input_range
R,
class
Hash
=
std::
hash
<
/*range-key-t*/
<
R
>>
,
|
(9) | (自 C++23 起) |
|
template
<
ranges::
input_range
R,
class
Alloc
>
unordered_map
(
std::
from_range_t
, R
&&
,
|
(10) | (C++23 起) |
|
template
<
ranges::
input_range
R,
class
Alloc
>
unordered_map
(
std::
from_range_t
, R
&&
, Alloc
)
|
(11) | (自 C++23 起) |
|
template
<
ranges::
input_range
R,
class
Hash,
class
Alloc
>
unordered_map
(
std::
from_range_t
, R
&&
,
typename
/* 见下文 */
::
size_type
,
|
(12) | (自 C++23 起) |
|
仅用于说明的辅助类型别名
|
||
|
template
<
class
InputIt
>
using
/*iter-val-t*/
=
|
( 仅用于说明* ) | |
|
template
<
class
InputIt
>
using
/*iter-key-t*/
=
|
( 仅用于说明* ) | |
|
template
<
class
InputIt
>
using
/*iter-mapped-t*/
=
|
( 仅用于说明* ) | |
|
template
<
class
InputIt
>
using
/*iter-to-alloc-t*/
=
|
( 仅用于说明* ) | |
|
template
<
ranges::
input_range
Range
>
using
/*range-key-t*/
=
|
(自 C++23 起)
( 仅用于说明* ) |
|
|
template
<
ranges::
input_range
Range
>
using
/*range-mapped-t*/
=
|
(始于 C++23)
( 仅用于说明* ) |
|
|
template
<
ranges::
input_range
Range
>
using
/*range-to-alloc-t*/
=
|
(自 C++23 起)
( 仅用于说明* ) |
|
这些重载仅在满足以下条件时参与重载决议:
InputIt
满足
LegacyInputIterator
、
Alloc
满足
Allocator
、
Hash
与
Pred
均不满足
Allocator
,且
Hash
不是整数类型。
注意:库判定类型不满足
LegacyInputIterator
要求的程度是未指定的,但至少整型类型不符合输入迭代器的要求。同样地,库判定类型不满足
Allocator
要求的程度也是未指定的,但至少要求成员类型
Alloc::value_type
必须存在,且表达式
std::
declval
<
Alloc
&
>
(
)
.
allocate
(
std::
size_t
{
}
)
在被视为未求值操作数时必须保持良构。
这些指南中的
size_type
参数类型指的是由推导指南推导出的类型的
size_type
成员类型。
注释
| 功能测试 宏 | 值 | 标准 | 功能特性 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | 支持范围 的构造与插入;重载 ( 9-12 ) |
示例
#include <unordered_map> int main() { // std::unordered_map m1 = {{"foo", 1}, {"bar", 2}}; // 错误:大括号初始化列表没有类型:无法 // 从 {"foo", 1} 或 {"bar", 2} 推导 pair<Key, T> std::unordered_map m1 = {std::pair{"foo", 2}, {"bar", 3}}; // 指南 #2 std::unordered_map m2(m1.begin(), m1.end()); // 指南 #1 }
缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
| DR | 适用版本 | 发布行为 | 正确行为 |
|---|---|---|---|
| LWG 3025 | C++17 | 初始化列表推导指引 ( 2 ) 和 ( 6-8 ) 采用 std:: pair < const Key, T > | 改用 std:: pair < Key, T > |