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::type_erasure::any_cast

Synopsis

// In header: <boost/type_erasure/any_cast.hpp>


template<typename T, typename Concept, typename Tag> 
  T any_cast(any< Concept, Tag > & arg);
template<typename T, typename Concept, typename Tag> 
  T any_cast(const any< Concept, Tag > & arg);
template<typename T, typename Concept, typename Tag> 
  T any_cast(any< Concept, Tag > * arg);
template<typename T, typename Concept, typename Tag> 
  T any_cast(const any< Concept, Tag > * arg);

Description

Attempts to extract the object that arg holds. If casting to a pointer fails, any_cast returns a null pointer. Casting to void* always succeeds and returns the address of stored object.

Requires:

if arg is a pointer, T must be a pointer type.

Concept must contain typeid_<Tag>.

Throws:

bad_any_cast if arg doesn't contain an object of type T and we're casting to a value or reference.

PrevUpHomeNext