PrevUpHomeNext

Minimal

minimal_expr below models ExpressionTemplate; since it has no operators, an expression must be built manually.

First, the template itself:

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

    Tuple elements;
};

This can be used to make a minimal_expr plus expression:

auto left = boost::yap::make_terminal<minimal_expr>(1);
auto right = boost::yap::make_terminal<minimal_expr>(41);

auto expr = boost::yap::make_expression<
    minimal_expr,
    boost::yap::expr_kind::plus
>(left, right);

You can evaluate, transform, or otherwise operate on minimal_expr expressions using the functions in Boost.YAP that accept an Expression:

auto result = boost::yap::evaluate(expr);

std::cout << result << "\n"; // prints "42"

[Note] Note

Don't use Boost.YAP this way. Use the operator macros instead. This is an example contrived only to show you the minimum requirements on a Boost.YAP-compatible template.


PrevUpHomeNext