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),否则此运算符不参与重载解析。目录 |
[编辑] 参数
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 起),则移动赋值运算符可能需要分配存储空间