std::expected<T,E>::operator=
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   constexpr expected& operator=( const expected& other );  | 
(1) | (C++23 起) | 
|   constexpr expected& operator=( expected&& other ) noexcept(/*see below*/);  | 
(2) | (C++23 起) | 
|   template< class U = T > constexpr expected& operator=( U&& v );  | 
(3) |  (C++23 起)  (T 不是 cv void)  | 
|   template< class G > constexpr expected& operator=( const unexpected<G>& other );  | 
(4) | (C++23 起) | 
|   template< class G > constexpr expected& operator=( unexpected<G>&& other );  | 
(5) | (C++23 起) | 
为一个现存的 expected 对象赋予新值。
1,2) 赋值 
other 的状态。
-  如果 
this->has_value()等于 other.has_value(),赋予other中储存的值。在T是(可能有 cv 限定的) void 且 other.has_value() 为 true 时什么也不做。 -  否则,销毁当前储存的值(在 this->has_value() 为 true 且 
T是(可能有 cv 限定的) void) 时什么也不做),使得*this包含other中储存的值的副本。 
-  在 other.has_value() 为 true 且 
T是(可能有 cv 限定的) void 时,不构造新值。否则,新值视情况从*other或other.error()拷贝构造 (1) 或移动构造 (2) 。如果抛出异常,则旧值被保留, *this 不会变得无值。 
如果没有抛出异常,在赋值后 has_value() 等于 other.has_value() 。
-  重载 (1) 被定义为弃置,除非
-  
T是(可能有 cv 限定的) void 或 std::is_copy_assignable_v<T> 为 true,且 -  
T是(可能有 cv 限定的) void 或 std::is_copy_constructible_v<T> 为 true,且 - std::is_copy_assignable_v<E> 为 true ,且
 - std::is_copy_constructible_v<E> 为 true ,且
 -  下列至少一项为 true :
-  
T是(可能有 cv 限定的) void - std::is_nothrow_move_constructible_v<T>
 - std::is_nothrow_move_constructible_v<E>
 
 -  
 
 -  
 -  重载 (2) 仅在以下情况才参与重载决议
-  
T是(可能有 cv 限定的) void 或 std::is_move_assignable_v<T> 为 true ,且 -  
T是(可能有 cv 限定的) void 或 std::is_move_constructible_v<T> 为 true ,且 - std::is_move_assignable_v<E> 为 true,且
 - std::is_move_constructible_v<E> 为 true,且
 -  下列至少一项为 true :
-  
T是(可能有 cv 限定的) void - std::is_nothrow_move_constructible_v<T>
 - std::is_nothrow_move_constructible_v<E>
 
 -  
 
 -  
 
3) 从期待的值赋值。
- 如果 this->has_value() 为 true ,等价于 *this = std::forward<U>(v) 。
 - 否则,销毁 *this 中包含的值,并使得 *this 包含从 std::forward<U>(v) 初始化的值。如果抛出异常,则旧值被保留, *this 不会变得无值。
 
如果没有抛出异常,在赋值后, this->has_value() 为 true。
-  此重载只有在
- std::is_same_v<expected, std::remove_cvref_t<U>> 为 false ,且
 -  std::remove_cvref_t<U> 不是 
std::unexpected的特化,且 - std::is_constructible_v<T, U> 为 true,且
 - std::is_assignable_v<T&, U> 为 true,且
 - 下列至少一项为 true :
 
 
4,5) 从不期待的值赋值。
令 GF 对于重载 (4) 为 const G&,对于重载 (5) 为 G。
-  如果 this->has_value() 为 true ,销毁 *this 中包含的值(在 
T是(可能有 cv 限定的) void) 时什么也不做),并且使 *this 包含从 std::forward<GF>(e.error()) 初始化的值。如果抛出异常,则旧值被保留, *this 不会变得无值。 - 否则,等价于 this->error() = std::forward<GF>(e.error())。
 
如果没有抛出异常,在赋值后, this->has_value() 为 false。
-  此重载只有在
- std::is_constructible_v<E, GF> 为 true ,且
 - std::is_assignable_v<E&, GF> 为 true ,且
 -  下列至少一项为 true :
-  
T是(可能有 cv 限定的) void - std::is_nothrow_constructible_v<E, GF>
 - std::is_nothrow_move_constructible_v<T>
 - std::is_nothrow_move_constructible_v<E>
 
 -  
 
 
所有情况下,如果 T 不是(可能有 cv 限定的) void ,旧值的析构和新值的构造是如同通过仅用于阐释的函数 reinit_expected 进行的。
template< class NewType, class OldType, class... Args > constexpr void reinit_expected( NewType& new_val, OldType& old_val, Args&&... args ) { if constexpr (std::is_nothrow_constructible_v<NewType, Args...>) { std::destroy_at(std::addressof(old_val)); std::construct_at(std::addressof(new_val), std::forward<Args>(args)...); } else if constexpr (std::is_nothrow_move_constructible_v<NewType>) { NewType temp(std::forward<Args>(args)...); std::destroy_at(std::addressof(old_val)); std::construct_at(std::addressof(new_val), std::move(temp)); } else { OldType temp(std::move(old_val)); std::destroy_at(std::addressof(old_val)); try { std::construct_at(std::addressof(new_val), std::forward<Args>(args)...); } catch (...) { std::construct_at(std::addressof(old_val), std::move(temp)); throw; } } }
参数
| other | - |  其他 expected 对象,其所含的值用于赋值
 | 
| value | - | 用于赋值所含值的值 | 
| e | - | std::unexpected 对象,其所含的值用于赋值 | 
返回值
*this
异常
1) 抛出任何 
T 或 E 的复制构造函数或复制赋值运算符所抛的异常。2) 如果 
T 是(可能有 cv 限定的) void,noexcept 说明:  
否则, noexcept(std::is_nothrow_move_constructible_v<E> && std::is_nothrow_move_assignable_v<E>)
noexcept 说明:  
noexcept(
  std::is_nothrow_move_constructible_v<T> && std::is_nothrow_move_assignable_v<T> &&
3) 抛出任何 
T 的构造函数或赋值运算符所抛的异常。4,5) 抛出任何 
E 的构造函数或赋值运算符所抛的异常。示例
| 本节未完成 原因:暂无示例  | 
参阅
|    在原位构造期待的值  (公开成员函数)  |