std::move_only_function::operator=
来自cppreference.com
< cpp | utility | functional | move only
function
工具库
函数对象
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 旧绑定器与适配器 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::move_only_function
| 成员函数 | ||||
|
move_only_function::operator=
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| 非成员函数 | ||||
|
(C++23)
|
||||
|
(C++23)
|
|
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) 通过 auto(std::move(other)).swap(*this) 移动
other 的目标给 *this 或若
other 为空则销毁 *this
的目标(若存在)。移动赋值后 other 在有未指定值的合法状态。3) 若当前目标存在则销毁它。调用后 *this 为空。
4) 如同通过执行 move_only_function(std::forward<F>(f)).swap(*this); 设置 *this 的目标为可调用对象
f ,或若 f 为空函数指针、空成员函数指针或空
std::move_only_function 则销毁当前目标。此重载只有在
move_only_function 源自 F
的构造函数参与重载决议时才会参与重载决议。若选择的构造函数调用非良构或有未定义行为,则程序非良构或有未定义行为。参数
| other | - | 要移动目标的 std::move_only_function 对象
|
| f | - | 用以初始化新目标的可调用对象 |
返回值
*this
注解
有意不要求移动赋值运算符为 noexcept
,以为将来的知分配器的 move_only_function 留出余地。
只要能从 std::in_place_type<Fn> 构造
move_only_function ,就能用该参数赋值它。
参阅
| 为内容赋值 ( std::function<R(Args...)>
的公开成员函数) |