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 to view this page for the latest version.
PrevUpHomeNext

Function dynamic_any_cast

boost::type_erasure::dynamic_any_cast

Synopsis

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


template<typename R, typename Any> R dynamic_any_cast(Any && arg);
template<typename R, typename Any, typename Map> 
  R dynamic_any_cast(Any && arg, const static_binding< Map > &);

Description

Downcasts or crosscasts an any.

The single argument form can only be used when R uses a single non-deduced placeholder.

Example:

 // Assume that typeid_<>, copy_constructible<>, and incrementable<>
 // have all been registered for int.
 any<mpl::vector<typeid_<>, copy_constructible<> > > x(1);
 typedef any<
     mpl::vector<
         typeid_<>,
         copy_constructible<>,
         incrementable<>
     >
 > incrementable_any;
 auto y = dynamic_any_cast<incrementable_any>(x);
 ++y;
 assert(any_cast<int>(y) == 2);

Requires:

R and Any must both be specializations of any.

PlaceholderMap must be an MPL map with a key for every non-deduced placeholder used by R. The value associated with each key should be the corresponding placeholder in Any.

The concept of Any must include typeid_, for every placeholder which is used by R.

Throws:

bad_any_cast if the concepts used by R were not previously registered via a call to register_binding.

PrevUpHomeNext