std::polymorphic<T, Allocator>::operator= - cppreference.com
From cppreference.com
|
(1) | (since C++26) |
|
(2) | (since C++26) |
Replaces contents of *this with the contents of other.
Let traits be std::allocator_traits<Allocator>:
1) If std::addressof(other) == this is true, does nothing. Otherwise, let need_update be traits::propagate_on_container_copy_assignment::value:
- If
otheris valueless, proceeds to the next step. Otherwise, constructs a new owned object in*thisusingtraits::constructwith*otheras the argument, using the allocatorupdate_alloc ? other.alloc:alloc. - The previously owned object in
*this(if any) is destroyed usingtraits::destroyand then the storage is deallocated.
After updating the object owned by *this, if need_update is true, alloc is replaced with a copy of other.alloc.
2) If std::addressof(other) == this is true, does nothing. Otherwise, let need_update be traits::propagate_on_container_move_assignment::value:
- If
alloc== other.allocistrue, swaps the owned objects in*thisandother; the owned object inother(if any) is then destroyed usingtraits::destroyand then the storage is deallocated. - Otherwise:
- If
otheris valueless, proceeds to the next step. Otherwise, constructs a new owned object in*thisusingtraits::constructwithstd::move(*other)as the argument, using the allocatorupdate_alloc ? other.alloc:alloc. - The previously owned object in
*this(if any) is destroyed usingtraits::destroyand then the storage is deallocated.
- If
After updating the objects owned by *this and other, if need_update is true, alloc is replaced with a copy of other.alloc.
If all following conditions are satisfied, the program is ill-formed:
std::allocator_traits<Allocator>::is_always_equal::valueisfalse.Tis an incomplete type.
Parameters
| other | - | another polymorphic object whose owned value (if exists) is used for assignment
|
Return value
*this
Exceptions
1) If any exception is thrown, there are no effects on *this.
2) If any exception is thrown, there are no effects on *this or other.
specification:
noexcept(std::allocator_traits<Allocator>:: propagate_on_container_move_assignment::value || std::allocator_traits<Allocator>::is_always_equal::value)