std::move_only_function::operator=
來自 cppreference.com
< cpp | 工具 | 函式物件 | move only function
move_only_function& operator=( move_only_function&& other ); |
(1) | (C++23 起) |
move_only_function& operator=( const move_only_function& ) = delete; |
(2) | (C++23 起) |
move_only_function& operator=( std::nullptr_t ) noexcept; |
(3) | (C++23 起) |
template< class F > move_only_function& operator=( F&& f ); |
(4) | (C++23 起) |
將新目標賦值給 std::move_only_function
或銷燬其目標。
1) 將 other 的目標移動到 *this,或者如果 other 為空,則銷燬 *this 的目標(如果存在),透過 auto(std::move(other)).swap(*this)。在移動賦值後,other 處於有效狀態,但值未指定。
3) 如果當前目標存在,則銷燬它。呼叫後 *this 為空。
4) 將 *this 的目標設定為可呼叫物件 f,或者如果 f 是空函式指標、空成員函式指標或空的
std::move_only_function
,則銷燬當前目標,如同執行 move_only_function(std::forward<F>(f)).swap(*this);。此過載僅在 move_only_function
從 F
建構函式參與過載決議時才參與過載決議。如果選擇的建構函式呼叫格式錯誤或具有未定義行為,則程式格式錯誤或具有未定義行為。目錄 |
[編輯] 引數
其他 | - | 另一個 std::move_only_function 物件,用於移動其目標 |
f | - | 一個可呼叫物件,用於初始化新目標 |
[編輯] 返回值
*this
[編輯] 注意
有意不要求移動賦值運算子為 noexcept,以便將來為支援分配器的 move_only_function
留出空間。
如果 move_only_function
可以從給定引數構造,則可以從 std::in_place_type<Fn> 賦值。
[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 參閱
賦值一個新的目標 ( std::function<R(Args...)> 的公共成員函式) |