std::allocator_traits<Alloc>::construct
來自 cppreference.com
定義於標頭檔案 <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() 或 放置 new(C++20 前)std::construct_at()(C++20 起) 的建構函式引數 |
[編輯] 返回值
(無)
[編輯] 注意
標準庫容器在插入、複製或移動元素時使用此函式。
因為此函式提供了對放置 new 的自動回退,所以自 C++11 起,成員函式 construct()
是一個可選的分配器 (Allocator) 要求。
[編輯] 參閱
分配函式 (函式) | |
(C++20 前) |
在已分配的儲存中構造物件 ( std::allocator<T> 的公開成員函式) |
(C++20) |
在給定地址建立物件 (函式模板) |