命名空间
变体
操作

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

来自 cppreference.cn
 
 
实验性
技术规范
文件系统库 (文件系统 TS)
库基础 (库基础 TS)
库基础 2 (库基础 TS v2)
库基础 3 (库基础 TS v3)
并行性扩展 (并行性 TS)
并行性扩展 2 (并行性 TS v2)
并发性扩展 (并发性 TS)
并发扩展 2 (并发 TS v2)
概念 (概念 TS)
范围 (范围 TS)
反射 (反射 TS)
数学特殊函数 (特殊函数 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);

目录

[编辑] 参数

其他 - 另一个 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),移动赋值运算符可能需要分配存储。