std::allocator_traits<Alloc>:: construct
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<memory>
|
||
|
template
<
class
T,
class
...
Args
>
static void construct ( Alloc & a, T * p, Args && ... args ) ; |
(C++11 起)
(C++20 起为 constexpr) |
|
如果可能,通过调用
a.
construct
(
p,
std::
forward
<
Args
>
(
args
)
...
)
,
在由
p
指向的已分配未初始化存储中构造一个类型为
T
的对象。
如果上述操作不可行(例如
Alloc
没有成员函数
construct()
),则调用
|
:: new ( static_cast < void * > ( p ) ) T ( std:: forward < Args > ( args ) ... ) |
(C++20 前) |
|
std:: construct_at ( p, std:: forward < Args > ( args ) ... ) |
(C++20 起) |
目录 |
参数
| a | - | 用于构造的分配器 |
| p | - |
指向未初始化存储的指针,将在该位置构造
T
对象
|
| args... | - | 传递给 a. construct ( ) 或 placement-new (C++20 前) std::construct_at() (C++20 起) 的构造函数参数 |
返回值
(无)
注释
该函数被标准库容器在插入、复制或移动元素时使用。
由于此函数提供了自动回退到 placement new 的功能,成员函数
construct()
自 C++11 起成为可选的
Allocator
要求。
参见
|
分配函数
(函数) |
|
|
(until C++20)
|
在已分配存储中构造对象
(
std::allocator<T>
的公开成员函数)
|
|
(C++20)
|
在给定地址创建对象
(函数模板) |