Namespaces
Variants

std::polymorphic<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 polymorphic & operator = ( const polymorphic & other ) ;
(1) (C++26以降)
constexpr polymorphic & operator = ( polymorphic && other )
noexcept ( /* 下記参照 */ ) ;
(2) (C++26以降)

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

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

1) もし std:: addressof ( other ) == this true の場合、何も行わない。それ以外の場合、 need_update traits :: propagate_on_container_copy_assignment :: value とする:
  1. もし other がvaluelessの場合、次のステップに進む。それ以外の場合、 * this 内に新しい所有オブジェクトを構築する。この際、 traits :: construct を使用し、引数として * other を、アロケータとして update_alloc ? other. alloc : alloc を使用する。
  2. * this 内の以前の所有オブジェクト(存在する場合)は、 traits :: destroy を使用して破棄され、その後ストレージが解放される。
* this によって所有されるオブジェクトを更新した後、 need_update true の場合、 alloc other. alloc のコピーで置き換えられます。
T incomplete type である場合、プログラムは不適格(ill-formed)です。
2) もし std:: addressof ( other ) == this true の場合、何も行わない。それ以外の場合、 need_update traits :: propagate_on_container_move_assignment :: value とする:
  • もし alloc == other. alloc true の場合、 * this other の所有オブジェクトを交換する; other の所有オブジェクト(存在する場合)はその後 traits :: destroy を使用して破棄され、その後ストレージが解放される。
  • それ以外の場合:
  1. other がvaluelessの場合、次のステップに進む。それ以外の場合、 * this に新しい所有オブジェクトを構築する。この際、 traits :: construct を使用し、引数として std :: move ( * other ) を、アロケータ update_alloc ? other. alloc : alloc を使用する。
  2. * this の以前の所有オブジェクト(存在する場合)は traits :: destroy を使用して破棄され、その後ストレージが解放される。
*this と other が所有するオブジェクトを更新した後、 * this および other において、 need_update true の場合、 alloc other. alloc のコピーで置き換えられます。
以下の条件がすべて満たされる場合、プログラムは不適格(ill-formed)である:
  • std:: allocator_traits < Allocator > :: is_always_equal :: value false である。
  • T が不完全型(incomplete type)である。

目次

パラメータ

その他 - 代入に使用される所有値(存在する場合)を持つ別の polymorphic オブジェクト

戻り値

* this

例外

1) 例外がスローされた場合、 * this に対する影響はありません。
2) 例外がスローされた場合、 * this または other に対する影響はありません。
noexcept 指定:
noexcept ( std:: allocator_traits < Allocator > ::

propagate_on_container_move_assignment :: value

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