PrevUpHomeNext

Macro BOOST_YAP_USER_UDT_UDT_BINARY_OPERATOR

BOOST_YAP_USER_UDT_UDT_BINARY_OPERATOR

Synopsis

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

BOOST_YAP_USER_UDT_UDT_BINARY_OPERATOR(op_name, expr_template, t_udt_trait, u_udt_trait)

Description

Defines a free/non-member operator overload for binary operator op_name that produces an expression instantiated from the expr_template expression template.

The lhs parameter to the defined operator overload may be any type that is not an expression and for which

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

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

The rhs parameter to the defined operator overload may be any type that is not an expression and for which

u_udt_trait<std::remove_cv_t<std::remove_reference_t<U>>>::value 

is true. The 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 {};

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

template <>
struct is_string<std::string> : std::true_type {};

// Defines an overload of operator||() that applies to vectors on the left and
// strings on the right, and returns expressions instantiated from user_expr.
BOOST_YAP_USER_UDT_UDT_BINARY_OPERATOR(logical_or, ::user_expr, is_vector, is_string)

// Defines an overload of operator&&() that applies to strings and returns
// expressions instantiated from user_expr.
BOOST_YAP_USER_UDT_UDT_BINARY_OPERATOR(logical_and, ::user_expr, is_string, is_string)

Parameters:

expr_template

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

op_name

The operator to be overloaded; this must be one of the binary enumerators in expr_kind, without the expr_kind:: qualification.

t_udt_trait

A trait template to use to constrain which types are accepted as T template parameters to the defined operator overload.

u_udt_trait

A trait template to use to constrain which types are accepted as U template parameters to the defined operator overload.


PrevUpHomeNext