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 前) |
|
template
<
class
T1,
class
T2,
class
U,
class
V
>
void construct ( std:: pair < T1, T2 > * p, const std:: pair < U, V > & xy ) ; |
(5) | (C++20 前) |
|
template
<
class
T1,
class
T2,
class
U,
class
V
>
void construct ( std:: pair < T1, T2 > * p, std:: pair < U, V > && xy ) ; |
(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
构造参数的对
|
| tup | - | 待合并的参数 |
注释
此函数由任何感知分配器的对象(例如
std::allocator_traits
)通过
std::vector
调用,这些对象被赋予
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
右值进行的构造 |
改为检查从非常量
inner_allocator_type
左值进行的构造 |
| LWG 2975 | C++11 | 重载 (1) 未受约束 | 约束为拒绝 std::pair |
参见
|
[static]
|
在已分配的存储空间中构造对象
(函数模板) |
|
(until C++20)
|
在已分配的存储空间中构造对象
(
std::allocator<T>
的公开成员函数)
|