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.
PrevUpHomeNext

Function any_cast

boost::anys::any_cast — Custom keyword cast for extracting a value of a given type from an basic_any. Also available from boost namespace.

Synopsis

// In header: <boost/any/basic_any.hpp>


template<typename T> T any_cast(basic_any & operand);
template<typename T> T any_cast(basic_any && operand);
template<typename T> T any_cast(const basic_any & operand);
template<typename ValueType> 
  const ValueType * any_cast(const basic_any * operand);
template<typename ValueType> ValueType * any_cast(basic_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 T is ValueType, it returns a copy of the held value, otherwise, if T is a reference to (possibly const qualified) ValueType, it returns a reference to the held value.

Throws:

Overloads taking an basic_any pointer do not throw; overloads taking an basic_any value or reference throw bad_any_cast if unsuccessful.

PrevUpHomeNext