Namespaces
Variants

std::copyable_function:: operator=

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until 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 ) ; 。此重载仅当 copyable_function 的构造函数对 F 参与重载决议时才参与重载决议。若选定的构造函数调用格式错误或具有未定义行为,则程序非良构或具有未定义行为。

目录

参数

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

返回值

* this

示例

参见

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