// 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 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 { static boost::yap::expr_kind const kind = Kind; Tuple elements; }; BOOST_YAP_USER_BINARY_OPERATOR(plus, user_expr, user_expr) template using user_term = boost::yap::terminal; template using user_ref = boost::yap::expression_ref; int test_main(int, char * []) { { { BOOST_MPL_ASSERT((std::is_same)); BOOST_CHECK(yap::value(1.0) == 1.0); } { double d = 2.0; BOOST_MPL_ASSERT((std::is_same)); BOOST_CHECK(yap::value(d) == 2.0); } { double const d = 3.0; BOOST_MPL_ASSERT( (std::is_same)); BOOST_CHECK(yap::value(d) == 3.0); } } { { term td = {{1.0}}; BOOST_MPL_ASSERT( (std::is_same)); BOOST_CHECK(yap::value(std::move(td)) == 1.0); } { term td = {{2.0}}; BOOST_MPL_ASSERT((std::is_same)); BOOST_CHECK(yap::value(td) == 2.0); } { term const td = {{3.0}}; BOOST_MPL_ASSERT( (std::is_same)); BOOST_CHECK(yap::value(td) == 3.0); } term unity = {{1.0}}; using plus_expr_type = yap::expression< yap::expr_kind::plus, bh::tuple &>, term>>; plus_expr_type plus_expr = unity + term{{1}}; { ref &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same)); } { ref &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same)); } { ref &> const ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same)); } { term const unity = {{1.0}}; yap::expression< yap::expr_kind::plus, bh::tuple const &>, term>> plus_expr = unity + term{{1}}; { ref const &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same< decltype(yap::value(std::move(ref))), double const &>)); } { ref const &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same)); } { ref const &> const ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same)); } } } { { user_term td = {{1.0}}; BOOST_MPL_ASSERT( (std::is_same)); BOOST_CHECK(yap::value(std::move(td)) == 1.0); } { user_term td = {{2.0}}; BOOST_MPL_ASSERT((std::is_same)); BOOST_CHECK(yap::value(td) == 2.0); } { user_term const td = {{3.0}}; BOOST_MPL_ASSERT( (std::is_same)); BOOST_CHECK(yap::value(td) == 3.0); } user_term unity = {{1.0}}; using plus_expr_type = user_expr< yap::expr_kind::plus, bh::tuple &>, user_term>>; plus_expr_type plus_expr = unity + user_term{{1}}; { user_ref &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same)); } { user_ref &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same)); } { user_ref &> const ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same)); } { user_term const unity = {{1.0}}; user_expr< yap::expr_kind::plus, bh::tuple const &>, user_term>> plus_expr = unity + user_term{{1}}; { user_ref const &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same< decltype(yap::value(std::move(ref))), double const &>)); } { user_ref const &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same)); } { user_ref const &> const ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same)); } } } return 0; }