4.1 KiB
[polymorphic.assign]
20 Memory management library [mem]
20.4 Types for composite class design [mem.composite.types]
20.4.2 Class template polymorphic [polymorphic]
20.4.2.5 Assignment [polymorphic.assign]
constexpr polymorphic& operator=(const polymorphic& other);
Mandates: T is a complete type.
Effects: If addressof(other) == this is true, there are no effects.
Otherwise:
-
The allocator needs updating ifallocator_traits::propagate_on_container_copy_assignment::value is true.
-
If other is not valueless, a new owned object is constructed in *this usingallocator_traits::construct with the owned object from other as the argument, using either the allocator in *this or the allocator in other if the allocator needs updating.
-
The previously owned object in *this, if any, is destroyed using allocator_traits::
destroy and then the storage is deallocated. -
If the allocator needs updating, the allocator in *this is replaced with a copy of the allocator in other.
Returns: A reference to *this.
Remarks: If any exception is thrown, there are no effects on *this.
constexpr polymorphic& operator=(polymorphic&& other) noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value);
Mandates: If allocator_traits::is_always_equal::value is false,T is a complete type.
Effects: If addressof(other) == this is true, there are no effects.
Otherwise:
-
The allocator needs updating ifallocator_traits::propagate_on_container_move_assignment::value is true.
-
If alloc == other.alloc is true, swaps the owned objects in *this and other; the owned object in other, if any, is then destroyed using allocator_traits::destroy and then the storage is deallocated.
-
Otherwise, if alloc != other.alloc is true; if other is not valueless, a new owned object is constructed in *this using allocator_traits::construct with the owned object from other as the argument as an rvalue, using either the allocator in *this or the allocator in other if the allocator needs updating.
-
The previously owned object in *this, if any, is destroyed using allocator_traits::
destroy and then the storage is deallocated. -
If the allocator needs updating, the allocator in *this is replaced with a copy of the allocator in other.
Returns: A reference to *this.
Remarks: If any exception is thrown, there are no effects on *this or other.