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) (seit C++26)
constexpr polymorphic & operator = ( polymorphic && other )
noexcept ( /* siehe unten */ ) ;
(2) (seit C++26)

Ersetzt den Inhalt von * this durch den Inhalt von other .

Sei traits gleich std:: allocator_traits < Allocator > :

1) Falls std:: addressof ( other ) == this true ist, wird nichts unternommen. Andernfalls sei need_update gleich traits :: propagate_on_container_copy_assignment :: value :
  1. Falls other wertlos ist, wird mit dem nächsten Schritt fortgefahren. Andernfalls wird ein neues besessenes Objekt in * this unter Verwendung von traits :: construct mit * other als Argument konstruiert, wobei der Allokator update_alloc ? other. alloc : alloc verwendet wird.
  2. Das zuvor besessene Objekt in * this (falls vorhanden) wird unter Verwendung von traits :: destroy zerstört und anschließend der Speicher freigegeben.
Nach dem Aktualisieren des Objekts, das im Besitz von * this ist, falls need_update den Wert true hat, wird alloc durch eine Kopie von other. alloc ersetzt.
Wenn T ein incomplete type ist, ist das Programm fehlerhaft.
2) Wenn std:: addressof ( other ) == this true ist, tut nichts. Andernfalls sei need_update gleich traits :: propagate_on_container_move_assignment :: value :
  • Wenn alloc == other. alloc true ist, tauscht die besessenen Objekte in * this und other ; das besessene Objekt in other (falls vorhanden) wird dann unter Verwendung von traits :: destroy zerstört und anschließend der Speicher freigegeben.
  • Andernfalls:
  1. Wenn other wertlos ist, fahre mit dem nächsten Schritt fort. Andernfalls konstruiere ein neues besessenes Objekt in * this unter Verwendung von traits :: construct mit std :: move ( * other ) als Argument, unter Verwendung des Allokators update_alloc ? other. alloc : alloc .
  2. Das zuvor besessene Objekt in * this (falls vorhanden) wird unter Verwendung von traits :: destroy zerstört und anschließend der Speicher freigegeben.
Nach dem Aktualisieren der Objekte, die im Besitz von * this und other sind, falls need_update den Wert true hat, wird alloc durch eine Kopie von other. alloc ersetzt.
Wenn alle folgenden Bedingungen erfüllt sind, ist das Programm fehlerhaft:

Inhaltsverzeichnis

Parameter

other - ein weiteres polymorphic Objekt, dessen besessener Wert (falls vorhanden) für die Zuweisung verwendet wird

Rückgabewert

* this

Exceptions

1) Wenn eine Ausnahme ausgelöst wird, hat dies keine Auswirkungen auf * this .
2) Wenn eine Ausnahme ausgelöst wird, gibt es keine Auswirkungen auf * this oder other .
noexcept Spezifikation:
noexcept ( std:: allocator_traits < Allocator > ::

propagate_on_container_move_assignment :: value

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

Beispiel