Namespaces
Variants

std::experimental::function<R(Args...)>:: operator=

From cppreference.net
function & operator = ( const function & other ) ;
(1) (库基础技术规范)
function & operator = ( function && other ) ;
(2) (库基础技术规范)
function & operator = ( std:: nullptr_t ) noexcept ;
(3) (库基础技术规范)
template < class F >
function & operator = ( F && f ) ;
(4) (库基础技术规范)
(5)
template < class F >
function & operator = ( std:: reference_wrapper < F > f ) ;
(库基础技术规范)
template < class F >
function & operator = ( std:: reference_wrapper < F > f ) noexcept ;
(库基础技术规范 v3)

std::experimental::function 分配新的 目标对象 。在以下描述中,令 ALLOCATOR_OF ( f ) 表示构造 f 时指定的分配器,若未指定分配器,则取构造时 std:: experimental :: pmr :: get_default_resource ( ) 的值 (库基础技术规范 v3 前) 默认构造的 std:: pmr :: polymorphic_allocator <> (库基础技术规范 v3 起)

1) 赋值 other target 副本,如同执行 function ( std:: allocator_arg , ALLOCATOR_OF ( * this ) , other ) . swap ( * this ) ;
2) other 的目标移动至 * this ,如同执行 function ( std:: allocator_arg , ALLOCATOR_OF ( * this ) , std :: move ( other ) ) . swap ( * this ) ; other 处于有效状态但值未指定。
3) 销毁 * this 目标对象 。调用后 * this 处于 状态。赋值后通过 get_memory_resource() 返回的内存资源与赋值前等效,但其地址可能发生改变。
4) * this 目标 设置为可调用对象 f ,如同执行 function ( std:: allocator_arg , ALLOCATOR_OF ( * this ) , std:: forward < F > ( f ) ) . swap ( * this ) ; 。仅当 f 对参数类型 Args... 和返回类型 R 满足 Callable 要求时,此运算符才参与重载决议。
5) * this 目标对象 设置为 f 的副本,如同通过执行 function ( std:: allocator_arg , ALLOCATOR_OF ( * this ) , f ) . swap ( * this ) ; 实现。

目录

参数

other - 另一个用于复制或移动来源的 std::experimental::function 对象
f - 用于初始化 目标 的可调用对象
类型要求
-
F 必须满足 Callable 的要求。

返回值

* this

异常

1,2,4) 在需要分配存储空间或初始化 * this 的目标对象(若存在)时抛出异常。
5) (无)

注释

移动赋值运算符可能需要分配存储,如果 get_memory_resource ( ) ! = other. get_memory_resource ( ) (until library fundamentals TS v3) get_allocator ( ) ! = other. get_allocator ( ) (library fundamentals TS v3)