std::experimental::any_cast
來自 cppreference.com
< 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,則程式格式錯誤。
[編輯] 引數
operand | - | 目標 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 內容的 typeid
匹配,則返回指向 operand 所包含值的指標,否則返回空指標。[編輯] 異常
1-3) 如果請求的
ValueType
的 typeid
與 operand 內容的 typeid
不匹配,則丟擲 bad_any_cast
。