deduction guides for
std::unordered_set
|
定义于头文件
<unordered_set>
|
||
|
template
<
class
InputIt,
|
(1) | (C++17 起) |
|
template
<
class
T,
class
Hash
=
std::
hash
<
T
>
,
|
(2) | (自 C++17 起) |
|
template
<
class
InputIt,
class
Alloc
>
unordered_set
(
InputIt, InputIt,
typename
/* 详见下文 */
::
size_type
, Alloc
)
|
(3) | (C++17 起) |
|
template
<
class
InputIt,
class
Hash,
class
Alloc
>
unordered_set
(
InputIt, InputIt,
typename
/* 见下文 */
::
size_type
, Hash, Alloc
)
|
(4) | (自 C++17 起) |
|
template
<
class
T,
class
Alloc
>
unordered_set
(
std::
initializer_list
<
T
>
,
typename
/* 详见下文 */
::
size_type
, Alloc
)
|
(5) | (自 C++17 起) |
|
template
<
class
T,
class
Hash,
class
Alloc
>
unordered_set
(
std::
initializer_list
<
T
>
,
typename
/* 见下文 */
::
size_type
,
|
(6) | (自 C++17 起) |
|
template
<
ranges::
input_range
R,
class
Hash
=
std::
hash
<
ranges::
range_value_t
<
R
>>
,
|
(7) | (自 C++23 起) |
|
template
<
ranges::
input_range
R,
class
Alloc
>
unordered_set
(
std::
from_range_t
, R
&&
,
|
(8) | (C++23 起) |
|
template
<
ranges::
input_range
R,
class
Alloc
>
unordered_set
(
std::
from_range_t
, R
&&
, Alloc
)
|
(9) | (C++23 起) |
|
template
<
ranges::
input_range
R,
class
Hash,
class
Alloc
>
unordered_set
(
std::
from_range_t
, R
&&
,
|
(10) | (自 C++23 起) |
unordered_set
提供,以允许从迭代器范围(重载
(1,3,4)
)和
std::initializer_list
(重载
(2,5,6)
)进行推导。此重载仅当满足以下条件时参与重载决议:
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) | 支持范围 的构造与插入;重载函数 (7-10) |
示例
#include <unordered_set> int main() { // 指南 #2 推导出 std::unordered_set<int> std::unordered_set s = {1, 2, 3, 4}; // 指南 #1 推导出 std::unordered_set<int> std::unordered_set s2(s.begin(), s.end()); }