compile_user_macros.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. template<yap::expr_kind Kind, typename Tuple>
  14. struct expr
  15. {
  16. static yap::expr_kind const kind = Kind;
  17. Tuple elements;
  18. BOOST_YAP_USER_ASSIGN_OPERATOR(expr, ::expr);
  19. };
  20. static_assert(yap::detail::copy_or_move<int, int const &>::value, "");
  21. static_assert(yap::detail::copy_or_move<int, int &>::value, "");
  22. static_assert(yap::detail::copy_or_move<int, int &&>::value, "");
  23. static_assert(!yap::detail::copy_or_move<int, int const &&>::value, "");
  24. static_assert(!yap::detail::copy_or_move<int, int>::value, "");
  25. void compile_user_macros()
  26. {
  27. using namespace boost::hana::literals;
  28. expr<yap::expr_kind::negate, bh::tuple<int>> negation1;
  29. negation1.elements[0_c] = 1;
  30. expr<yap::expr_kind::negate, bh::tuple<int>> negation2;
  31. negation2.elements[0_c] = 2;
  32. // Normal-rules assignment.
  33. negation2 = negation1;
  34. assert(negation2.elements[0_c] == 1);
  35. negation2.elements[0_c] = 2;
  36. // Normal-rules move assignment.
  37. negation2 = std::move(negation1);
  38. assert(negation2.elements[0_c] == 1);
  39. // Produce a new expression via BOOST_YAP_USER_ASSIGN_OPERATOR.
  40. auto expr = negation1 = 2;
  41. (void)expr;
  42. }