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> 的公開成員函式) |