名稱空間
變體
操作

std::copyable_function::operator=

來自 cppreference.com
 
 
 
函式物件
函式呼叫
(C++17)(C++23)
恆等函式物件
(C++20)
透明運算子包裝器
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

舊繫結器和介面卡
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)
(直到 C++17*)  
(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
(直到 C++17*)(直到 C++17*)
(直到 C++17*)(直到 C++17*)

(直到 C++17*)
(直到 C++17*)(直到 C++17*)(直到 C++17*)(直到 C++17*)
(直到 C++20*)
(直到 C++20*)
 
 
copyable_function& operator=( const copyable_function& other );
(1) (C++26 起)
copyable_function& operator=( copyable_function&& other );
(2) (C++26 起)
copyable_function& operator=( std::nullptr_t ) noexcept;
(3) (C++26 起)
template< class F >
copyable_function& operator=( F&& f );
(4) (C++26 起)

std::copyable_function 分配新目標或銷燬其目標。

1)other 的目標的副本賦值給 *this,如同透過執行 auto(other).swap(*this)
2)other 的目標移動到 *this,或如果 other 為空,則銷燬 *this 的目標(如果存在),透過 auto(std::move(other)).swap(*this)。移動賦值後,other 處於有效但未指定值的狀態。
3) 如果當前目標存在,則銷燬它。呼叫後 *this 為空。
4)*this 的目標設定為可呼叫物件 f,或者如果 f 是空函式指標、空成員函式指標或空的 std::copyable_function,則銷燬當前目標,如同透過執行 copyable_function(std::forward<F>(f)).swap(*this);。此過載僅在從 F 構造 copyable_function 的建構函式參與過載決議時才參與過載決議。如果選定的建構函式呼叫格式錯誤或具有未定義行為,則程式格式錯誤或具有未定義行為。

目錄

[編輯] 引數

其他 - 另一個 std::copyable_function 物件,用於複製或移動其目標
f - 一個可呼叫物件,用於初始化新目標

[編輯] 返回值

*this

[編輯] 示例

[編輯] 參閱

賦值一個新的目標
(std::function<R(Args...)> 的公開成員函式) [編輯]
替換或銷燬目標
(std::move_only_function 的公開成員函式) [編輯]