#include #include template using term = boost::yap::terminal; 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(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< yap::expression_ref &>, term > >; plus_expr_type plus_expr = unity + term{{1}}; { yap::expression_ref &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same &>::value)); } { yap::expression_ref &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same &>::value)); } { yap::expression_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< yap::expression_ref const &>, term > > plus_expr = unity + term{{1}}; { yap::expression_ref const &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same const &>::value)); } { yap::expression_ref const &> ref = bh::front(plus_expr.elements); EXPECT_TRUE((std::is_same const &>::value)); } { yap::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(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 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)); } } }