std::experimental::function<R(Args...)>::operator=
来自 cppreference.cn
< cpp | experimental | function
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)。
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) 的。目录 |
[编辑] 参数
其他 | - | 另一个 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),移动赋值运算符可能需要分配存储。