PrevUpHomeNext

Macro BOOST_YAP_USER_UDT_ANY_IF_ELSE

BOOST_YAP_USER_UDT_ANY_IF_ELSE

Synopsis

// In header: <boost/yap/user_macros.hpp>

BOOST_YAP_USER_UDT_ANY_IF_ELSE(expr_template, udt_trait)

Description

Defines a function if_else() that acts as an analogue to the ternary operator (?:), since the ternary operator is not user-overloadable. The return type of if_else() is an expression instantiated from the expr_template expression template.

Each parameter to if_else() may be any type that is not an expression. At least on parameter must be a type T for which

udt_trait<std::remove_cv_t<std::remove_reference_t<T>>>::value

is true. Each parameter is wrapped in a terminal expression.

Example:

template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;
};

template <typename T>
struct is_vector : std::false_type {};

template <typename T, typename A>
struct is_vector<std::vector<T, A>> : std::true_type {};

// Defines an overload of if_else() that returns expressions instantiated from
// user_expr.
BOOST_YAP_USER_UDT_ANY_IF_ELSE(::user_expr, is_vector)

Parameters:

expr_template

The expression template to use to instantiate the result expression. expr_template must be an ExpressionTemplate.

udt_trait

A trait template to use to constrain which types are accepted as template parameters to if_else().


PrevUpHomeNext