Namespaces
Variants

std::indirect<T, Allocator>:: operator=

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)
constexpr indirect & operator = ( const indirect & other ) ;
(1) (C++26以降)
constexpr indirect & operator = ( indirect && other ) noexcept ( /* 詳細は後述 */ ) ;
(2) (C++26以降)
template < class U = T >
constexpr indirect & operator = ( U && value ) ;
(3) (C++26以降)

* this の内容を value または other の内容で置き換えます。

traits std:: allocator_traits < Allocator > とします:

1) もし std:: addressof ( other ) == this true の場合、何も行わない。それ以外の場合、 need_update traits :: propagate_on_container_copy_assignment :: value とする:
  • もし other がvaluelessの場合、 * this はvaluelessとなり、 * this が所有するオブジェクト(存在する場合)は traits :: destroy を使用して破棄され、その後ストレージが解放される。
  • それ以外の場合、もし alloc == other. alloc true であり、かつ * this がvaluelessでない場合、 ** this = * other と等価である。
  • それ以外の場合:
  1. * this 内に新しい所有オブジェクトを traits :: construct を使用して構築し、引数として * other を、アロケータとして update_alloc ? other. alloc : alloc を使用する。
  2. * this 内の以前の所有オブジェクト(存在する場合)は traits :: destroy を使用して破棄され、その後ストレージが解放される。
  3. p は新しい所有オブジェクトを指す。
alloc によって所有されるオブジェクトを更新した後、 need_update true の場合、 alloc other. alloc のコピーで置き換えられます。
もし std:: is_copy_assignable_v < T > && std:: is_copy_constructible_v < T > false の場合、プログラムは不適格です。
2) もし std:: addressof ( other ) == this true の場合、何も行わない。それ以外の場合、 need_update traits :: propagate_on_container_move_assignment :: value とする:
  • もし other がvaluelessの場合、 * this はvaluelessとなり、 * this が所有するオブジェクト(存在する場合)は traits :: destroy を使用して破棄され、その後ストレージが解放される。
  • それ以外の場合、もし alloc == other. alloc true の場合、 * this other の所有するオブジェクトを交換する; other の所有するオブジェクト(存在する場合)はその後 traits :: destroy を使用して破棄され、その後ストレージが解放される。
  • それ以外の場合:
  1. * this 内に新しい所有オブジェクトを traits :: construct を使用して構築し、引数として std :: move ( * other ) を使用し、アロケータとして update_alloc ? other. alloc : alloc を使用する。
  2. * this 内の以前の所有オブジェクト(存在する場合)は traits :: destroy を使用して破棄され、その後ストレージが解放される。
  3. p は新しい所有オブジェクトを指す。
*thisとotherによって所有されるオブジェクトを更新した後、 * this および other において、 need_update true の場合、 alloc other. alloc のコピーで置き換えられます。
std:: is_copy_constructible_v < T > false の場合、プログラムは不適格です。
3) * this が値を持たない場合、 alloc を使用して std:: forward < U > ( value ) で所有するオブジェクトを構築する。それ以外の場合、 ** this = std:: forward < U > ( value ) と等価。
このオーバーロードは、以下の条件がすべて満たされる場合にのみオーバーロード解決に参加します:

目次

パラメータ

other - 所有されている値(存在する場合)が代入に使用される別の indirect オブジェクト
value - 所有されている値に代入または構築する値

戻り値

* this

例外

1) 例外がスローされた場合、 this - > valueless_after_move ( ) の結果は変更されないまま残る。
T の選択されたコピーコンストラクタの呼び出し中に例外がスローされた場合、何の効果もありません。
T のコピー代入演算子の呼び出し中に例外がスローされた場合、 this - > p の状態は T のコピー代入演算子の例外安全性保証によって定義されます。
2) 例外がスローされた場合、 * this または other に対する影響はありません。
noexcept 指定:
noexcept ( std:: allocator_traits < Allocator > ::

propagate_on_container_move_assignment :: value

|| std:: allocator_traits < Allocator > :: is_always_equal :: value )