std::experimental::any::operator=

< cpp‎ | experimental‎ | any
any& operator=( const any& rhs );
(1) (库基础 TS)
any& operator=( any&& rhs ) noexcept;
(2) (库基础 TS)
template< typename ValueType >
    any& operator=( ValueType&& rhs );
(3) (库基础 TS)

将内容赋值给所含值。

1) 通过复制 rhs 的状态赋值,如同用 any(rhs).swap(*this)
2) 通过移动 rhs 的状态赋值,如同用 any(std::move(rhs)).swap(*this)。赋值后 rhs 留在有效但未指定的状态。
3)rhs 的类型和值赋值,如同用 any(std::forward<ValueType>(rhs)).swap(*this)。若 std::is_copy_constructible<std::decay_t<ValueType>>::valuefalse,则程序非良构此重载只有在std::decay_t<ValueType>any 不是同一类型时才会参与重载决议。

模板形参

ValueType - 被含有的值类型
类型要求
-
std::decay_t<ValueType> 必须满足可复制构造 (CopyConstructible)

参数

rhs - 要赋值给其所含值的对象

返回值

*this

异常

1,3) 抛出 bad_alloc 或所含类型的构造函数所抛出的任何异常。若抛出异常,则无效果(强异常保证)。

参阅

构造 any 对象
(公开成员函数)