std::indirect<T, Allocator>::operator=
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Memory management library
(exposition only*)
(C++11)
(C++23)
(C++11)
(C++17)
(C++11)
(C++11)
(C++20)
(C++20)
(C++17)
(C++11)
(C++17)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
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)
(C++11)
(C++11)
(C++17)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
(until C++17*)
(C++11)
(C++17)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++11)
(C++20)
(C++11)
(C++11)
(C++20)
(C++26)
std::indirect
indirect::operator=
constexpr indirect& operator=( const indirect& other );
(1)
(since C++26)
constexpr indirect& operator=( indirect&& other ) noexcept(/* see below */);
(2)
(since C++26)
template< class U = T >
constexpr indirect& operator=( U&& value );
(3)
(since C++26)
constexpr indirect& operator=( U&& value );
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:
- If other is valueless, *this becomes valueless and the object owned by *this (if any) is destroyed using traits::destroy and then the storage is deallocated.
- Otherwise, if
alloc== other.allocis true and *this is not valueless, equivalent to **this = *other. - Otherwise:
- Constructs a new owned object in *this using traits::construct with *other as the argument, using the allocator update_alloc ? other.
alloc:alloc. - The previously owned object in *this (if any) is destroyed using traits::destroy and then the storage is deallocated.
-
ppoints to the new owned object.
- Constructs a new owned object in *this using traits::construct with *other as the argument, using the allocator update_alloc ? other.
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 other is valueless, *this becomes valueless and the object owned by *this (if any) is destroyed using traits::destroy and then the storage is deallocated.
- Otherwise, if
alloc== other.allocis true, swaps the owned objects in *this and other; the owned object in other (if any) is then destroyed using traits::destroy and then the storage is deallocated. - Otherwise:
- Constructs a new owned object in *this using traits::construct with std::move(*other) as the argument, using the allocator update_alloc ? other.
alloc:alloc. - The previously owned object in *this (if any) is destroyed using traits::destroy and then the storage is deallocated.
-
ppoints to the new owned object.
- Constructs a new owned object in *this using traits::construct with std::move(*other) as the argument, using the allocator update_alloc ? other.
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> is false.
- std::is_constructible_v <T, U> is true.
- std::is_assignable_v <T&, U> is true.
Contents
[edit] Parameters
other
-
another
indirect object whose owned value (if exists) is used for assignment
value
-
value to assign to or construct the owned value
[edit] Return value
*this
[edit] 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.
noexcept specification:
noexcept(std::allocator_traits <Allocator>::
propagate_on_container_move_assignment::value
[edit] Example
This section is incomplete
Reason: no example
Reason: no example