From 29a7bedc0074cfcf62ca1a726159a3f353884a5e Mon Sep 17 00:00:00 2001 From: Zach Laine Date: Tue, 22 Nov 2016 17:04:05 -0600 Subject: [PATCH] Add reference-to-expr expr_kind expr_ref; expressions used in other expressions are now captured by reference. --- detail/default_eval.hpp | 18 +- detail/expression.hpp | 17 +- example/lazy_vector.cpp | 69 ++++-- expression.hpp | 215 ++++++++++++++---- expression_fwd.hpp | 2 + print.hpp | 63 +++-- test/call_expr.cpp | 4 +- test/compile_const_term.cpp | 19 +- test/compile_move_only_types.cpp | 6 +- test/compile_placeholders.cpp | 7 +- test/compile_term_plus_expr.cpp | 155 +++++++------ test/compile_term_plus_term.cpp | 57 +++-- test/compile_term_plus_x.cpp | 29 ++- ...compile_term_plus_x_this_ref_overloads.cpp | 29 ++- test/compile_x_plus_term.cpp | 31 ++- test/default_eval.cpp | 49 +++- test/placeholder_eval.cpp | 6 +- test/print.cpp | 30 ++- test/user_eval_expression_as.cpp | 6 +- test/user_expression_transform.cpp | 11 +- test/user_expression_transform_3.cpp | 35 +-- test/user_operator_and_eval_expression_as.cpp | 6 +- test/user_operator_eval.cpp | 6 +- 23 files changed, 557 insertions(+), 313 deletions(-) diff --git a/detail/default_eval.hpp b/detail/default_eval.hpp index 55b08ba..bbe8410 100644 --- a/detail/default_eval.hpp +++ b/detail/default_eval.hpp @@ -51,12 +51,12 @@ namespace boost::proto17 { > ) { return transform_expression(expr, static_cast(args)...); + } else if constexpr (kind == expr_kind::expr_ref) { + return default_eval_expr(expr.value(), static_cast(args)...); } else if constexpr (kind == expr_kind::terminal) { - static_assert(decltype(hana::size(expr.elements))::value == 1UL); - return expr.elements[0_c]; + return expr.value(); } else if constexpr (kind == expr_kind::placeholder) { - static_assert(decltype(hana::size(expr.elements))::value == 1UL); - return eval_placeholder(expr.elements[0_c], static_cast(args)...); + return eval_placeholder(expr.value(), static_cast(args)...); } #define BOOST_PROTO17_UNARY_OPERATOR_CASE(op_name) \ @@ -142,7 +142,7 @@ namespace boost::proto17 { return hana::unpack( expr.elements, - [&](auto && ... elements) { + [expand_args](auto && ... elements) { return eval_call( expand_args(static_cast(elements))... ); @@ -162,7 +162,11 @@ namespace boost::proto17 { auto operator() (Expr && expr, Transform && transform) { constexpr expr_kind kind = remove_cv_ref_t::kind; - if constexpr (kind == expr_kind::terminal || kind == expr_kind::placeholder) { + if constexpr (kind == expr_kind::expr_ref) { + decltype(auto) ref = expr.value(); + default_transform_expression transformer; + return transformer(ref, static_cast(transform)); + } else if constexpr (kind == expr_kind::terminal || kind == expr_kind::placeholder) { return static_cast(expr); } else { return transform_nonterminal_tuple( @@ -198,7 +202,7 @@ namespace boost::proto17 { ); } ); - using return_type = expression; + using return_type = expression; // TODO: Don't turn this into an expression<>! return return_type(std::move(transformed_tuple)); } diff --git a/detail/expression.hpp b/detail/expression.hpp index 07a0cef..c98994c 100644 --- a/detail/expression.hpp +++ b/detail/expression.hpp @@ -81,20 +81,25 @@ namespace boost::proto17 { typename T, typename U = typename operand_value_type_phase_1::type, bool RemoveRefs = std::is_rvalue_reference_v, - bool IsExpr = is_expr>::value + bool IsExpr = is_expr>::value, + bool IsLRef = std::is_lvalue_reference{} > struct operand_type; template - struct operand_type + struct operand_type { using type = remove_cv_ref_t; }; - template - struct operand_type + template + struct operand_type + { using type = expression; }; + + template + struct operand_type { using type = terminal>; }; - template - struct operand_type + template + struct operand_type { using type = terminal; }; template diff --git a/example/lazy_vector.cpp b/example/lazy_vector.cpp index 71da71b..9ea5f1a 100644 --- a/example/lazy_vector.cpp +++ b/example/lazy_vector.cpp @@ -13,12 +13,13 @@ struct eval_nth auto operator() (Expr const & expr) { using boost::proto17::transform; - using boost::proto17::value; using boost::proto17::left; using boost::proto17::right; if constexpr (Expr::kind == boost::proto17::expr_kind::terminal) { - return value(expr)[n]; + return boost::proto17::value(expr)[n]; + } else if constexpr (Expr::kind == boost::proto17::expr_kind::expr_ref) { + return transform(boost::proto17::value(expr), *this); } else if constexpr (Expr::kind == boost::proto17::expr_kind::plus) { return transform(left(expr), *this) + transform(right(expr), *this); } else if constexpr (Expr::kind == boost::proto17::expr_kind::minus) { @@ -29,30 +30,34 @@ struct eval_nth std::size_t n; }; -template +template struct lazy_vector_expr { - using this_type = lazy_vector_expr; + using this_type = lazy_vector_expr; static const boost::proto17::expr_kind kind = Kind; - boost::hana::tuple elements; + Tuple elements; - template - auto operator+ (lazy_vector_expr const & rhs) + template + auto operator+ (Expr && rhs) { - using rhs_type = lazy_vector_expr; - return lazy_vector_expr{ - boost::hana::tuple{*this, rhs} + using lhs_type = boost::proto17::expression_ref; + using rhs_type = boost::proto17::detail::operand_type_t; + using tuple_type = boost::hana::tuple; + return lazy_vector_expr{ + tuple_type{lhs_type{*this}, rhs_type{rhs}} }; } - template - auto operator- (lazy_vector_expr const & rhs) + template + auto operator- (Expr && rhs) { - using rhs_type = lazy_vector_expr; - return lazy_vector_expr{ - boost::hana::tuple{*this, rhs} + using lhs_type = boost::proto17::expression_ref; + using rhs_type = boost::proto17::detail::operand_type_t; + using tuple_type = boost::hana::tuple; + return lazy_vector_expr{ + tuple_type{lhs_type{*this}, rhs_type{rhs}} }; } @@ -63,11 +68,11 @@ struct lazy_vector_expr struct lazy_vector : lazy_vector_expr< boost::proto17::expr_kind::terminal, - std::vector // TODO: Use a reference? + boost::hana::tuple> > { - template - auto operator+= (lazy_vector_expr const & rhs) + template + lazy_vector & operator+= (lazy_vector_expr const & rhs) { std::vector & this_vec = boost::proto17::value(*this); for (int i = 0, size = (int)this_vec.size(); i < size; ++i) { @@ -83,7 +88,33 @@ int main () lazy_vector v2{{std::vector(4, 2.0)}}; lazy_vector v3{{std::vector(4, 3.0)}}; - // TODO: Restore reference preservation when building expression trees. +#if 1 // TODO + // Type of the plus expression. Note the mix of boost::proto17 and user types. + lazy_vector_expr< + boost::proto17::expr_kind::plus, + boost::hana::tuple< + boost::proto17::expression< + boost::proto17::expr_kind::expr_ref, + // This is expanded into a lazy_vector_expr, because + // lazy_vector_expr::operator+() does not know whether it is a + // lazy_vector or not. + lazy_vector_expr< + boost::proto17::expr_kind::terminal, + boost::hana::tuple> + > const & + >, + boost::proto17::expression< + boost::proto17::expr_kind::expr_ref, + // This is preserved as a lazy_vector, since the rhs of + // lazy_vector_expr::operator+() just wraps whatever Expr type + // it is given. + lazy_vector & + > + > + > plus_expr = v2 + v3; + (void)plus_expr; +#endif + double d1 = (v2 + v3)[2]; std::cout << d1 << "\n"; diff --git a/expression.hpp b/expression.hpp index 628c9f6..69f6e7c 100644 --- a/expression.hpp +++ b/expression.hpp @@ -154,9 +154,19 @@ namespace boost::proto17 { #define BOOST_PROTO17_UNARY_MEMBER_OPERATOR(op, op_name) \ auto operator op const & \ { \ - using tuple_type = hana::tuple; \ + using lhs_type = expression; \ + using tuple_type = hana::tuple; \ return expression{ \ - tuple_type{*this} \ + tuple_type{lhs_type{*this}} \ + }; \ + } \ + template \ + auto operator op & \ + { \ + using lhs_type = expression; \ + using tuple_type = hana::tuple; \ + return expression{ \ + tuple_type{lhs_type{*this}} \ }; \ } \ auto operator op && \ @@ -180,17 +190,26 @@ namespace boost::proto17 { #undef BOOST_PROTO17_UNARY_MEMBER_OPERATOR + // TODO: Add test coverage for all the operators, for expression and terminal. #define BOOST_PROTO17_BINARY_MEMBER_OPERATOR(op, op_name) \ template \ auto operator op (U && rhs) const & \ { \ + using lhs_type = expression; \ using rhs_type = detail::operand_type_t; \ - using tuple_type = hana::tuple; \ + using tuple_type = hana::tuple; \ return expression{ \ - tuple_type{ \ - *this, \ - static_cast(rhs) \ - } \ + tuple_type{lhs_type{*this}, static_cast(rhs)} \ + }; \ + } \ + template \ + auto operator op (U && rhs) & \ + { \ + using lhs_type = expression; \ + using rhs_type = detail::operand_type_t; \ + using tuple_type = hana::tuple; \ + return expression{ \ + tuple_type{lhs_type{*this}, static_cast(rhs)} \ }; \ } \ template \ @@ -199,10 +218,7 @@ namespace boost::proto17 { using rhs_type = detail::operand_type_t; \ using tuple_type = hana::tuple; \ return expression{ \ - tuple_type{ \ - std::move(*this), \ - static_cast(rhs) \ - } \ + tuple_type{std::move(*this), static_cast(rhs)} \ }; \ } @@ -228,10 +244,21 @@ namespace boost::proto17 { template auto operator, (U && rhs) const & { + using lhs_type = expression; using rhs_type = detail::operand_type_t; using tuple_type = hana::tuple; return expression{ - tuple_type{*this, static_cast(rhs)} + tuple_type{lhs_type{*this}, static_cast(rhs)} + }; + } + template + auto operator, (U && rhs) & + { + using lhs_type = expression; + using rhs_type = detail::operand_type_t; + using tuple_type = hana::tuple; + return expression{ + tuple_type{lhs_type{*this}, static_cast(rhs)} }; } template @@ -263,9 +290,19 @@ namespace boost::proto17 { template auto operator() (U && ...u) const & { - using tuple_type = hana::tuple...>; + using lhs_type = expression; + using tuple_type = hana::tuple...>; return expression{ - tuple_type{*this, static_cast(u)...} + tuple_type{lhs_type{*this}, static_cast(u)...} + }; + } + template + auto operator() (U && ...u) & + { + using lhs_type = expression; + using tuple_type = hana::tuple...>; + return expression{ + tuple_type{lhs_type{*this}, static_cast(u)...} }; } template @@ -278,6 +315,32 @@ namespace boost::proto17 { } }; + template + struct expression + { + static_assert(std::is_lvalue_reference{}); + + using this_type = expression; + using tuple_type = hana::tuple *>; + + static const expr_kind kind = expr_kind::expr_ref; + + expression (T t) : + elements (std::addressof(t)) + {} + + tuple_type elements; + + T value () const + { + using namespace hana::literals; + return *elements[0_c]; + } + }; + + template + using expression_ref = expression; + template struct expression { @@ -305,39 +368,37 @@ namespace boost::proto17 { decltype(auto) value () const & { using namespace hana::literals; - static_assert( - decltype(hana::size(elements))::value == 1UL, - "value() is only defined for unary expressions." - ); return elements[0_c]; } decltype(auto) value () & { using namespace hana::literals; - static_assert( - decltype(hana::size(elements))::value == 1UL, - "value() is only defined for unary expressions." - ); return elements[0_c]; } decltype(auto) value () && { using namespace hana::literals; - static_assert( - decltype(hana::size(elements))::value == 1UL, - "value() is only defined for unary expressions." - ); return static_cast(elements)[0_c]; } #define BOOST_PROTO17_UNARY_MEMBER_OPERATOR(op, op_name) \ auto operator op const & \ { \ - using tuple_type = hana::tuple; \ + using lhs_type = expression; \ + using tuple_type = hana::tuple; \ return expression{ \ - tuple_type{*this} \ + tuple_type{lhs_type{*this}} \ + }; \ + } \ + template \ + auto operator op & \ + { \ + using lhs_type = expression; \ + using tuple_type = hana::tuple; \ + return expression{ \ + tuple_type{lhs_type{*this}} \ }; \ } \ auto operator op && \ @@ -365,10 +426,21 @@ namespace boost::proto17 { template \ auto operator op (U && rhs) const & \ { \ + using lhs_type = expression; \ using rhs_type = detail::operand_type_t; \ - using tuple_type = hana::tuple; \ + using tuple_type = hana::tuple; \ return expression{ \ - tuple_type{std::move(*this), static_cast(rhs)} \ + tuple_type{lhs_type{*this}, static_cast(rhs)} \ + }; \ + } \ + template \ + auto operator op (U && rhs) & \ + { \ + using lhs_type = expression; \ + using rhs_type = detail::operand_type_t; \ + using tuple_type = hana::tuple; \ + return expression{ \ + tuple_type{lhs_type{*this}, static_cast(rhs)} \ }; \ } \ template \ @@ -403,10 +475,21 @@ namespace boost::proto17 { template auto operator, (U && rhs) const & { + using lhs_type = expression; using rhs_type = detail::operand_type_t; using tuple_type = hana::tuple; return expression{ - tuple_type{*this, static_cast(rhs)} + tuple_type{lhs_type{*this}, static_cast(rhs)} + }; + } + template + auto operator, (U && rhs) & + { + using lhs_type = expression; + using rhs_type = detail::operand_type_t; + using tuple_type = hana::tuple; + return expression{ + tuple_type{lhs_type{*this}, static_cast(rhs)} }; } template @@ -438,9 +521,19 @@ namespace boost::proto17 { template auto operator() (U && ...u) const & { - using tuple_type = hana::tuple...>; + using lhs_type = expression; + using tuple_type = hana::tuple...>; return expression{ - tuple_type{*this, static_cast(u)...} + tuple_type{lhs_type{*this}, static_cast(u)...} + }; + } + template + auto operator() (U && ...u) & + { + using lhs_type = expression; + using tuple_type = hana::tuple...>; + return expression{ + tuple_type{lhs_type{*this}, static_cast(u)...} }; } template @@ -464,7 +557,11 @@ namespace boost::proto17 { decltype(hana::size(expr.elements))::value == 1UL, "value() is only defined for unary expressions." ); - return expr.elements[0_c]; + if constexpr (Expr::kind == expr_kind::expr_ref) { + return expr.value(); + } else { + return expr.elements[0_c]; + } } template @@ -475,7 +572,11 @@ namespace boost::proto17 { decltype(hana::size(expr.elements))::value == 1UL, "value() is only defined for unary expressions." ); - return expr.elements[0_c]; + if constexpr (Expr::kind == expr_kind::expr_ref) { + return expr.value(); + } else { + return expr.elements[0_c]; + } } template @@ -486,7 +587,11 @@ namespace boost::proto17 { decltype(hana::size(expr.elements))::value == 1UL, "value() is only defined for unary expressions." ); - return static_cast(expr.elements)[0_c]; + if constexpr (Expr::kind == expr_kind::expr_ref) { + return std::move(expr.value()); + } else { + return std::move(expr.elements[0_c]); + } } template @@ -561,12 +666,12 @@ namespace boost::proto17 { expr_kind OpKind, typename T, typename U, bool TNonExprUExpr = !detail::is_expr>::value && - detail::is_expr::value + detail::is_expr>::value > struct binary_op_result { using lhs_type = detail::operand_type_t; - using rhs_type = U; + using rhs_type = expression; using type = expression>; }; @@ -574,27 +679,45 @@ namespace boost::proto17 { struct binary_op_result {}; + template + using binary_op_result_t = typename binary_op_result::type; + } #define BOOST_PROTO17_BINARY_NON_MEMBER_OPERATOR(op, op_name) \ template \ auto operator op (T && lhs, Expr const & rhs) \ - -> typename detail::binary_op_result::type \ + -> detail::binary_op_result_t \ { \ - using lhs_type = detail::operand_type_t; \ - using rhs_type = Expr; \ + using result_types = detail::binary_op_result; \ + using lhs_type = typename result_types::lhs_type; \ + using rhs_type = typename result_types::rhs_type; \ + using tuple_type = hana::tuple; \ return { \ - hana::tuple{static_cast(lhs), rhs} \ + tuple_type{static_cast(lhs), rhs_type{rhs}} \ + }; \ + } \ + template \ + auto operator op (T && lhs, Expr & rhs) \ + -> detail::binary_op_result_t \ + { \ + using result_types = detail::binary_op_result; \ + using lhs_type = typename result_types::lhs_type; \ + using rhs_type = typename result_types::rhs_type; \ + using tuple_type = hana::tuple; \ + return { \ + tuple_type{static_cast(lhs), rhs_type{rhs}} \ }; \ } \ template \ auto operator op (T && lhs, detail::remove_cv_ref_t && rhs) \ - -> typename detail::binary_op_result>::type \ + -> detail::binary_op_result_t> \ { \ - using lhs_type = detail::operand_type_t; \ - using rhs_type = detail::remove_cv_ref_t; \ + using result_types = detail::binary_op_result>; \ + using lhs_type = typename result_types::lhs_type; \ + using rhs_type = typename result_types::rhs_type; \ return { \ - hana::tuple{static_cast(lhs), static_cast(rhs)} \ + hana::tuple{static_cast(lhs), std::move(rhs)} \ }; \ } diff --git a/expression_fwd.hpp b/expression_fwd.hpp index ada3613..c077a06 100644 --- a/expression_fwd.hpp +++ b/expression_fwd.hpp @@ -8,6 +8,8 @@ namespace boost::proto17 { enum class expr_kind { + expr_ref, + terminal, placeholder, diff --git a/print.hpp b/print.hpp index de43ace..d2cf20c 100644 --- a/print.hpp +++ b/print.hpp @@ -87,32 +87,57 @@ namespace boost::proto17 { return os; } + bool is_const_expr_ref (...) { return false; } + template + bool is_const_expr_ref (expression_ref const &) { return true; } + template std::ostream & print_impl ( std::ostream & os, Expr const & expr, int indent, - char const * indent_str) + char const * indent_str, + bool is_ref = false, + bool is_const_ref = false) { - for (int i = 0; i < indent; ++i) { - os << indent_str; - } - - if constexpr (Expr::kind == expr_kind::terminal) { - os << "term<"; - print_type(os, expr.elements); - os << ">[="; - print_value(os, value(expr)); - os << "]\n"; - } else if constexpr (Expr::kind == expr_kind::placeholder) { - os << "placeholder<" << (long long)value(expr) << ">\n"; + if constexpr (Expr::kind == expr_kind::expr_ref) { + print_impl(os, expr.value(), indent, indent_str, true, is_const_expr_ref(expr)); } else { - os << "expr<"; - print_kind(os, Expr::kind); - os << ">\n"; - hana::for_each(expr.elements, [&os, indent, indent_str](auto const & element) { - print_impl(os, element, indent + 1, indent_str); - }); + for (int i = 0; i < indent; ++i) { + os << indent_str; + } + + if constexpr (Expr::kind == expr_kind::terminal) { + os << "term<"; + print_type(os, expr.elements); + os << ">[="; + print_value(os, expr.value()); + os << "]"; + if (is_const_ref) + os << " const &"; + else if (is_ref) + os << " &"; + os << "\n"; + } else if constexpr (Expr::kind == expr_kind::placeholder) { + os << "placeholder<" << (long long)expr.value() << ">"; + if (is_const_ref) + os << " const &"; + else if (is_ref) + os << " &"; + os << "\n"; + } else { + os << "expr<"; + print_kind(os, Expr::kind); + os << ">"; + if (is_const_ref) + os << " const &"; + else if (is_ref) + os << " &"; + os << "\n"; + hana::for_each(expr.elements, [&os, indent, indent_str](auto const & element) { + print_impl(os, element, indent + 1, indent_str); + }); + } } return os; diff --git a/test/call_expr.cpp b/test/call_expr.cpp index 4602a6b..060def5 100644 --- a/test/call_expr.cpp +++ b/test/call_expr.cpp @@ -171,7 +171,7 @@ TEST(call_expr, test_call_expr) bp17::expression< bp17::expr_kind::call, bh::tuple< - term, + bp17::expression_ref& >, term, term > @@ -200,7 +200,7 @@ TEST(call_expr, test_call_expr) bp17::expression< bp17::expr_kind::call, bh::tuple< - term, + bp17::expression_ref& >, term, term > diff --git a/test/compile_const_term.cpp b/test/compile_const_term.cpp index 2715eed..4ded011 100644 --- a/test/compile_const_term.cpp +++ b/test/compile_const_term.cpp @@ -1,4 +1,3 @@ -#define BOOST_PROTO17_CONVERSION_OPERATOR_TEMPLATE #include "expression.hpp" template @@ -17,18 +16,18 @@ void compile_const_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > @@ -44,18 +43,18 @@ void compile_const_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref const &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref const &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref const &>, term > > @@ -71,18 +70,18 @@ void compile_const_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > const expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > diff --git a/test/compile_move_only_types.cpp b/test/compile_move_only_types.cpp index b3b67a1..51ac5ce 100644 --- a/test/compile_move_only_types.cpp +++ b/test/compile_move_only_types.cpp @@ -19,7 +19,7 @@ void compile_move_only_types () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term> > > expr_1 = unity + std::move(i); @@ -27,11 +27,11 @@ void compile_move_only_types () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term> > > diff --git a/test/compile_placeholders.cpp b/test/compile_placeholders.cpp index 1806507..03556fb 100644 --- a/test/compile_placeholders.cpp +++ b/test/compile_placeholders.cpp @@ -1,4 +1,3 @@ -#define BOOST_PROTO17_CONVERSION_OPERATOR_TEMPLATE #include "expression.hpp" template @@ -23,8 +22,8 @@ void compile_placeholders () bp17::expression< bp17::expr_kind::plus, bh::tuple< - bp17::placeholder<1>, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > expr = p1 + unity; (void)expr; @@ -35,7 +34,7 @@ void compile_placeholders () bp17::expression< bp17::expr_kind::plus, bh::tuple< - bp17::placeholder<1>, + bp17::expression_ref &>, bp17::placeholder<2> > > expr = p1 + 2_p; diff --git a/test/compile_term_plus_expr.cpp b/test/compile_term_plus_expr.cpp index 707378c..90352ce 100644 --- a/test/compile_term_plus_expr.cpp +++ b/test/compile_term_plus_expr.cpp @@ -1,4 +1,3 @@ -#define BOOST_PROTO17_CONVERSION_OPERATOR_TEMPLATE #include "expression.hpp" template @@ -17,21 +16,21 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > expr = unity + i; bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - bp17::expression< + bp17::expression_ref &>, + bp17::expression_ref, - term + bp17::expression_ref &>, + bp17::expression_ref &> > - > + > &> > > unevaluated_expr = unity + expr; (void)unevaluated_expr; @@ -43,21 +42,21 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > expr = unity + i; bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - bp17::expression< + bp17::expression_ref &>, + bp17::expression_ref, - term + bp17::expression_ref &>, + bp17::expression_ref &> > - > + > &> > > unevaluated_expr = unity + expr; (void)unevaluated_expr; @@ -69,21 +68,21 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - bp17::expression< + bp17::expression_ref &>, + bp17::expression_ref, + bp17::expression_ref &>, term > - > + > &> > > unevaluated_expr = unity + expr; (void)unevaluated_expr; @@ -96,21 +95,21 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref const &> > > const expr = unity + i; bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - bp17::expression< + bp17::expression_ref &>, + bp17::expression_ref, - term + bp17::expression_ref &>, + bp17::expression_ref const &> > - > + > const &> > > unevaluated_expr = unity + expr; (void)unevaluated_expr; @@ -122,21 +121,21 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > const expr = unity + i; bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - bp17::expression< + bp17::expression_ref &>, + bp17::expression_ref, - term + bp17::expression_ref &>, + bp17::expression_ref &> > - > + > const &> > > unevaluated_expr = unity + expr; (void)unevaluated_expr; @@ -150,21 +149,21 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > expr = unity + i; bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - bp17::expression< + bp17::expression_ref &>, + bp17::expression_ref, - term + bp17::expression_ref &>, + bp17::expression_ref &> > - > + > &> > > unevaluated_expr = unity + expr; (void)unevaluated_expr; @@ -177,21 +176,21 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > expr = unity + i; bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - bp17::expression< + bp17::expression_ref &>, + bp17::expression_ref, - term + bp17::expression_ref &>, + bp17::expression_ref &> > - > + > &> > > unevaluated_expr = unity + expr; (void)unevaluated_expr; @@ -204,21 +203,21 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - bp17::expression< + bp17::expression_ref &>, + bp17::expression_ref, + bp17::expression_ref &>, term > - > + > &> > > unevaluated_expr = unity + expr; (void)unevaluated_expr; @@ -231,19 +230,19 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > expr = unity + i; bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > > @@ -258,19 +257,19 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > expr = unity + i; bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > > @@ -285,18 +284,18 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > @@ -313,18 +312,18 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > @@ -340,18 +339,18 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > @@ -367,18 +366,18 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > @@ -394,18 +393,18 @@ void compile_term_plus_expr () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > diff --git a/test/compile_term_plus_term.cpp b/test/compile_term_plus_term.cpp index 203f5d0..3d44c81 100644 --- a/test/compile_term_plus_term.cpp +++ b/test/compile_term_plus_term.cpp @@ -1,4 +1,3 @@ -#define BOOST_PROTO17_CONVERSION_OPERATOR_TEMPLATE #include "expression.hpp" #include @@ -21,7 +20,7 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + term{"3"}; @@ -34,7 +33,7 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + term{"3"s}; @@ -49,8 +48,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > unevaluated_expr = unity + ints; (void)unevaluated_expr; @@ -63,8 +62,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > unevaluated_expr = unity + ints; (void)unevaluated_expr; @@ -77,7 +76,7 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(ints); @@ -92,8 +91,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > unevaluated_expr = unity + int_ptr; (void)unevaluated_expr; @@ -106,8 +105,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > unevaluated_expr = unity + int_ptr; (void)unevaluated_expr; @@ -120,7 +119,7 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(int_ptr); @@ -134,8 +133,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > unevaluated_expr = unity + i; (void)unevaluated_expr; @@ -147,8 +146,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > unevaluated_expr = unity + i; (void)unevaluated_expr; @@ -160,7 +159,7 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(i); @@ -174,8 +173,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref const &> > > unevaluated_expr = unity + i; (void)unevaluated_expr; @@ -187,8 +186,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref const &> > > unevaluated_expr = unity + i; (void)unevaluated_expr; @@ -202,8 +201,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > unevaluated_expr = unity + i; (void)unevaluated_expr; @@ -216,8 +215,8 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > > unevaluated_expr = unity + i; (void)unevaluated_expr; @@ -230,7 +229,7 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(i); @@ -245,7 +244,7 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(i); @@ -259,7 +258,7 @@ void compile_term_plus_term () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(i); diff --git a/test/compile_term_plus_x.cpp b/test/compile_term_plus_x.cpp index 8f48d9a..754ea3c 100644 --- a/test/compile_term_plus_x.cpp +++ b/test/compile_term_plus_x.cpp @@ -1,4 +1,3 @@ -#define BOOST_PROTO17_CONVERSION_OPERATOR_TEMPLATE #include "expression.hpp" #include @@ -21,7 +20,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + "3"; @@ -34,7 +33,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + "3"s; @@ -48,7 +47,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + ints; @@ -61,7 +60,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + ints; @@ -74,7 +73,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(ints); @@ -89,7 +88,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + int_ptr; @@ -103,7 +102,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + int_ptr; @@ -117,7 +116,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(int_ptr); @@ -132,7 +131,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + int_ptr; @@ -146,7 +145,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + int_ptr; @@ -160,7 +159,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(int_ptr); @@ -174,7 +173,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + i; @@ -187,7 +186,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + i; @@ -200,7 +199,7 @@ void compile_term_plus_x () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(i); diff --git a/test/compile_term_plus_x_this_ref_overloads.cpp b/test/compile_term_plus_x_this_ref_overloads.cpp index e994741..7fdcc4e 100644 --- a/test/compile_term_plus_x_this_ref_overloads.cpp +++ b/test/compile_term_plus_x_this_ref_overloads.cpp @@ -1,4 +1,3 @@ -#define BOOST_PROTO17_CONVERSION_OPERATOR_TEMPLATE #include "expression.hpp" #include @@ -21,7 +20,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + "3"; @@ -34,7 +33,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + "3"s; @@ -48,7 +47,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + ints; @@ -61,7 +60,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + ints; @@ -74,7 +73,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(ints); @@ -89,7 +88,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + int_ptr; @@ -103,7 +102,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + int_ptr; @@ -117,7 +116,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(int_ptr); @@ -132,7 +131,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + int_ptr; @@ -146,7 +145,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + int_ptr; @@ -160,7 +159,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(int_ptr); @@ -174,7 +173,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + i; @@ -187,7 +186,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + i; @@ -200,7 +199,7 @@ void compile_term_plus_x_this_ref_overloads () bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > unevaluated_expr = unity + std::move(i); diff --git a/test/compile_x_plus_term.cpp b/test/compile_x_plus_term.cpp index 73315eb..dd5f045 100644 --- a/test/compile_x_plus_term.cpp +++ b/test/compile_x_plus_term.cpp @@ -1,4 +1,3 @@ -#define BOOST_PROTO17_CONVERSION_OPERATOR_TEMPLATE #include "expression.hpp" #include @@ -22,7 +21,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = "3" + unity; (void)unevaluated_expr; @@ -30,12 +29,12 @@ void compile_x_plus_term () // std::string temporary { - term unity{1.0}; + term const unity{1.0}; bp17::expression< bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref const &> > > unevaluated_expr = "3"s + unity; (void)unevaluated_expr; @@ -49,7 +48,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = ints + unity; (void)unevaluated_expr; @@ -62,7 +61,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = ints + unity; (void)unevaluated_expr; @@ -75,7 +74,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = std::move(ints) + unity; (void)unevaluated_expr; @@ -90,7 +89,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = int_ptr + unity; (void)unevaluated_expr; @@ -104,7 +103,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = int_ptr + unity; (void)unevaluated_expr; @@ -118,7 +117,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = std::move(int_ptr) + unity; (void)unevaluated_expr; @@ -133,7 +132,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = int_ptr + unity; (void)unevaluated_expr; @@ -147,7 +146,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = int_ptr + unity; (void)unevaluated_expr; @@ -161,7 +160,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = std::move(int_ptr) + unity; (void)unevaluated_expr; @@ -175,7 +174,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = i + unity; (void)unevaluated_expr; @@ -188,7 +187,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = i + unity; (void)unevaluated_expr; @@ -201,7 +200,7 @@ void compile_x_plus_term () bp17::expr_kind::plus, bh::tuple< term, - term + bp17::expression_ref &> > > unevaluated_expr = std::move(i) + unity; (void)unevaluated_expr; diff --git a/test/default_eval.cpp b/test/default_eval.cpp index 86e3e89..0c02e5b 100644 --- a/test/default_eval.cpp +++ b/test/default_eval.cpp @@ -19,23 +19,40 @@ TEST(default_eval, default_eval) bp17::expression< bp17::expr_kind::minus, bh::tuple< - term, + boost::proto17::expression_ref &>, term > > expr = unity - std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + boost::proto17::expression_ref &>, bp17::expression< bp17::expr_kind::minus, bh::tuple< - term, + boost::proto17::expression_ref &>, term > > > - > unevaluated_expr = unity + std::move(expr); + > unevaluated_expr_1 = unity + std::move(expr); + + bp17::expression< + bp17::expr_kind::plus, + bh::tuple< + boost::proto17::expression_ref &>, + boost::proto17::expression_ref &> + > + > unevaluated_expr_2 = unity + unity; + + term const const_unity{1.0}; + bp17::expression< + bp17::expr_kind::plus, + bh::tuple< + boost::proto17::expression_ref &>, + boost::proto17::expression_ref const &> + > + > unevaluated_expr_3 = unity + const_unity; { double result = unity; @@ -48,10 +65,20 @@ TEST(default_eval, default_eval) } { - double result = unevaluated_expr; + double result = unevaluated_expr_1; EXPECT_EQ(result, -40); } + { + double result = unevaluated_expr_2; + EXPECT_EQ(result, 2); + } + + { + double result = unevaluated_expr_3; + EXPECT_EQ(result, 2); + } + { double result = evaluate(unity, 5, 6, 7); EXPECT_EQ(result, 1); @@ -63,7 +90,17 @@ TEST(default_eval, default_eval) } { - double result = evaluate(unevaluated_expr, std::string("15")); + double result = evaluate(unevaluated_expr_1, std::string("15")); EXPECT_EQ(result, -40); } + + { + double result = evaluate(unevaluated_expr_2, std::string("15")); + EXPECT_EQ(result, 2); + } + + { + double result = evaluate(unevaluated_expr_3, std::string("15")); + EXPECT_EQ(result, 2); + } } diff --git a/test/placeholder_eval.cpp b/test/placeholder_eval.cpp index fef0554..0147524 100644 --- a/test/placeholder_eval.cpp +++ b/test/placeholder_eval.cpp @@ -22,18 +22,18 @@ TEST(placeholder_eval, test_placeholder_eval) bp17::expression< bp17::expr_kind::plus, bh::tuple< - bp17::placeholder<3>, + bp17::expression_ref &>, term > > expr = p3 + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - bp17::placeholder<3>, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - bp17::placeholder<3>, + bp17::expression_ref &>, term > > diff --git a/test/print.cpp b/test/print.cpp index 99f5d06..aacf0b0 100644 --- a/test/print.cpp +++ b/test/print.cpp @@ -21,18 +21,18 @@ TEST(print, test_print) bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term > > @@ -50,7 +50,7 @@ TEST(print, test_print) std::ostringstream oss; bp17::print(oss, expr); EXPECT_EQ(oss.str(), R"(expr<+> - term[=1] + term[=1] & term[=42] )"); } @@ -59,9 +59,9 @@ TEST(print, test_print) std::ostringstream oss; bp17::print(oss, unevaluated_expr); EXPECT_EQ(oss.str(), R"(expr<+> - term[=1] + term[=1] & expr<+> - term[=1] + term[=1] & term[=42] )"); } @@ -73,6 +73,24 @@ TEST(print, test_print) std::ostringstream oss; bp17::print(oss, a_thing); EXPECT_EQ(oss.str(), R"(term[=<>] +)"); + } + + term const const_unity{1.0}; + bp17::expression< + bp17::expr_kind::plus, + bh::tuple< + bp17::expression_ref &>, + bp17::expression_ref const &> + > + > nonconst_plus_const = unity + const_unity; + + { + std::ostringstream oss; + bp17::print(oss, nonconst_plus_const); + EXPECT_EQ(oss.str(), R"(expr<+> + term[=1] & + term[=1] const & )"); } } diff --git a/test/user_eval_expression_as.cpp b/test/user_eval_expression_as.cpp index c842fa9..60568ae 100644 --- a/test/user_eval_expression_as.cpp +++ b/test/user_eval_expression_as.cpp @@ -44,18 +44,18 @@ TEST(user_eval_expression_as, test_user_eval_expression_as) bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref& >, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref& >, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref& >, term > > diff --git a/test/user_expression_transform.cpp b/test/user_expression_transform.cpp index e730fae..76f2407 100644 --- a/test/user_expression_transform.cpp +++ b/test/user_expression_transform.cpp @@ -105,7 +105,7 @@ TEST(user_expression_transform, test_user_expression_transform) >, term > - > expr = k * a * x + y; + > expr = term{{2.0}} * user::number{1.0} * user::number{42.0} + user::number{3.0}; user::number result = expr; EXPECT_EQ(result.value, 87); @@ -124,7 +124,7 @@ TEST(user_expression_transform, test_user_expression_transform) >, term > - > expr = a * x + y; + > expr = term{{1.0}} * user::number{42.0} + user::number{3.0}; user::number result = expr; EXPECT_EQ(result.value, 55); @@ -149,14 +149,17 @@ TEST(user_expression_transform, test_user_expression_transform) > > > - > expr = k * (a * x + y); + > expr = term{{2.0}} * (term{{1.0}} * user::number{42.0} + user::number{3.0}); user::number result = expr; EXPECT_EQ(result.value, 110); } { - auto expr = (a * x + y) * (a * x + y) + (a * x + y); + auto expr = + (term{{1.0}} * user::number{42.0} + user::number{3.0}) * + (term{{1.0}} * user::number{42.0} + user::number{3.0}) + + (term{{1.0}} * user::number{42.0} + user::number{3.0}); user::number result = expr; diff --git a/test/user_expression_transform_3.cpp b/test/user_expression_transform_3.cpp index 8161242..fbd1666 100644 --- a/test/user_expression_transform_3.cpp +++ b/test/user_expression_transform_3.cpp @@ -1,5 +1,7 @@ #include "expression.hpp" +#include "print.hpp" + #include @@ -49,11 +51,11 @@ namespace user { bp17::expression< bp17::expr_kind::multiplies, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > >, - term + bp17::expression_ref &> > > const & expr ) { @@ -70,17 +72,17 @@ namespace user { bp17::expression< bp17::expr_kind::multiplies, bh::tuple< - term, - term + bp17::expression_ref &>, + bp17::expression_ref &> > >, - term + bp17::expression_ref &> > > const & expr ) { - auto a = expr.left().left(); - auto x = expr.left().right(); - auto y = expr.right(); + decltype(auto) a = expr.left().left().value(); + decltype(auto) x = expr.left().right().value(); + decltype(auto) y = expr.right().value(); return bp17::make_terminal(naxpy)(a, x, y); } @@ -102,10 +104,11 @@ namespace user { > > const & expr ) { - auto a = transform(expr.left().left(), naxpy_xform{}); - auto x = transform(expr.left().right(), naxpy_xform{}); - auto y = transform(expr.right(), naxpy_xform{}); - return bp17::make_terminal(naxpy)(a, x, y); + return bp17::make_terminal(naxpy)( + transform(expr.left().left(), naxpy_xform{}), + transform(expr.left().right(), naxpy_xform{}), + transform(expr.right(), naxpy_xform{}) + ); } }; @@ -232,7 +235,7 @@ TEST(move_only, test_user_expression_transform_3) bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term> > > expr_1 = unity + std::move(i); @@ -240,11 +243,11 @@ TEST(move_only, test_user_expression_transform_3) bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref &>, term> > > diff --git a/test/user_operator_and_eval_expression_as.cpp b/test/user_operator_and_eval_expression_as.cpp index 62eab21..e2fbedd 100644 --- a/test/user_operator_and_eval_expression_as.cpp +++ b/test/user_operator_and_eval_expression_as.cpp @@ -46,18 +46,18 @@ TEST(user_eval_expression_as, test_user_eval_expression_as) bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref& >, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref& >, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref& >, term > > diff --git a/test/user_operator_eval.cpp b/test/user_operator_eval.cpp index d8a90a9..2057cc7 100644 --- a/test/user_operator_eval.cpp +++ b/test/user_operator_eval.cpp @@ -35,18 +35,18 @@ TEST(user_operator_eval, test_user_operator_eval) bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref& >, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref& >, bp17::expression< bp17::expr_kind::plus, bh::tuple< - term, + bp17::expression_ref& >, term > >