Namespaces
Variants

std::copyable_function::operator=

从 zh.cppreference.net
 
 
 
函数对象
函数调用
(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,或者在 *this 为空时销毁其目标(如果有),通过 other 实现。移动赋值后,auto(std::move(other)).swap(*this) 处于有效但未指定值的状态。other
3) 销毁当前目标(如果存在)。调用后,*this 为空。
4) 将 *this 的目标设为可调用对象 f,或者在 f 是空函数指针、空成员函数指针或空 std::copyable_function 时销毁当前目标,如同执行 copyable_function(std::forward<F>(f)).swap(*this); 一样。此重载仅当 copyable_function 的构造函数针对 F 参与重载决议时才会参与。如果所选的构造函数调用是病式或具有未定义行为,则程序为病式或具有未定义行为。

参数

other - 用于复制或移动其目标对象的另一个 std::copyable_function 对象
f - 用于初始化新目标的可调用对象

返回值

* this

示例

参见

赋值新目标
( std::function<R(Args...)> 的公开成员函数)
替换或销毁目标
( std::move_only_function 的公开成员函数)