PrevUpHomeNext

Operators

Let's see an expression template type with some operators:

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

    Tuple elements;

    // Note that this does not return an expression; it is greedily evaluated.
    auto operator[] (std::size_t n) const;
};

BOOST_YAP_USER_BINARY_OPERATOR(plus, lazy_vector_expr, lazy_vector_expr)
BOOST_YAP_USER_BINARY_OPERATOR(minus, lazy_vector_expr, lazy_vector_expr)

Those macros are used to define operator overloads that return Expressions. As shown here, that sort of operator can be mixed with normal, non-lazy ones — the operator[] is a normal eager function.

Use of the macros is not necessary (you can write your own operators that return Expressions if you like), but it is suitable 99% of the time.

Making the operators easy to define like this allows you to define custom expression templates that have only the operators defined that are appropriate for your use case.

Detailed documentation on all the available macros can be found later in the Operator Macros section.


PrevUpHomeNext