compile_placeholders.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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<long long I>
  10. using place_term =
  11. boost::yap::terminal<boost::yap::expression, boost::yap::placeholder<I>>;
  12. template<typename T>
  13. using ref = boost::yap::expression_ref<boost::yap::expression, T>;
  14. namespace yap = boost::yap;
  15. namespace bh = boost::hana;
  16. void compile_placeholders()
  17. {
  18. using namespace boost::yap::literals;
  19. {
  20. place_term<1> p1 = 1_p;
  21. (void)p1;
  22. }
  23. {
  24. place_term<1> p1 = 1_p;
  25. term<double> unity{1.0};
  26. yap::expression<
  27. yap::expr_kind::plus,
  28. bh::tuple<ref<place_term<1> &>, ref<term<double> &>>>
  29. expr = p1 + unity;
  30. (void)expr;
  31. }
  32. {
  33. place_term<1> p1 = 1_p;
  34. yap::expression<
  35. yap::expr_kind::plus,
  36. bh::tuple<ref<place_term<1> &>, place_term<2>>>
  37. expr = p1 + 2_p;
  38. (void)expr;
  39. }
  40. }