std::indirect<T, Allocator>::operator= - cppreference.com
From cppreference.com
|
(1) | (since C++26) |
|
(2) | (since C++26) |
|
(3) | (since C++26) |
Replaces contents of *this with value or 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:
After updating the object owned by *this, if need_update is true, alloc is replaced with a copy of other.alloc.
If std::is_copy_assignable_v<T> && std::is_copy_constructible_v<T> is false, the program is ill-formed.
2) If std::addressof(other) == this is true, does nothing. Otherwise, let need_update be traits::propagate_on_container_move_assignment::value:
- If
otheris valueless,*thisbecomes valueless and the object owned by*this(if any) is destroyed usingtraits::destroyand then the storage is deallocated. - Otherwise, 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:
- 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. ppoints to the new owned object.
- Constructs a new owned object in
After updating the objects owned by *this and other, if need_update is true, alloc is replaced with a copy of other.alloc.
If std::is_copy_constructible_v<T> is false, the program is ill-formed.
3) If *this is valueless, then constructs an owned object with std::forward<U>(value) using alloc . Otherwise, equivalent to **this = std::forward<U>(value).
This overload participates in overload resolution only if all following conditions are satisfied:
std::is_same_v<std::remove_cvref_t<U>, std::indirect>isfalse.std::is_constructible_v<T, U>istrue.std::is_assignable_v<T&, U>istrue.
Parameters
| other | - | another indirect object whose owned value (if exists) is used for assignment
|
| value | - | value to assign to or construct the owned value |
Return value
*this
Exceptions
1) If any exception is thrown, the result of this->valueless_after_move() remains unchanged.
If an exception is thrown during the call to T’s selected copy constructor, no effect.
If an exception is thrown during the call to T’s copy assignment operator, the state of this->p is as defined by the exception safety guarantee of T’s copy assignment operator.
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)