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_lvalue_reference_v<U> ||
            std::is_const_v<std::remove_reference_t<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.

U cannot be a mutable lvalue reference: that would bind a reference to the value contained in a temporary. Boost.Any rejects it with a static assertion; this overload is removed from the overload set instead, for consistency with the other reference categories.

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

An rvalue reference to the boost::any method argument.

Created with MrDocs