deduction guides for
std::vector
|
定义于头文件
<vector>
|
||
|
template
<
class
InputIt,
class
Alloc
=
std::
allocator
<
|
(1) | (C++17 起) |
|
template
<
ranges::
input_range
R,
class
Alloc
=
std::
allocator
<
ranges::
range_value_t
<
R
>>
>
|
(2) | (C++23 起) |
InputIt
满足
LegacyInputIterator
且
Alloc
满足
Allocator
时参与重载决议。
注意:库判定某个类型不满足
LegacyInputIterator
要求的程度是未指定的,但至少整型类型不符合输入迭代器的要求。同样地,库判定某个类型不满足
Allocator
要求的程度也是未指定的,但至少要求成员类型
Alloc::value_type
必须存在,且表达式
std::
declval
<
Alloc
&
>
(
)
.
allocate
(
std::
size_t
{
}
)
在作为未求值操作数处理时必须合法。
注释
| 功能测试 宏 | 值 | 标准 | 功能特性 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | 支持范围 的构造与插入;重载 (2) |
示例
#include <vector> int main() { std::vector<int> v = {1, 2, 3, 4}; // 使用显式推导指南推导 std::vector<int> std::vector x(v.begin(), v.end()); // 推导出 std::vector<std::vector<int>::iterator> // 列表初始化的重载决议第一阶段选择从初始化列表构造函数合成的候选函数 // 第二阶段未执行,推导指南不生效 std::vector y{v.begin(), v.end()}; }