template<class ValueType>
ValueType any_cast(const any& operand);
| (1) | (since C++17) |
template<class ValueType>
ValueType any_cast(any& operand);
| (2) | (since C++17) |
template<class ValueType>
ValueType any_cast(any&& operand);
| (3) | (since C++17) |
template<class ValueType>
const ValueType* any_cast(const any* operand);
| (4) | (since C++17) |
template<class ValueType>
ValueType* any_cast(any* operand);
| (5) | (since C++17) |
Performs type-safe access to the contained object.
Let U be std::remove_cv_t<std::remove_reference_t<ValueType>>.
is_constructible_v<ValueType, const U&> is not true.is_constructible_v<ValueType, U&> is not true.is_constructible_v<ValueType, U> is not true.| operand | - | target any object |
static_cast<ValueType>(*std::any_cast<U>(&operand))
static_cast<ValueType>(std::move(*std::any_cast<U>(&operand))).operand is not a null pointer, and the typeid of the requested ValueType matches that of the contents of operand, a pointer to the value contained by operand, otherwise a null pointer.std::bad_any_cast if the typeid of the requested ValueType does not match that of the contents of operand.noexcept specification: noexcept
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/any/any_cast