std::scoped_allocator_adaptor<OuterAlloc,InnerAlloc...>::construct
定义于头文件 <scoped_allocator> |
||
template< class T, class... Args > void construct( T* p, Args&&... args ); |
(1) | |
template< class T1, class T2, class... Args1, class... Args2 > void construct( std::pair<T1, T2>* p, std::piecewise_construct_t, |
(2) | (C++20 前) |
template< class T1, class T2 > void construct( std::pair<T1, T2>* p ); |
(3) | (C++20 前) |
template< class T1, class T2, class U, class V > void construct( std::pair<T1, T2>* p, U&& x, V&& y ); |
(4) | (C++20 前) |
(5) | (C++20 前) | |
(6) | (C++20 前) | |
辅助函数模板 |
||
template < class T, class... Args > std::tuple</* see below */> /*concat-args*/( std::tuple<Args...>&& tup ); |
(7) | (仅作说明*) (C++20 前) |
在 `p` 指向的已分配但未初始化的存储中,使用外部分配器和提供的构造函数参数构造一个对象。如果该对象本身的类型使用分配器,或者如果它是 std::pair(直到 C++20),则将内部分配器传递给构造的对象。
T
的对象。
给定 std::uses_allocator<T, inner_allocator_type>::value 为 uses_inner
此重载仅在 |
(C++20 前) |
等价于 std::apply |
(C++20 起) |
concat-args
<T1>(std::move(x)),yprime 为 concat-args
<T2>(std::move(y)),调用 outermost-construct
(p, std::piecewise_construct, std::move(xprime), std::move(yprime))。std::forward_as_tuple(xarg), std::forward_as_tuple(yarg));,其中 xarg 和 yarg 定义如下:
重载 | xarg | yarg |
---|---|---|
(4) | std::forward<U>(x) | std::forward<V>(y) |
(5) | xy.first | xy.second |
(6) | std::forward<U>(xy.first) | std::forward<V>(xy.second) |
- 如果 uses_inner 为 false 且 std::is_constructible<T, Args...>::value 为 true,则返回 std::tuple<Args&&...>(std::move(tup))。
- 否则,如果 uses_inner 和 std::is_constructible<T, std::allocator_arg_t,
inner_allocator_type&,
Args...>::value 都为 true,则返回 std::tuple_cat(std::tuple<std::allocator_arg_t, inner_allocator_type&>
(std::allocator_arg, inner_allocator()),
std::tuple<Args&&...>(std::move(tup)))。 - 否则,如果 uses_inner 和 std::is_constructible<T, Args..., inner_allocator_type&>::value 都为 true,则返回 std::tuple_cat(std::tuple<Args&&...>(std::move(tup)),
std::tuple<inner_allocator_type&>(inner_allocator())。 - 否则,程序格式错误。
目录 |
[编辑] 参数
p | - | 指向已分配但未初始化的存储的指针 |
args | - | 要传递给 T 构造函数的构造函数参数 |
x | - | 要传递给 T1 构造函数的构造函数参数 |
y | - | 要传递给 T2 构造函数的构造函数参数 |
xy | - | 其两个成员为 T1 和 T2 构造函数参数的 pair |
tup | - | 要合并的参数 |
[编辑] 注意
此函数由任何分配器感知对象(例如 std::vector)通过 std::allocator_traits 调用,该对象已将 std::scoped_allocator_adaptor 作为要使用的分配器。由于 inner_allocator_type
本身是 std::scoped_allocator_adaptor 的特化,因此当通过此函数构造的分配器感知对象开始构造其自己的成员时,此函数也将被调用。
[编辑] 缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
缺陷报告 | 应用于 | 发布时的行为 | 正确的行为 |
---|---|---|---|
LWG 2203 | C++11 | 内部分配器通过值初始化获得 一个 inner_allocator_type 对象 |
通过调用 inner_allocator() 获得 |
LWG 2511 (P0475R1) |
C++11 | concat-args 可能会复制 std::tuple 的元素 |
消除了所有元素复制操作 |
LWG 2586 | C++11 | 仅检查了从inner_allocator_type 右值进行的构造 |
改为检查从非 constinner_allocator_type 左值进行的构造 |
LWG 2975 | C++11 | 重载 (1) 未受限制 | 限制为拒绝 std::pair |
[编辑] 参阅
[静态] |
在已分配的存储中构造一个对象 (函数模板) |
(C++20 前) |
在已分配的存储中构造对象 ( std::allocator<T> 的公开成员函数) |