Namespaces
Variants

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

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(注:このHTML要素には翻訳対象となるテキストコンテンツが含まれていません。すべてのタグと属性は元のフォーマットで保持されています)
定義済みヘッダー <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) Constructs an object of type T by uses-allocator construction at the uninitialized memory location indicated by p using the outermost allocator.

std:: uses_allocator < T, inner_allocator_type > :: value uses_inner として与える:

このオーバーロードは、 T std::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) xprime 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 ) ) を呼び出す。
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 ) ) ;
。ただし、 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 )
7) tup に含まれる引数と、 uses-allocator construction によって型 T のオブジェクトに必要な追加引数を統合する。
std:: uses_allocator < T, inner_allocator_type > :: value uses_inner として与える:

目次

パラメータ

p - 確保済みだが初期化されていないストレージへのポインタ
args - T のコンストラクタに渡すコンストラクタ引数
x - T1 のコンストラクタに渡すコンストラクタ引数
y - T2 のコンストラクタに渡すコンストラクタ引数
xy - 2つのメンバーがそれぞれ T1 T2 のコンストラクタ引数となるペア
tup - マージされる引数

注記

この関数は( std::allocator_traits を通じて) std::vector のようなアロケータ対応オブジェクトによって呼び出されます。これらのオブジェクトはアロケータとして std::scoped_allocator_adaptor が指定された場合に使用されます。 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 左辺値からの構築をチェックするように変更
LWG 2975 C++11 オーバーロード (1) が制約されていなかった std::pair を拒否するように制約

関連項目

[static]
割り当てられたストレージ内にオブジェクトを構築する
(関数テンプレート)
(until C++20)
割り当てられたストレージ内にオブジェクトを構築する
( std::allocator<T> の公開メンバ関数)