std::experi...al::any_cast(3)
okay so bestie, welcome to the C++ Standard Libary manual (yes, that spelling is in the header, not me π) β this is the std::experi...al::any_cast(3) page, and we're talking about std::experimental::any_cast. Buckle up, it's giving type-safe access realness β¨
π NAME π
std::experimental::any_cast β literally std::experimental::any_cast, the function this whole page is about. No cap.
β¨ Synopsis β¨
Here's the whole overload lineup, bestie β all five are from the library fundamentals TS:
template<class ValueType> (1) (library
fundamentals TS)
ValueType any_cast(const any& operand);
template<class ValueType> (2) (library
fundamentals TS)
ValueType any_cast(any& operand);
template<class ValueType> (3) (library
fundamentals TS)
ValueType any_cast(any&& operand);
template<class ValueType>
const ValueType* any_cast(const any* operand) (4) (library
fundamentals TS)
noexcept;
template<class ValueType> (5) (library
fundamentals TS)
ValueType* any_cast(any* operand) noexcept;
Performs type-safe access to the contained object. That's the whole vibe.
And for overloads (1-3), the program is ill-formed if ValueType is not a reference and std::is_copy_constructible<ValueType>::value is false. Like, do not pass go, do not collect $200, the compiler is gonna side-eye you π
πΈ Parameters πΈ
operandβ targetanyobject. That's it, that's the parameter, she's simple and iconic.
π Return value π
- 1) Returns
*any_cast<std::add_const_t<std::remove_reference_t<ValueType>>>(&operand). - 2, 3) Returns
*any_cast<std::remove_reference_t<ValueType>>(&operand). - 4, 5) If
operandis not a null pointer, and thetypeidof the requestedValueTypematches that of the contents ofoperand, a pointer to the value contained byoperand, otherwise a null pointer.
π Exceptions π
- 1-3) Throws
bad_any_castif thetypeidof the requestedValueTypedoes not match that of the contents ofoperand.
π·οΈ Category π·οΈ
- Noindexed pages
source/version + date tea: http://cppreference.com β 2024.06.10. Bye bestie, go slay your any casts π
π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms