// 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 * []) { { 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< decltype(yap::deref(std::move(ref))), term &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { ref &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { ref &> const ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { 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::deref(std::move(ref))), term const &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { ref const &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same< decltype(yap::deref(ref)), term const &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { ref const &> const ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same< decltype(yap::deref(ref)), term const &>)); BOOST_CHECK(yap::value(ref) == 1.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< decltype(yap::deref(std::move(ref))), user_term &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { user_ref &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { user_ref &> const ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT( (std::is_same &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { 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::deref(std::move(ref))), user_term const &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { user_ref const &> ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same< decltype(yap::deref(ref)), user_term const &>)); BOOST_CHECK(yap::value(ref) == 1.0); } { user_ref const &> const ref = bh::front(plus_expr.elements); BOOST_MPL_ASSERT((std::is_same< decltype(yap::deref(ref)), user_term const &>)); BOOST_CHECK(yap::value(ref) == 1.0); } } } return 0; }