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</* 以下を参照 */> /*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 | - | 2つのメンバーが T1 と T2 のコンストラクタ引数であるペア |
| tup | - | マージされる引数 |
[編集] 備考
この関数は、アロケータとして std::scoped_allocator_adaptor が与えられた std::vector のような任意のアロケータ対応オブジェクトによって(std::allocator_traits を通じて)呼び出されます。inner_allocator_type はそれ自身 std::scoped_allocator_adaptor の特殊化であるため、この関数を通じて構築されたアロケータ対応オブジェクトが自身のメンバを構築し始めるときにもこの関数が呼び出されます。
[編集] 欠陥報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| 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 の右辺値からの構築のみがチェックされていた非 const の inner_allocator_type の左辺値からの構築を代わりにチェック |
非 const のinner_allocator_type 左辺値を代わりにチェック |
| LWG 2975 | C++11 | オーバーロード (1) は制約されていなかった | std::pair を拒否するように制約された |
[編集] 関連項目
| [static] |
割り当てられたストレージにオブジェクトを構築する (関数テンプレート) |
| (C++20まで) |
割り当てられたストレージにオブジェクトを構築する ( std::allocator<T> のパブリックメンバ関数) |