名前空間
変種
操作

std::scoped_allocator_adaptor<OuterAlloc,InnerAlloc...>::construct

From cppreference.com
 
 
メモリ管理ライブラリ
(説明用*)
未初期化メモリのアルゴリズム
(C++17)
(C++17)
(C++17)
制約付き未初期化
メモリアルゴリズム
Cライブラリ

アロケータ
メモリリソース
ガベージコレクションのサポート
(C++11)(C++23まで)
(C++11)(C++23まで)
(C++11)(C++23まで)
(C++11)(C++23まで)
(C++11)(C++23まで)
(C++11)(C++23まで)
未初期化ストレージ
(C++20まで*)
(C++20まで*)
明示的な生存期間管理
 
 
ヘッダ <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,

                std::tuple<Args1...> x, std::tuple<Args2...> y );
(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まで)
template< class T1, class T2, class U, class V >
void construct( std::pair<T1, T2>* p, const std::pair<U, V>& xy );
(5) (C++20まで)
template< class T1, class T2, class U, class V >
void construct( std::pair<T1, T2>* p, std::pair<U, V>&& xy );
(6) (C++20まで)
ヘルパー関数テンプレート
template < class T, class... Args >
std::tuple</* 以下を参照 */> /*concat-args*/( std::tuple<Args...>&& tup );
(7) (説明用*)
(C++20まで)

外側のアロケータと指定されたコンストラクタ引数を使用して、p が指す、割り当てられているが初期化されていないストレージにオブジェクトを構築します。オブジェクトがそれ自身アロケータを使用する型である場合、または std::pair である場合(C++20まで)、内側のアロケータを構築されたオブジェクトに渡します。

1) 最も外側のアロケータを使用して、p で示される未初期化メモリ位置に、uses-allocator construction によって型 T のオブジェクトを構築します。

std::uses_allocator<T, inner_allocator_type>::valueuses_inner とします。

このオーバーロードは、Tstd::pair の特殊化でない場合にのみオーバーロード解決に参加します。

(C++20まで)

std::apply
(
    [p, this](auto&&... newargs)
    {
        outermost-construct
            (p, std::forward<decltype(newargs)>(newargs)...);
    },
    std::uses_allocator_construction_args
        (inner_allocator(), std::forward<Args>(args)...)
);
と同等です。

(C++20以降)
2-6) 最も外側のアロケータを使用して、p で示される未初期化メモリ位置に、uses-allocator construction によって std::pair オブジェクトを構築します。
2) xprimeconcat-args <T1>(std::move(x))yprimeconcat-args <T2>(std::move(y)) とし、outermost-construct (p, std::piecewise_construct, std::move(xprime), std::move(yprime)) を呼び出します。
3) construct(p, std::piecewise_construct, std::tuple<>(), std::tuple<>()); と同等です。
4-6) construct(p, std::piecewise_construct,
          std::forward_as_tuple(xarg), std::forward_as_tuple(yarg));
と同等です。ここで、xargyarg は以下のように定義されます。
 オーバーロード  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)
7) tup に含まれる引数と、型 T のオブジェクトの uses-allocator construction に必要な追加引数をマージします。
std::uses_allocator<T, inner_allocator_type>::valueuses_inner とします。

目次

[編集] パラメータ

p - 割り当てられているが初期化されていないストレージへのポインタ
args - T のコンストラクタに渡すコンストラクタ引数
x - T1 のコンストラクタに渡すコンストラクタ引数
y - T2 のコンストラクタに渡すコンストラクタ引数
xy - 2つのメンバーが T1T2 のコンストラクタ引数であるペア
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-argsstd::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> のパブリックメンバ関数) [編集]
English 日本語 中文(简体) 中文(繁體)