compile_move_only_types.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 <memory>
  8. template<typename T>
  9. using term = boost::yap::terminal<boost::yap::expression, T>;
  10. template<typename T>
  11. using ref = boost::yap::expression_ref<boost::yap::expression, T>;
  12. namespace yap = boost::yap;
  13. namespace bh = boost::hana;
  14. inline auto double_to_float(term<double> expr)
  15. {
  16. return term<float>{(float)expr.value()};
  17. }
  18. void compile_move_only_types()
  19. {
  20. term<double> unity{1.0};
  21. term<std::unique_ptr<int>> i{new int{7}};
  22. yap::expression<
  23. yap::expr_kind::plus,
  24. bh::tuple<ref<term<double> &>, term<std::unique_ptr<int>>>>
  25. expr_1 = unity + std::move(i);
  26. yap::expression<
  27. yap::expr_kind::plus,
  28. bh::tuple<
  29. ref<term<double> &>,
  30. yap::expression<
  31. yap::expr_kind::plus,
  32. bh::tuple<ref<term<double> &>, term<std::unique_ptr<int>>>>>>
  33. expr_2 = unity + std::move(expr_1);
  34. auto transformed_expr = transform(std::move(expr_2), double_to_float);
  35. (void)transformed_expr;
  36. }