#include #include template using term = boost::yap::terminal; template using ref = boost::yap::expression_ref; namespace yap = boost::yap; namespace bh = boost::hana; template struct user_expr { using this_type = user_expr; static boost::yap::expr_kind const kind = Kind; Tuple elements; BOOST_YAP_USER_BINARY_OPERATOR_MEMBER(plus, this_type, ::user_expr) }; template using user_term = boost::yap::terminal; template using user_ref = boost::yap::expression_ref; TEST(builtin, test_value) { { EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(yap::value(1.0), 1.0); } { double d = 2.0; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(yap::value(d), 2.0); } { double const d = 3.0; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(yap::value(d), 3.0); } } TEST(expression, test_value) { { term td = {{1.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(yap::value(std::move(td)), 1.0); } { term td = {{2.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(yap::value(td), 2.0); } { term const td = {{3.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(yap::value(td), 3.0); } term unity = {{1.0}}; using plus_expr_type = yap::expression< yap::expr_kind::plus, bh::tuple< ref &>, term > >; plus_expr_type plus_expr = unity + term{{1}}; { ref &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same::value)); } { ref &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same::value)); } { ref &> const ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same::value)); } { term const unity = {{1.0}}; yap::expression< yap::expr_kind::plus, bh::tuple< ref const &>, term > > plus_expr = unity + term{{1}}; { ref const &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same::value)); } { ref const &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same::value)); } { ref const &> const ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same::value)); } } } TEST(user_expr, test_value) { { user_term td = {{1.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(yap::value(std::move(td)), 1.0); } { user_term td = {{2.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(yap::value(td), 2.0); } { user_term const td = {{3.0}}; EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(yap::value(td), 3.0); } user_term unity = {{1.0}}; using plus_expr_type = user_expr< yap::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< yap::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::value)); } { user_ref const &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same::value)); } { user_ref const &> const ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same::value)); } } }