std::uses_allocator_construction_args
定义于头文件 <memory> |
||
T 不是 std::pair 的特化 |
||
template< class T, class Alloc, class... Args > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(1) | (自 C++20 起) |
T 是 std::pair 的特化 |
||
template< class T, class Alloc, class Tuple1, class Tuple2 > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(2) | (自 C++20 起) |
template< class T, class Alloc > constexpr auto uses_allocator_construction_args( const Alloc& alloc ) noexcept; |
(3) | (自 C++20 起) |
template< class T, class Alloc, class U, class V > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(4) | (自 C++20 起) |
template< class T, class Alloc, class U, class V > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(5) | (自 C++23 起) |
template< class T, class Alloc, class U, class V > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(6) | (自 C++20 起) |
template< class T, class Alloc, class U, class V > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(7) | (自 C++20 起) |
template< class T, class Alloc, class U, class V > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(8) | (自 C++23 起) |
template< class T, class Alloc, class NonPair > constexpr auto uses_allocator_construction_args( const Alloc& alloc, |
(9) | (自 C++20 起) |
准备通过使用分配器的构造创建给定类型 T
的对象所需的参数列表。
T
不是 std::pair 的特化时,此重载才参与重载决议。 返回按如下方式确定的 std::tuple- 若 std::uses_allocator_v<T, Alloc> 为 false 且 std::is_constructible_v<T, Args...> 为 true,则返回 std::forward_as_tuple(std::forward<Args>(args)...)。
- 否则,若 std::uses_allocator_v<T, Alloc> 为 true 且 std::is_constructible_v<T, std::allocator_arg_t, const Alloc&, Args...> 为 true,则返回
std::tuple<std::allocator_arg_t, const Alloc&, Args&&...>(std::allocator_arg, alloc,
std::forward<Args>(args)...). - 否则,若 std::uses_allocator_v<T, Alloc> 为 true 且 std::is_constructible_v<T, Args..., const Alloc&> 为 true,则返回 std::forward_as_tuple(std::forward<Args>(args)..., alloc)。
- 否则,程序为非良构。
T
是 std::pair 的特化时,此重载才参与重载决议。 对于作为 std::pair<T1, T2> 的 T
,等价于return std::make_tuple(std::piecewise_construct, std::apply([&alloc](auto&&... args1) { return std::uses_allocator_construction_args<T1>(alloc, std::forward<decltype(args1)>(args1)...); }, std::forward<Tuple1>(x) ), std::apply([&alloc](auto&&... args2) { return std::uses_allocator_construction_args<T2>(alloc, std::forward<decltype(args2)>(args2)...); }, std::forward<Tuple2>(y) ) );
T
是 std::pair 的特化时,此重载才参与重载决议。 等价于return std::uses_allocator_construction_args<T>(alloc, std::piecewise_construct, std::tuple<>{}, std::tuple<>{} );
T
是 std::pair 的特化时,此重载才参与重载决议。 等价于return std::uses_allocator_construction_args<T>(alloc, std::piecewise_construct, std::forward_as_tuple(std::forward<U>(u)), std::forward_as_tuple(std::forward<V>(v)) );
T
是 std::pair 的特化时,此重载才参与重载决议。 等价于return std::uses_allocator_construction_args<T>(alloc, std::piecewise_construct, std::forward_as_tuple(pr.first), std::forward_as_tuple(pr.second) );
T
是 std::pair 的特化时,此重载才参与重载决议。 等价于return std::uses_allocator_construction_args<T>(alloc, std::piecewise_construct, std::forward_as_tuple(std::get<0>(std::move(pr))), std::forward_as_tuple(std::get<1>(std::move(pr))) );
T
是 std::pair 的特化,且给定仅为阐释目的的函数模板时,此重载才参与重载决议template<class A, class B> void /*deduce-as-pair*/(const std::pair<A, B>&);
,当 /*deduce-as-pair*/(non_pair) 被视为未求值操作数时,为非良构。
设仅为阐释目的的类 pair-constructor
定义为
class /*pair-constructor*/ { const Alloc& alloc_; // exposition only NonPair& u_; // exposition only constexpr reconstruct(const std::remove_cv<T>& p) const // exposition only { return std::make_obj_using_allocator<std::remove_cv<T>>(alloc_, p); } constexpr reconstruct(std::remove_cv<T>&& p) const // exposition only { return std::make_obj_using_allocator<std::remove_cv<T>>(alloc_, std::move(p)); } public: constexpr operator std::remove_cv<T>() const { return reconstruct(std::forward<NonPair>(u_)); } };
pair_construction
是类型为 pair-constructor
的值,其 alloc_
和 u_
成员分别为 alloc
和 non_pair
。内容 |
[编辑] 参数
alloc | - | 要使用的分配器 |
args | - | 要传递给 T 的构造函数的参数 |
x | - | 要传递给 T 的 first 数据成员的构造函数的参数元组 |
y | - | 要传递给 T 的 second 数据成员的构造函数的参数元组 |
u | - | 要传递给 T 的 first 数据成员的构造函数的单个参数 |
v | - | 要传递给 T 的 second 数据成员的构造函数的单个参数 |
pr | - | 一个 pair,其 first 数据成员将传递给 T 的 first 数据成员的构造函数,而 second 数据成员将传递给 T 的 second 数据成员的构造函数 |
non_pair | - | 要转换为 std::pair 以进行进一步构造的单个参数 |
[编辑] 返回值
适用于传递给 T
的构造函数的参数的 std::tuple。
[编辑] 注解
重载 (2-9) 提供分配器传播到 std::pair 中,后者既不支持前导分配器调用约定也不支持尾随分配器调用约定(与例如 std::tuple 不同,后者使用前导分配器约定)。
当在使用分配器的构造中使用时,pair-constructor
的转换函数首先将提供的参数转换为 std::pair,然后通过使用分配器的构造从该 std::pair 构造结果。
[编辑] 示例
本节尚不完整 原因:没有示例 |
[编辑] 缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 3525 | C++20 | 没有重载可以处理可转换为 pair 的非 pair 类型 |
添加了重建重载 |
[编辑] 参见
(C++11) |
检查指定的类型是否支持使用分配器的构造 (类模板) |
(C++20) |
通过使用分配器的构造创建给定类型的对象 (函数模板) |
通过使用分配器的构造在指定的内存位置创建给定类型的对象 (函数模板) |