]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/yap/test/transform.cpp
1 // Copyright (C) 2016-2018 T. Zachary Laine
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/yap/yap.hpp>
8 #include <boost/mpl/assert.hpp>
10 #include <boost/core/lightweight_test.hpp>
16 using term
= boost::yap::terminal
<boost::yap::minimal_expr
, T
>;
18 namespace yap
= boost::yap
;
19 namespace bh
= boost::hana
;
22 struct iota_terminal_transform
25 auto operator()(boost::yap::expr_tag
<boost::yap::expr_kind::terminal
>, T
&& t
)
27 return boost::yap::make_terminal(index_
++);
30 template<typename CallableExpr
, typename
... Arg
>
31 auto operator()(boost::yap::expr_tag
<boost::yap::expr_kind::call
>,
32 CallableExpr callable
, Arg
&&... arg
)
34 return boost::yap::make_expression
<boost::yap::expr_kind::call
>(
35 callable
, boost::yap::transform(arg
, *this)...);
43 static yap::expr_kind
const kind
= yap::expr_kind::plus
;
45 bh::tuple
<term
<int>, term
<int>> elements
;
50 // Each node instantiated from from yap::expression.
52 auto plus_expr
= yap::terminal
<yap::expression
, int>{{5}} + 6;
54 BOOST_TEST(yap::evaluate(plus_expr
) == 11);
58 yap::transform(plus_expr
, iota_terminal_transform
{0})) == 1);
61 // Each node instantiated from from yap::minimal_expr.
63 yap::minimal_expr
<yap::expr_kind::plus
, bh::tuple
<term
<int>, term
<int>>>
66 yap::evaluate(yap::transform(plus_expr
, iota_terminal_transform
{0}), 1);
69 // Leaves are instantiated from from yap::minimal_expr; nonterminal
70 // expr_kind::plus does not even come from a template.
72 plus_expr_t plus_expr
;
74 yap::evaluate(yap::transform(plus_expr
, iota_terminal_transform
{0}), 1);
77 return boost::report_errors();