compile_term_plus_term.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 <string>
  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. void compile_term_plus_term()
  15. {
  16. using namespace std::literals;
  17. // char const * string
  18. {
  19. term<double> unity{1.0};
  20. yap::expression<
  21. yap::expr_kind::plus,
  22. bh::tuple<ref<term<double> &>, term<char const *>>>
  23. unevaluated_expr = unity + term<char const *>{"3"};
  24. (void)unevaluated_expr;
  25. }
  26. // std::string temporary
  27. {
  28. term<double> unity{1.0};
  29. yap::expression<
  30. yap::expr_kind::plus,
  31. bh::tuple<ref<term<double> &>, term<std::string>>>
  32. unevaluated_expr = unity + term<std::string>{"3"s};
  33. (void)unevaluated_expr;
  34. }
  35. // pointers
  36. {
  37. term<double> unity{1.0};
  38. int ints_[] = {1, 2};
  39. term<int *> ints = {ints_};
  40. yap::expression<
  41. yap::expr_kind::plus,
  42. bh::tuple<ref<term<double> &>, ref<term<int *> &>>>
  43. unevaluated_expr = unity + ints;
  44. (void)unevaluated_expr;
  45. }
  46. {
  47. term<double> unity{1.0};
  48. int const ints_[] = {1, 2};
  49. term<int const *> ints = {ints_};
  50. yap::expression<
  51. yap::expr_kind::plus,
  52. bh::tuple<ref<term<double> &>, ref<term<int const *> &>>>
  53. unevaluated_expr = unity + ints;
  54. (void)unevaluated_expr;
  55. }
  56. {
  57. term<double> unity{1.0};
  58. int ints_[] = {1, 2};
  59. term<int *> ints = {ints_};
  60. yap::expression<
  61. yap::expr_kind::plus,
  62. bh::tuple<ref<term<double> &>, term<int *>>>
  63. unevaluated_expr = unity + std::move(ints);
  64. (void)unevaluated_expr;
  65. }
  66. // const pointers
  67. {
  68. term<double> unity{1.0};
  69. int ints[] = {1, 2};
  70. term<int * const> int_ptr = {ints};
  71. yap::expression<
  72. yap::expr_kind::plus,
  73. bh::tuple<ref<term<double> &>, ref<term<int * const> &>>>
  74. unevaluated_expr = unity + int_ptr;
  75. (void)unevaluated_expr;
  76. }
  77. {
  78. term<double> unity{1.0};
  79. int const ints[] = {1, 2};
  80. term<int const * const> int_ptr = {ints};
  81. yap::expression<
  82. yap::expr_kind::plus,
  83. bh::tuple<ref<term<double> &>, ref<term<int const * const> &>>>
  84. unevaluated_expr = unity + int_ptr;
  85. (void)unevaluated_expr;
  86. }
  87. {
  88. term<double> unity{1.0};
  89. int ints[] = {1, 2};
  90. term<int * const> int_ptr = {ints};
  91. yap::expression<
  92. yap::expr_kind::plus,
  93. bh::tuple<ref<term<double> &>, term<int * const>>>
  94. unevaluated_expr = unity + std::move(int_ptr);
  95. (void)unevaluated_expr;
  96. }
  97. // values
  98. {
  99. term<double> unity{1.0};
  100. term<int> i = {1};
  101. yap::expression<
  102. yap::expr_kind::plus,
  103. bh::tuple<ref<term<double> &>, ref<term<int> &>>>
  104. unevaluated_expr = unity + i;
  105. (void)unevaluated_expr;
  106. }
  107. {
  108. term<double> unity{1.0};
  109. term<int const> i = {1};
  110. yap::expression<
  111. yap::expr_kind::plus,
  112. bh::tuple<ref<term<double> &>, ref<term<int const> &>>>
  113. unevaluated_expr = unity + i;
  114. (void)unevaluated_expr;
  115. }
  116. {
  117. term<double> unity{1.0};
  118. term<int> i = {1};
  119. yap::expression<
  120. yap::expr_kind::plus,
  121. bh::tuple<ref<term<double> &>, term<int>>>
  122. unevaluated_expr = unity + std::move(i);
  123. (void)unevaluated_expr;
  124. }
  125. // const value terminals
  126. {
  127. term<double> unity{1.0};
  128. term<int> const i = {1};
  129. yap::expression<
  130. yap::expr_kind::plus,
  131. bh::tuple<ref<term<double> &>, ref<term<int> const &>>>
  132. unevaluated_expr = unity + i;
  133. (void)unevaluated_expr;
  134. }
  135. {
  136. term<double> unity{1.0};
  137. term<int const> const i = {1};
  138. yap::expression<
  139. yap::expr_kind::plus,
  140. bh::tuple<ref<term<double> &>, ref<term<int const> const &>>>
  141. unevaluated_expr = unity + i;
  142. (void)unevaluated_expr;
  143. }
  144. // lvalue refs
  145. {
  146. term<double> unity{1.0};
  147. int i_ = 1;
  148. term<int &> i{i_};
  149. yap::expression<
  150. yap::expr_kind::plus,
  151. bh::tuple<ref<term<double> &>, ref<term<int &> &>>>
  152. unevaluated_expr = unity + i;
  153. (void)unevaluated_expr;
  154. }
  155. {
  156. term<double> unity{1.0};
  157. int i_ = 1;
  158. term<int const &> i{i_};
  159. yap::expression<
  160. yap::expr_kind::plus,
  161. bh::tuple<ref<term<double> &>, ref<term<int const &> &>>>
  162. unevaluated_expr = unity + i;
  163. (void)unevaluated_expr;
  164. }
  165. {
  166. term<double> unity{1.0};
  167. int i_ = 1;
  168. term<int &> i{i_};
  169. yap::expression<
  170. yap::expr_kind::plus,
  171. bh::tuple<ref<term<double> &>, term<int &>>>
  172. unevaluated_expr = unity + std::move(i);
  173. (void)unevaluated_expr;
  174. }
  175. // rvalue refs
  176. {
  177. term<double> unity{1.0};
  178. int i_ = 1;
  179. term<int &&> i{std::move(i_)};
  180. yap::expression<
  181. yap::expr_kind::plus,
  182. bh::tuple<ref<term<double> &>, term<int &&>>>
  183. unevaluated_expr = unity + std::move(i);
  184. (void)unevaluated_expr;
  185. }
  186. {
  187. term<double> unity{1.0};
  188. int i_ = 1;
  189. term<int &&> i{std::move(i_)};
  190. yap::expression<
  191. yap::expr_kind::plus,
  192. bh::tuple<ref<term<double> &>, term<int &&>>>
  193. unevaluated_expr = unity + std::move(i);
  194. (void)unevaluated_expr;
  195. }
  196. }