Namespaces
Variants

std::allocator_traits<Alloc>:: 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)
ヘッダーで定義 <memory>
template < class T, class ... Args >
static void construct ( Alloc & a, T * p, Args && ... args ) ;
(C++11以降)
(C++20以降constexpr)

可能であれば、割り当てられた未初期化ストレージ( p が指す)内で型 T のオブジェクトを構築します。これは a. construct ( p, std:: forward < Args > ( args ) ... ) を呼び出すことによって行われます。

上記が不可能な場合(例: 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 ( ) または placement-new (until C++20) std::construct_at() (since C++20) に渡すコンストラクタ引数

戻り値

(なし)

注記

この関数は、標準ライブラリのコンテナが要素を挿入、コピー、または移動する際に使用されます。

この関数は配置newへの自動的なフォールバックを提供するため、メンバー関数 construct() はC++11以降ではオプションの Allocator 要件となっています。

関連項目

確保関数
(関数)
(C++20まで)
確保済みストレージにオブジェクトを構築する
( std::allocator<T> の 公開メンバ関数)
指定されたアドレスにオブジェクトを作成する
(関数テンプレート)