placeholder_eval.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2016-2018 T. Zachary Laine
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/yap/expression.hpp>
  7. #include <boost/test/minimal.hpp>
  8. #include <sstream>
  9. template<typename T>
  10. using term = boost::yap::terminal<boost::yap::expression, T>;
  11. template<long long I>
  12. using place_term =
  13. boost::yap::terminal<boost::yap::expression, boost::yap::placeholder<I>>;
  14. template<typename T>
  15. using ref = boost::yap::expression_ref<boost::yap::expression, T>;
  16. namespace yap = boost::yap;
  17. namespace bh = boost::hana;
  18. int test_main(int, char * [])
  19. {
  20. {
  21. using namespace boost::yap::literals;
  22. place_term<3> p3 = 3_p;
  23. int i_ = 42;
  24. term<int> i{std::move(i_)};
  25. yap::expression<
  26. yap::expr_kind::plus,
  27. bh::tuple<ref<place_term<3> &>, term<int>>>
  28. expr = p3 + std::move(i);
  29. yap::expression<
  30. yap::expr_kind::plus,
  31. bh::tuple<
  32. ref<place_term<3> &>,
  33. yap::expression<
  34. yap::expr_kind::plus,
  35. bh::tuple<ref<place_term<3> &>, term<int>>>>>
  36. unevaluated_expr = p3 + std::move(expr);
  37. {
  38. double result = evaluate(p3, 5, 6, 7);
  39. BOOST_CHECK(result == 7);
  40. }
  41. {
  42. double result = evaluate(expr, std::string("15"), 3, 1);
  43. BOOST_CHECK(result == 43);
  44. }
  45. {
  46. double result = evaluate(unevaluated_expr, std::string("15"), 2, 3);
  47. BOOST_CHECK(result == 48);
  48. }
  49. }
  50. return 0;
  51. }