123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- // 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 <boost/yap/expression.hpp>
- #include <boost/mpl/assert.hpp>
- #include <boost/test/minimal.hpp>
- template<typename T>
- using term = boost::yap::terminal<boost::yap::expression, T>;
- template<typename T>
- using ref = boost::yap::expression_ref<boost::yap::expression, T>;
- namespace yap = boost::yap;
- namespace bh = boost::hana;
- template<boost::yap::expr_kind Kind, typename Tuple>
- struct user_expr
- {
- static boost::yap::expr_kind const kind = Kind;
- Tuple elements;
- };
- BOOST_YAP_USER_BINARY_OPERATOR(plus, user_expr, user_expr)
- template<typename T>
- using user_term = boost::yap::terminal<user_expr, T>;
- template<typename T>
- using user_ref = boost::yap::expression_ref<user_expr, T>;
- int test_main(int, char * [])
- {
- {
- term<double> unity = {{1.0}};
- using plus_expr_type = yap::expression<
- yap::expr_kind::plus,
- bh::tuple<ref<term<double> &>, term<int>>>;
- {
- plus_expr_type plus_expr = unity + term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(std::move(plus_expr))),
- ref<term<double> &> &&>));
- }
- {
- plus_expr_type plus_expr = unity + term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr)),
- ref<term<double> &> &>));
- }
- {
- plus_expr_type const plus_expr = unity + term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr)),
- ref<term<double> &> const &>));
- }
- {
- term<double> const unity = {{1.0}};
- using plus_expr_type = yap::expression<
- yap::expr_kind::plus,
- bh::tuple<ref<term<double> const &>, term<int>>>;
- {
- plus_expr_type plus_expr = unity + term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(std::move(plus_expr))),
- ref<term<double> const &> &&>));
- }
- {
- plus_expr_type plus_expr = unity + term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr)),
- ref<term<double> const &> &>));
- }
- {
- plus_expr_type const plus_expr = unity + term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr)),
- ref<term<double> const &> const &>));
- }
- }
- {
- term<double> unity = {{1.0}};
- using plus_expr_type = yap::expression<
- yap::expr_kind::plus,
- bh::tuple<ref<term<double> &>, term<int>>>;
- plus_expr_type plus_expr = unity + term<int>{{1}};
- using plus_plus_expr_type = yap::expression<
- yap::expr_kind::plus,
- bh::tuple<ref<plus_expr_type &>, term<int>>>;
- {
- plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
- ref<plus_expr_type &> plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(std::move(plus_expr_ref))),
- ref<term<double> &> &>));
- }
- {
- plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
- ref<plus_expr_type &> plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr_ref)),
- ref<term<double> &> &>));
- }
- {
- plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
- ref<plus_expr_type &> const plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr_ref)),
- ref<term<double> &> &>));
- }
- }
- {
- term<double> unity = {{1.0}};
- using plus_expr_type = yap::expression<
- yap::expr_kind::plus,
- bh::tuple<ref<term<double> &>, term<int>>>;
- plus_expr_type const plus_expr = unity + term<int>{{1}};
- using plus_plus_expr_type = yap::expression<
- yap::expr_kind::plus,
- bh::tuple<ref<plus_expr_type const &>, term<int>>>;
- {
- plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
- ref<plus_expr_type const &> plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(std::move(plus_expr_ref))),
- ref<term<double> &> const &>));
- }
- {
- plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
- ref<plus_expr_type const &> plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr_ref)),
- ref<term<double> &> const &>));
- }
- {
- plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
- ref<plus_expr_type const &> const plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr_ref)),
- ref<term<double> &> const &>));
- }
- }
- }
- {
- user_term<double> unity = {{1.0}};
- using plus_expr_type = user_expr<
- yap::expr_kind::plus,
- bh::tuple<user_ref<user_term<double> &>, user_term<int>>>;
- {
- plus_expr_type plus_expr = unity + user_term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(std::move(plus_expr))),
- user_ref<user_term<double> &> &&>));
- }
- {
- plus_expr_type plus_expr = unity + user_term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr)),
- user_ref<user_term<double> &> &>));
- }
- {
- plus_expr_type const plus_expr = unity + user_term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr)),
- user_ref<user_term<double> &> const &>));
- }
- {
- user_term<double> const unity = {{1.0}};
- using plus_expr_type = user_expr<
- yap::expr_kind::plus,
- bh::tuple<user_ref<user_term<double> const &>, user_term<int>>>;
- {
- plus_expr_type plus_expr = unity + user_term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(std::move(plus_expr))),
- user_ref<user_term<double> const &> &&>));
- }
- {
- plus_expr_type plus_expr = unity + user_term<int>{{1}};
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr)),
- user_ref<user_term<double> const &> &>));
- }
- {
- plus_expr_type const plus_expr = unity + user_term<int>{{1}};
- BOOST_MPL_ASSERT(
- (std::is_same<
- decltype(yap::left(plus_expr)),
- user_ref<user_term<double> const &> const &>));
- }
- }
- {
- user_term<double> unity = {{1.0}};
- using plus_expr_type = user_expr<
- yap::expr_kind::plus,
- bh::tuple<user_ref<user_term<double> &>, user_term<int>>>;
- plus_expr_type plus_expr = unity + user_term<int>{{1}};
- using plus_plus_expr_type = user_expr<
- yap::expr_kind::plus,
- bh::tuple<user_ref<plus_expr_type &>, user_term<int>>>;
- {
- plus_plus_expr_type plus_plus_expr =
- plus_expr + user_term<int>{{1}};
- user_ref<plus_expr_type &> plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(std::move(plus_expr_ref))),
- user_ref<user_term<double> &> &>));
- }
- {
- plus_plus_expr_type plus_plus_expr =
- plus_expr + user_term<int>{{1}};
- user_ref<plus_expr_type &> plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr_ref)),
- user_ref<user_term<double> &> &>));
- }
- {
- plus_plus_expr_type plus_plus_expr =
- plus_expr + user_term<int>{{1}};
- user_ref<plus_expr_type &> const plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr_ref)),
- user_ref<user_term<double> &> &>));
- }
- }
- {
- user_term<double> unity = {{1.0}};
- using plus_expr_type = user_expr<
- yap::expr_kind::plus,
- bh::tuple<user_ref<user_term<double> &>, user_term<int>>>;
- plus_expr_type const plus_expr = unity + user_term<int>{{1}};
- using plus_plus_expr_type = user_expr<
- yap::expr_kind::plus,
- bh::tuple<user_ref<plus_expr_type const &>, user_term<int>>>;
- {
- plus_plus_expr_type plus_plus_expr =
- plus_expr + user_term<int>{{1}};
- user_ref<plus_expr_type const &> plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(std::move(plus_expr_ref))),
- user_ref<user_term<double> &> const &>));
- }
- {
- plus_plus_expr_type plus_plus_expr =
- plus_expr + user_term<int>{{1}};
- user_ref<plus_expr_type const &> plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr_ref)),
- user_ref<user_term<double> &> const &>));
- }
- {
- plus_plus_expr_type plus_plus_expr =
- plus_expr + user_term<int>{{1}};
- user_ref<plus_expr_type const &> const plus_expr_ref =
- bh::front(plus_plus_expr.elements);
- BOOST_MPL_ASSERT((std::is_same<
- decltype(yap::left(plus_expr_ref)),
- user_ref<user_term<double> &> const &>));
- }
- }
- }
- return 0;
- }
|