std::experimental::any_cast
From cppreference.com
< cpp | experimental | any
| template<class ValueType> ValueType any_cast(const any& operand); |
(1) | (Library Fundamentals TS) |
| template<class ValueType> ValueType any_cast(any& operand); |
(2) | (Library Fundamentals TS) |
| template<class ValueType> ValueType any_cast(any&& operand); |
(3) | (Library Fundamentals TS) |
| template<class ValueType> const ValueType* any_cast(const any* operand) noexcept; |
(4) | (Library Fundamentals TS) |
| template<class ValueType> ValueType* any_cast(any* operand) noexcept; |
(5) | (Library Fundamentals 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 をスローします。