left.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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 <boost/mpl/assert.hpp>
  8. #include <boost/test/minimal.hpp>
  9. template<typename T>
  10. using term = boost::yap::terminal<boost::yap::expression, T>;
  11. template<typename T>
  12. using ref = boost::yap::expression_ref<boost::yap::expression, T>;
  13. namespace yap = boost::yap;
  14. namespace bh = boost::hana;
  15. template<boost::yap::expr_kind Kind, typename Tuple>
  16. struct user_expr
  17. {
  18. static boost::yap::expr_kind const kind = Kind;
  19. Tuple elements;
  20. };
  21. BOOST_YAP_USER_BINARY_OPERATOR(plus, user_expr, user_expr)
  22. template<typename T>
  23. using user_term = boost::yap::terminal<user_expr, T>;
  24. template<typename T>
  25. using user_ref = boost::yap::expression_ref<user_expr, T>;
  26. int test_main(int, char * [])
  27. {
  28. {
  29. term<double> unity = {{1.0}};
  30. using plus_expr_type = yap::expression<
  31. yap::expr_kind::plus,
  32. bh::tuple<ref<term<double> &>, term<int>>>;
  33. {
  34. plus_expr_type plus_expr = unity + term<int>{{1}};
  35. BOOST_MPL_ASSERT((std::is_same<
  36. decltype(yap::left(std::move(plus_expr))),
  37. ref<term<double> &> &&>));
  38. }
  39. {
  40. plus_expr_type plus_expr = unity + term<int>{{1}};
  41. BOOST_MPL_ASSERT((std::is_same<
  42. decltype(yap::left(plus_expr)),
  43. ref<term<double> &> &>));
  44. }
  45. {
  46. plus_expr_type const plus_expr = unity + term<int>{{1}};
  47. BOOST_MPL_ASSERT((std::is_same<
  48. decltype(yap::left(plus_expr)),
  49. ref<term<double> &> const &>));
  50. }
  51. {
  52. term<double> const unity = {{1.0}};
  53. using plus_expr_type = yap::expression<
  54. yap::expr_kind::plus,
  55. bh::tuple<ref<term<double> const &>, term<int>>>;
  56. {
  57. plus_expr_type plus_expr = unity + term<int>{{1}};
  58. BOOST_MPL_ASSERT((std::is_same<
  59. decltype(yap::left(std::move(plus_expr))),
  60. ref<term<double> const &> &&>));
  61. }
  62. {
  63. plus_expr_type plus_expr = unity + term<int>{{1}};
  64. BOOST_MPL_ASSERT((std::is_same<
  65. decltype(yap::left(plus_expr)),
  66. ref<term<double> const &> &>));
  67. }
  68. {
  69. plus_expr_type const plus_expr = unity + term<int>{{1}};
  70. BOOST_MPL_ASSERT((std::is_same<
  71. decltype(yap::left(plus_expr)),
  72. ref<term<double> const &> const &>));
  73. }
  74. }
  75. {
  76. term<double> unity = {{1.0}};
  77. using plus_expr_type = yap::expression<
  78. yap::expr_kind::plus,
  79. bh::tuple<ref<term<double> &>, term<int>>>;
  80. plus_expr_type plus_expr = unity + term<int>{{1}};
  81. using plus_plus_expr_type = yap::expression<
  82. yap::expr_kind::plus,
  83. bh::tuple<ref<plus_expr_type &>, term<int>>>;
  84. {
  85. plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
  86. ref<plus_expr_type &> plus_expr_ref =
  87. bh::front(plus_plus_expr.elements);
  88. BOOST_MPL_ASSERT((std::is_same<
  89. decltype(yap::left(std::move(plus_expr_ref))),
  90. ref<term<double> &> &>));
  91. }
  92. {
  93. plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
  94. ref<plus_expr_type &> plus_expr_ref =
  95. bh::front(plus_plus_expr.elements);
  96. BOOST_MPL_ASSERT((std::is_same<
  97. decltype(yap::left(plus_expr_ref)),
  98. ref<term<double> &> &>));
  99. }
  100. {
  101. plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
  102. ref<plus_expr_type &> const plus_expr_ref =
  103. bh::front(plus_plus_expr.elements);
  104. BOOST_MPL_ASSERT((std::is_same<
  105. decltype(yap::left(plus_expr_ref)),
  106. ref<term<double> &> &>));
  107. }
  108. }
  109. {
  110. term<double> unity = {{1.0}};
  111. using plus_expr_type = yap::expression<
  112. yap::expr_kind::plus,
  113. bh::tuple<ref<term<double> &>, term<int>>>;
  114. plus_expr_type const plus_expr = unity + term<int>{{1}};
  115. using plus_plus_expr_type = yap::expression<
  116. yap::expr_kind::plus,
  117. bh::tuple<ref<plus_expr_type const &>, term<int>>>;
  118. {
  119. plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
  120. ref<plus_expr_type const &> plus_expr_ref =
  121. bh::front(plus_plus_expr.elements);
  122. BOOST_MPL_ASSERT((std::is_same<
  123. decltype(yap::left(std::move(plus_expr_ref))),
  124. ref<term<double> &> const &>));
  125. }
  126. {
  127. plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
  128. ref<plus_expr_type const &> plus_expr_ref =
  129. bh::front(plus_plus_expr.elements);
  130. BOOST_MPL_ASSERT((std::is_same<
  131. decltype(yap::left(plus_expr_ref)),
  132. ref<term<double> &> const &>));
  133. }
  134. {
  135. plus_plus_expr_type plus_plus_expr = plus_expr + term<int>{{1}};
  136. ref<plus_expr_type const &> const plus_expr_ref =
  137. bh::front(plus_plus_expr.elements);
  138. BOOST_MPL_ASSERT((std::is_same<
  139. decltype(yap::left(plus_expr_ref)),
  140. ref<term<double> &> const &>));
  141. }
  142. }
  143. }
  144. {
  145. user_term<double> unity = {{1.0}};
  146. using plus_expr_type = user_expr<
  147. yap::expr_kind::plus,
  148. bh::tuple<user_ref<user_term<double> &>, user_term<int>>>;
  149. {
  150. plus_expr_type plus_expr = unity + user_term<int>{{1}};
  151. BOOST_MPL_ASSERT((std::is_same<
  152. decltype(yap::left(std::move(plus_expr))),
  153. user_ref<user_term<double> &> &&>));
  154. }
  155. {
  156. plus_expr_type plus_expr = unity + user_term<int>{{1}};
  157. BOOST_MPL_ASSERT((std::is_same<
  158. decltype(yap::left(plus_expr)),
  159. user_ref<user_term<double> &> &>));
  160. }
  161. {
  162. plus_expr_type const plus_expr = unity + user_term<int>{{1}};
  163. BOOST_MPL_ASSERT((std::is_same<
  164. decltype(yap::left(plus_expr)),
  165. user_ref<user_term<double> &> const &>));
  166. }
  167. {
  168. user_term<double> const unity = {{1.0}};
  169. using plus_expr_type = user_expr<
  170. yap::expr_kind::plus,
  171. bh::tuple<user_ref<user_term<double> const &>, user_term<int>>>;
  172. {
  173. plus_expr_type plus_expr = unity + user_term<int>{{1}};
  174. BOOST_MPL_ASSERT((std::is_same<
  175. decltype(yap::left(std::move(plus_expr))),
  176. user_ref<user_term<double> const &> &&>));
  177. }
  178. {
  179. plus_expr_type plus_expr = unity + user_term<int>{{1}};
  180. BOOST_MPL_ASSERT((std::is_same<
  181. decltype(yap::left(plus_expr)),
  182. user_ref<user_term<double> const &> &>));
  183. }
  184. {
  185. plus_expr_type const plus_expr = unity + user_term<int>{{1}};
  186. BOOST_MPL_ASSERT(
  187. (std::is_same<
  188. decltype(yap::left(plus_expr)),
  189. user_ref<user_term<double> const &> const &>));
  190. }
  191. }
  192. {
  193. user_term<double> unity = {{1.0}};
  194. using plus_expr_type = user_expr<
  195. yap::expr_kind::plus,
  196. bh::tuple<user_ref<user_term<double> &>, user_term<int>>>;
  197. plus_expr_type plus_expr = unity + user_term<int>{{1}};
  198. using plus_plus_expr_type = user_expr<
  199. yap::expr_kind::plus,
  200. bh::tuple<user_ref<plus_expr_type &>, user_term<int>>>;
  201. {
  202. plus_plus_expr_type plus_plus_expr =
  203. plus_expr + user_term<int>{{1}};
  204. user_ref<plus_expr_type &> plus_expr_ref =
  205. bh::front(plus_plus_expr.elements);
  206. BOOST_MPL_ASSERT((std::is_same<
  207. decltype(yap::left(std::move(plus_expr_ref))),
  208. user_ref<user_term<double> &> &>));
  209. }
  210. {
  211. plus_plus_expr_type plus_plus_expr =
  212. plus_expr + user_term<int>{{1}};
  213. user_ref<plus_expr_type &> plus_expr_ref =
  214. bh::front(plus_plus_expr.elements);
  215. BOOST_MPL_ASSERT((std::is_same<
  216. decltype(yap::left(plus_expr_ref)),
  217. user_ref<user_term<double> &> &>));
  218. }
  219. {
  220. plus_plus_expr_type plus_plus_expr =
  221. plus_expr + user_term<int>{{1}};
  222. user_ref<plus_expr_type &> const plus_expr_ref =
  223. bh::front(plus_plus_expr.elements);
  224. BOOST_MPL_ASSERT((std::is_same<
  225. decltype(yap::left(plus_expr_ref)),
  226. user_ref<user_term<double> &> &>));
  227. }
  228. }
  229. {
  230. user_term<double> unity = {{1.0}};
  231. using plus_expr_type = user_expr<
  232. yap::expr_kind::plus,
  233. bh::tuple<user_ref<user_term<double> &>, user_term<int>>>;
  234. plus_expr_type const plus_expr = unity + user_term<int>{{1}};
  235. using plus_plus_expr_type = user_expr<
  236. yap::expr_kind::plus,
  237. bh::tuple<user_ref<plus_expr_type const &>, user_term<int>>>;
  238. {
  239. plus_plus_expr_type plus_plus_expr =
  240. plus_expr + user_term<int>{{1}};
  241. user_ref<plus_expr_type const &> plus_expr_ref =
  242. bh::front(plus_plus_expr.elements);
  243. BOOST_MPL_ASSERT((std::is_same<
  244. decltype(yap::left(std::move(plus_expr_ref))),
  245. user_ref<user_term<double> &> const &>));
  246. }
  247. {
  248. plus_plus_expr_type plus_plus_expr =
  249. plus_expr + user_term<int>{{1}};
  250. user_ref<plus_expr_type const &> plus_expr_ref =
  251. bh::front(plus_plus_expr.elements);
  252. BOOST_MPL_ASSERT((std::is_same<
  253. decltype(yap::left(plus_expr_ref)),
  254. user_ref<user_term<double> &> const &>));
  255. }
  256. {
  257. plus_plus_expr_type plus_plus_expr =
  258. plus_expr + user_term<int>{{1}};
  259. user_ref<plus_expr_type const &> const plus_expr_ref =
  260. bh::front(plus_plus_expr.elements);
  261. BOOST_MPL_ASSERT((std::is_same<
  262. decltype(yap::left(plus_expr_ref)),
  263. user_ref<user_term<double> &> const &>));
  264. }
  265. }
  266. }
  267. return 0;
  268. }