#include "expression.hpp" #include template using term = boost::proto17::terminal; namespace bp17 = boost::proto17; namespace bh = boost::hana; template struct user_expr { using this_type = user_expr; static boost::proto17::expr_kind const kind = Kind; Tuple elements; BOOST_PROTO17_USER_BINARY_OPERATOR_MEMBER(plus, this_type, ::user_expr) }; template using user_term = boost::proto17::terminal; template using user_ref = boost::proto17::expression_ref; TEST(expression, test_value) { { term td = {{1.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(bp17::value(std::move(td)), 1.0); } { term td = {{2.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(bp17::value(td), 2.0); } { term const td = {{3.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(bp17::value(td), 3.0); } term unity = {{1.0}}; using plus_expr_type = bp17::expression< bp17::expr_kind::plus, bh::tuple< bp17::expression_ref &>, term > >; plus_expr_type plus_expr = unity + term{{1}}; { bp17::expression_ref &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same &>::value)); } { bp17::expression_ref &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same &>::value)); } { bp17::expression_ref &> const ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same &>::value)); } { term const unity = {{1.0}}; bp17::expression< bp17::expr_kind::plus, bh::tuple< bp17::expression_ref const &>, term > > plus_expr = unity + term{{1}}; { bp17::expression_ref const &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same const &>::value)); } { bp17::expression_ref const &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same const &>::value)); } { bp17::expression_ref const &> const ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same const &>::value)); } } } TEST(user_expr, test_value) { { user_term td = {{1.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(bp17::value(std::move(td)), 1.0); } { user_term td = {{2.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(bp17::value(td), 2.0); } { user_term const td = {{3.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(bp17::value(td), 3.0); } user_term unity = {{1.0}}; using plus_expr_type = user_expr< bp17::expr_kind::plus, bh::tuple< user_ref &>, user_term > >; plus_expr_type plus_expr = unity + user_term{{1}}; { user_ref &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same &>::value)); } { user_ref &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same &>::value)); } { user_ref &> const ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same &>::value)); } { user_term const unity = {{1.0}}; user_expr< bp17::expr_kind::plus, bh::tuple< user_ref const &>, user_term > > plus_expr = unity + user_term{{1}}; { user_ref const &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same const &>::value)); } { user_ref const &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same const &>::value)); } { user_ref const &> const ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same const &>::value)); } } }