// Copyright (C) 2016-2018 T. Zachary Laine // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include template using term = boost::yap::terminal; namespace yap = boost::yap; namespace bh = boost::hana; struct iota_terminal_transform { template auto operator()(boost::yap::expr_tag, T && t) { return boost::yap::make_terminal(index_++); } template auto operator()(boost::yap::expr_tag, CallableExpr callable, Arg &&... arg) { return boost::yap::make_expression( callable, boost::yap::transform(arg, *this)...); } int index_; }; struct plus_expr_t { static yap::expr_kind const kind = yap::expr_kind::plus; bh::tuple, term> elements; }; int test_main(int, char * []) { // Each node instantiated from from yap::expression. { auto plus_expr = yap::terminal{{5}} + 6; BOOST_CHECK(yap::evaluate(plus_expr) == 11); BOOST_CHECK( yap::evaluate( yap::transform(plus_expr, iota_terminal_transform{0})) == 1); } // Each node instantiated from from yap::minimal_expr. { yap::minimal_expr, term>> plus_expr; yap::evaluate(yap::transform(plus_expr, iota_terminal_transform{0}), 1); } // Leaves are instantiated from from yap::minimal_expr; nonterminal // expr_kind::plus does not even come from a template. { plus_expr_t plus_expr; yap::evaluate(yap::transform(plus_expr, iota_terminal_transform{0}), 1); } return 0; }