std::any::operator=
来自cppreference.com
| any& operator=( const any& rhs ); |
(1) | (C++17 起) |
| any& operator=( any&& rhs ) noexcept; |
(2) | (C++17 起) |
| template<typename ValueType> any& operator=( ValueType&& rhs ); |
(3) | (C++17 起) |
将内容赋值给所含值。
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::decay_t<ValueType> 与 any 不是同一类型且 std::is_copy_constructible_v<std::decay_t<ValueType>> 为 true才参与重载决议。模板参数
| ValueType | - | 被含有的值类型 |
| 类型要求 | ||
-std::decay_t<ValueType> 必须满足可复制构造 (CopyConstructible) 的要求。
| ||
参数
| rhs | - | 要赋值给其所含值的对象 |
返回值
*this
异常
1,3) 抛出 bad_alloc 或任何所含类型的构造函数所抛出的异常。若抛出异常,则无效应(强异常保证)。
参阅
构造 any 对象 (公开成员函数) |