std::experimental::pmr::polymorphic_allocator<T>:: construct
|
template
<
class
U,
class
...
Args
>
void construct ( U * p, Args && ... args ) ; |
(1) | (库基础技术规范) |
|
template
<
class
T1,
class
T2,
class
...
Args1
,
class
...
Args2
>
void
construct
(
std::
pair
<
T1, T2
>
*
p,
|
(2) | (库基础技术规范) |
|
template
<
class
T1,
class
T2
>
void construct ( std:: pair < T1, T2 > * p ) ; |
(3) | (库基础技术规范) |
|
template
<
class
T1,
class
T2,
class
U,
class
V
>
void construct ( std:: pair < T1, T2 > * p, U && x, V && y ) ; |
(4) | (库基础技术规范) |
|
template
<
class
T1,
class
T2,
class
U,
class
V
>
void construct ( std:: pair < T1, T2 > * p, const std:: pair < U, V > & xy ) ; |
(5) | (库基础技术规范) |
|
template
<
class
T1,
class
T2,
class
U,
class
V
>
void construct ( std:: pair < T1, T2 > * p, std:: pair < U, V > && xy ) ; |
(6) | (库基础技术规范) |
在由
p
指向的已分配但未初始化的存储空间中,使用提供的构造函数参数构造对象。若该对象本身使用分配器的类型,或为 std::pair 类型,则向构造对象传递
this->resource()
。
1) 若
std::
uses_allocator
<
U, memory_resource
*
>
::
value
==
false
(类型
U
不使用分配器)且
std::
is_constructible
<
U, Args...
>
::
value
==
true
,则通过
::
new
(
(
void
*
)
p
)
U
(
std::
forward
<
Args
>
(
args
)
...
)
;
方式构造对象。
否则,如果
std::
uses_allocator
<
U, memory_resource
*
>
::
value
==
true
(类型
U
使用分配器,例如它是容器)且
std::
is_constructible
<
U,
std::
allocator_arg_t
, memory_resource
*
, Args...
>
::
value
==
true
,则通过
::
new
(
(
void
*
)
p
)
U
(
std::
allocator_arg
, this
-
>
resource
(
)
,
std::
forward
<
Args
>
(
args
)
...
)
;
构造对象。
否则,若
std::
uses_allocator
<
U, memory_resource
*
>
::
value
==
true
(类型
U
使用分配器,例如其为容器)且
std::
is_constructible
<
U, Args..., memory_resource
*
>
::
value
==
true
,则通过
::
new
(
(
void
*
)
p
)
U
(
std::
forward
<
Args
>
(
args
)
..., this
-
>
resource
(
)
)
;
方式构造对象。
否则,程序将是格式错误的。
2) 首先,若
T1
或
T2
具备分配器感知能力,则根据以下三条规则修改元组
x
和
y
以包含
this->resource()
,从而得到两个新元组
xprime
和
yprime
:
2a) 如果
T1
不感知分配器(
std::
uses_allocator
<
T1, memory_resource
*
>
::
value
==
false
)且
std::
is_constructible
<
T1, Args1...
>
::
value
==
true
,则
xprime
保持原值
x
不变。
2b) 如果
T1
是分配器感知的(
std::
uses_allocator
<
T1, memory_resource
*
>
::
value
==
true
),且其构造函数接受分配器标签(
std::
is_constructible
<
T1,
std::
allocator_arg_t
, memory_resource
*
, Args1...
>
::
value
==
true
),则
xprime
为
std::
tuple_cat
(
std::
make_tuple
(
std::
allocator_arg
, this
-
>
resource
(
)
)
, std
::
move
(
x
)
)
。
2c) 如果
T1
是分配器感知的(
std::
uses_allocator
<
T1, memory_resource
*
>
::
value
==
true
),且其构造函数将分配器作为最后一个参数(
std::
is_constructible
<
T1, Args1..., memory_resource
*
>
::
value
==
true
),则
xprime
为
std::
tuple_cat
(
std
::
move
(
x
)
,
std::
make_tuple
(
this
-
>
resource
(
)
)
)
。
2d) 否则,程序格式错误。
同样的规则适用于
T2
以及将
y
替换为
yprime
的情况。
在构造完
xprime
和
yprime
后,在已分配存储空间中构造
p
对,其构造方式相当于执行
::
new
(
(
void
*
)
p
)
pair
<
T1, T2
>
(
std::
piecewise_construct
, std
::
move
(
xprime
)
, std
::
move
(
yprime
)
)
;
。
3) 等价于 construct ( p, std:: piecewise_construct , std:: tuple <> ( ) , std:: tuple <> ( ) ) ,即如果 pair 的成员类型接受内存资源,则将内存资源传递给它们。
4) 等同于
construct
(
p,
std::
piecewise_construct
,
std::
forward_as_tuple
(
std::
forward
<
U
>
(
x
)
)
,
std::
forward_as_tuple
(
std::
forward
<
V
>
(
y
)
)
)
5) 等同于
construct
(
p,
std::
piecewise_construct
,
std::
forward_as_tuple
(
xy.
first
)
,
std::
forward_as_tuple
(
xy.
second
)
)
6) 等同于
construct
(
p,
std::
piecewise_construct
,
std::
forward_as_tuple
(
std::
forward
<
U
>
(
xy.
first
)
)
,
std::
forward_as_tuple
(
std::
forward
<
V
>
(
xy.
second
)
)
)
目录 |
参数
| p | - | 指向已分配但未初始化的存储空间的指针 |
| args... | - |
传递给
T
构造函数的构造参数
|
| x | - |
传递给
T1
构造函数的构造参数
|
| y | - |
传递给
T2
构造函数的构造参数
|
| xy | - |
其两个成员分别为
T1
和
T2
构造参数的对组
|
返回值
(无)
注释
此函数由任何具备分配器感知能力的对象(例如
std::vector
)通过
std::allocator_traits
调用,这些对象被指定使用
std::polymorphic_allocator
作为分配器。由于
memory_resource*
可隐式转换为
polymorphic_allocator
,该内存资源指针将通过多态分配器传播至所有具备分配器感知能力的子对象。
另请参阅
|
[static]
|
在已分配的存储中构造对象
(函数模板) |
|
(until C++20)
|
在已分配的存储中构造对象
(
std::allocator<T>
的公开成员函数)
|