Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
Function any_cast
c++boost.gif (8819 bytes)HomeLibrariesPeopleFAQMore

Function any_cast

boost::any_cast — Custom keyword cast for extracting a value of a given type from an any.

Synopsis

template<typename ValueType> ValueType any_cast(const any & operand);
template<typename ValueType> const ValueType * any_cast(const any * operand);
template<typename ValueType> ValueType * any_cast(any * operand);

Description

Returns: If passed a pointer, it returns a similarly qualified pointer to the value content if successful, otherwise null is returned. If passed a value or reference, it returns a copy of the value content if successful.
Throws: Overloads taking an any pointer do not throw; the overload taking an any value or reference throws bad_any_cast if unsuccessful.
Rationale: The value/reference version returns a copy because the C++ keyword casts return copies.

Last revised: , at GMTCopyright © 2001 Kevlin Henney