Namespaces
Variants

std::experimental:: any_cast

From cppreference.net
template < class ValueType >
ValueType any_cast ( const any & operand ) ;
(1) (库基础技术规范)
template < class ValueType >
ValueType any_cast ( any & operand ) ;
(2) (库基础技术规范)
template < class ValueType >
ValueType any_cast ( any && operand ) ;
(3) (库基础技术规范)
template < class ValueType >
const ValueType * any_cast ( const any * operand ) noexcept ;
(4) (库基础技术规范)
template < class ValueType >
ValueType * any_cast ( any * operand ) noexcept ;
(5) (库基础技术规范)

对所含对象执行类型安全访问。

对于 (1-3) ,若 ValueType 不是引用类型且 std:: is_copy_constructible < ValueType > :: value false ,则程序非良构。

参数

操作数 - 目标 any 对象

返回值

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 所含内容的类型标识匹配,则返回指向 operand 所包含值的指针,否则返回空指针。

异常

1-3) 若请求的 ValueType typeid operand 所含内容的类型不匹配,则抛出 bad_any_cast