compile_const_term.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. template<typename T>
  8. using term = boost::yap::terminal<boost::yap::expression, T>;
  9. template<typename T>
  10. using ref = boost::yap::expression_ref<boost::yap::expression, T>;
  11. namespace yap = boost::yap;
  12. namespace bh = boost::hana;
  13. void compile_const_term()
  14. {
  15. {
  16. term<double const> unity{1.0};
  17. int i_ = 42;
  18. term<int &&> i{std::move(i_)};
  19. yap::expression<
  20. yap::expr_kind::plus,
  21. bh::tuple<ref<term<double const> &>, term<int &&>>>
  22. expr = unity + std::move(i);
  23. yap::expression<
  24. yap::expr_kind::plus,
  25. bh::tuple<
  26. ref<term<double const> &>,
  27. yap::expression<
  28. yap::expr_kind::plus,
  29. bh::tuple<ref<term<double const> &>, term<int &&>>>>>
  30. unevaluated_expr = unity + std::move(expr);
  31. (void)unevaluated_expr;
  32. }
  33. {
  34. term<double> const unity{1.0};
  35. int i_ = 42;
  36. term<int &&> i{std::move(i_)};
  37. yap::expression<
  38. yap::expr_kind::plus,
  39. bh::tuple<ref<term<double> const &>, term<int &&>>>
  40. expr = unity + std::move(i);
  41. yap::expression<
  42. yap::expr_kind::plus,
  43. bh::tuple<
  44. ref<term<double> const &>,
  45. yap::expression<
  46. yap::expr_kind::plus,
  47. bh::tuple<ref<term<double> const &>, term<int &&>>>>>
  48. unevaluated_expr = unity + std::move(expr);
  49. (void)unevaluated_expr;
  50. }
  51. {
  52. term<double> unity{1.0};
  53. int i_ = 42;
  54. term<int const &> i{i_};
  55. yap::expression<
  56. yap::expr_kind::plus,
  57. bh::tuple<ref<term<double> &>, term<int const &>>> const expr =
  58. unity + std::move(i);
  59. yap::expression<
  60. yap::expr_kind::plus,
  61. bh::tuple<
  62. ref<term<double> &>,
  63. yap::expression<
  64. yap::expr_kind::plus,
  65. bh::tuple<ref<term<double> &>, term<int const &>>>>>
  66. unevaluated_expr = unity + std::move(expr);
  67. (void)unevaluated_expr;
  68. }
  69. }