命名空间
变体
操作

std::copyable_function::operator=

来自 cppreference.cn
 
 
 
函数对象
函数调用
(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 的公开成员函数) [编辑]