boost::openmethod::virtual_traits<boost::any&, Registry>::cast

Cast to a type.

Synopsis

Declared in <boost/openmethod/interop/boost_any.hpp>

template<typename U>
requires !std::is_rvalue_reference_v<U>
static
decltype(auto)
cast(boost::any& arg);

Description

If U is the any itself (by any reference category), returns arg unchanged, which is how a catch‐all overrider is written. Otherwise, extracts the stored value using boost::any_cast, and registers U, stripped of reference and cv‐qualifiers, in Registry as a class derived from boost::any. Supports mutable references (e.g. Dog&) because the any argument is not const; modifications through the result are visible through the any.

U cannot be an rvalue reference. Unlike std::any_cast, boost::any_cast binds an rvalue reference to the value stored in an lvalue any; moving the value out must go through an explicit virtual_<boost::any&&> parameter, so this overload is removed from the overload set.

Return Value

The value stored in arg, cast to U.

Template Parameters

Name

Description

U

The target type (e.g. Dog&, const Dog&, Dog).

Parameters

Name

Description

arg

A mutable reference to the boost::any method argument.

Created with MrDocs