命名空间
变体
操作

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

来自 cppreference.cn
 
 
实验性
技术规范
文件系统库 (filesystem TS)
库基础 (library fundamentals TS)
库基础 2 (library fundamentals TS v2)
库基础 3 (library fundamentals TS v3)
并行扩展 (parallelism TS)
并行扩展 2 (parallelism TS v2)
并发扩展 (concurrency TS)
并发扩展 2 (concurrency TS v2)
概念 (concepts TS)
范围 (ranges TS)
反射 (reflection TS)
数学特殊函数 (special functions TR)
实验性非 TS
模式匹配
线性代数
std::execution
契约
2D 图形
 
 
 
function& operator=( const function& other );
(1) (库基础 TS)
function& operator=( function&& other );
(2) (库基础 TS)
function& operator=( std::nullptr_t ) noexcept;
(3) (库基础 TS)
template< class F >
function& operator=( F&& f );
(4) (库基础 TS)
(5)
template< class F >
function& operator=( std::reference_wrapper<F> f );
(库基础 TS)
template< class F >
function& operator=( std::reference_wrapper<F> f ) noexcept;
(库基础 TS v3)

将新的目标赋值给 std::experimental::function。在以下描述中,设 ALLOCATOR_OF(f) 为在 f 的构造中指定的分配器,或者 std::experimental::pmr::get_default_resource() 的值(直到库基础 TS v3)默认构造的 std::pmr::polymorphic_allocator<>(库基础 TS v3 起),如果在构造时未指定分配器。

1) 赋值 other目标的副本,如同执行 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()(直到库基础 TS v3)get_allocator() != other.get_allocator()(库基础 TS v3 起),则移动赋值运算符可能需要分配存储空间