命名空间
变体
操作

std::move_only_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*)
 
 
move_only_function& operator=( move_only_function&& other );
(1) (since C++23)
move_only_function& operator=( const move_only_function& ) = delete;
(2) (since C++23)
move_only_function& operator=( std::nullptr_t ) noexcept;
(3) (since C++23)
template< class F >
move_only_function& operator=( F&& f );
(4) (since C++23)

std::move_only_function 赋予新目标,或销毁其目标。

1)other 的目标移动到 *this,或者如果 other 为空,则通过 auto(std::move(other)).swap(*this) 销毁 *this 的目标(如果有)。移动赋值后,other 处于有效状态,但值未指定。
2) 复制赋值运算符已删除。std::move_only_function 不满足 CopyAssignable
3) 如果当前目标存在,则销毁它。调用后 *this 为空。
4)*this 的目标设置为可调用对象 f,或者如果 f 是空函数指针、空成员函数指针或空的 std::move_only_function,则销毁当前目标,如同执行 move_only_function(std::forward<F>(f)).swap(*this);。仅当从 F 构造 move_only_function 的构造函数参与重载决议时,此重载才参与重载决议。如果选择的构造函数调用是非良构的或具有未定义的行为,则程序是非良构的或具有未定义的行为。

目录

[编辑] 参数

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

[编辑] 返回值

*this

[编辑] 注解

有意不要求移动赋值运算符为 noexcept,以便将来为感知分配器的 move_only_function 留出空间。

如果可以从该参数构造,则可以将 move_only_functionstd::in_place_type<Fn> 赋值。

[编辑] 示例

[编辑] 参见

赋予新目标
(std::function<R(Args...)> 的公共成员函数) [编辑]