std::experimental::any_cast
来自 cppreference.cn
< cpp | experimental | any
template<class ValueType> ValueType any_cast(const any& operand); |
(1) | (库基础 TS) |
template<class ValueType> ValueType any_cast(any& operand); |
(2) | (库基础 TS) |
template<class ValueType> ValueType any_cast(any&& operand); |
(3) | (库基础 TS) |
template<class ValueType> const ValueType* any_cast(const any* operand) noexcept; |
(4) | (库基础 TS) |
template<class ValueType> ValueType* any_cast(any* operand) noexcept; |
(5) | (库基础 TS) |
执行到包含对象的类型安全访问。
对于 (1-3),如果 ValueType
不是引用且 std::is_copy_constructible<ValueType>::value 为 false,则程序是非良构的。
[edit] 参数
operand | - | 目标 any 对象 |
[edit] 返回值
1) 返回 *any_cast<std::add_const_t<std::remove_reference_t<ValueType>>>(&operand)。
2,3) 返回 *any_cast<std::remove_reference_t<ValueType>>(&operand)。
4,5) 如果 operand 不是空指针,且请求的
ValueType
的 typeid
与 operand 内容的 typeid
匹配,则返回指向 operand 所含值的指针,否则返回空指针。[edit] 异常
1-3) 如果请求的
ValueType
的 typeid
与 operand 内容的 typeid
不匹配,则抛出 bad_any_cast
。