compile_term_plus_x_this_ref_overloads.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_x_this_ref_overloads()
  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 + "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 + "3"s;
  33. (void)unevaluated_expr;
  34. }
  35. // arrays
  36. {
  37. term<double> unity{1.0};
  38. int ints[] = {1, 2};
  39. yap::expression<
  40. yap::expr_kind::plus,
  41. bh::tuple<ref<term<double> &>, term<int *>>>
  42. unevaluated_expr = unity + ints;
  43. (void)unevaluated_expr;
  44. }
  45. {
  46. term<double> unity{1.0};
  47. int const ints[] = {1, 2};
  48. yap::expression<
  49. yap::expr_kind::plus,
  50. bh::tuple<ref<term<double> &>, term<int const *>>>
  51. unevaluated_expr = unity + ints;
  52. (void)unevaluated_expr;
  53. }
  54. {
  55. term<double> unity{1.0};
  56. int ints[] = {1, 2};
  57. yap::expression<
  58. yap::expr_kind::plus,
  59. bh::tuple<ref<term<double> &>, term<int *>>>
  60. unevaluated_expr = unity + std::move(ints);
  61. (void)unevaluated_expr;
  62. }
  63. // pointers
  64. {
  65. term<double> unity{1.0};
  66. int ints[] = {1, 2};
  67. int * int_ptr = ints;
  68. yap::expression<
  69. yap::expr_kind::plus,
  70. bh::tuple<ref<term<double> &>, term<int *&>>>
  71. unevaluated_expr = unity + int_ptr;
  72. (void)unevaluated_expr;
  73. }
  74. {
  75. term<double> unity{1.0};
  76. int const ints[] = {1, 2};
  77. int const * int_ptr = ints;
  78. yap::expression<
  79. yap::expr_kind::plus,
  80. bh::tuple<ref<term<double> &>, term<int const *&>>>
  81. unevaluated_expr = unity + int_ptr;
  82. (void)unevaluated_expr;
  83. }
  84. {
  85. term<double> unity{1.0};
  86. int ints[] = {1, 2};
  87. int * int_ptr = ints;
  88. yap::expression<
  89. yap::expr_kind::plus,
  90. bh::tuple<ref<term<double> &>, term<int *>>>
  91. unevaluated_expr = unity + std::move(int_ptr);
  92. (void)unevaluated_expr;
  93. }
  94. // const pointers
  95. {
  96. term<double> unity{1.0};
  97. int ints[] = {1, 2};
  98. int * const int_ptr = ints;
  99. yap::expression<
  100. yap::expr_kind::plus,
  101. bh::tuple<ref<term<double> &>, term<int * const &>>>
  102. unevaluated_expr = unity + int_ptr;
  103. (void)unevaluated_expr;
  104. }
  105. {
  106. term<double> unity{1.0};
  107. int const ints[] = {1, 2};
  108. int const * const int_ptr = ints;
  109. yap::expression<
  110. yap::expr_kind::plus,
  111. bh::tuple<ref<term<double> &>, term<int const * const &>>>
  112. unevaluated_expr = unity + int_ptr;
  113. (void)unevaluated_expr;
  114. }
  115. {
  116. term<double> unity{1.0};
  117. int ints[] = {1, 2};
  118. int * const int_ptr = ints;
  119. yap::expression<
  120. yap::expr_kind::plus,
  121. bh::tuple<ref<term<double> &>, term<int * const>>>
  122. unevaluated_expr = unity + std::move(int_ptr);
  123. (void)unevaluated_expr;
  124. }
  125. // values
  126. {
  127. term<double> unity{1.0};
  128. int i = 1;
  129. yap::expression<
  130. yap::expr_kind::plus,
  131. bh::tuple<ref<term<double> &>, term<int &>>>
  132. unevaluated_expr = unity + i;
  133. (void)unevaluated_expr;
  134. }
  135. {
  136. term<double> unity{1.0};
  137. int const i = 1;
  138. yap::expression<
  139. yap::expr_kind::plus,
  140. bh::tuple<ref<term<double> &>, term<int const &>>>
  141. unevaluated_expr = unity + i;
  142. (void)unevaluated_expr;
  143. }
  144. {
  145. term<double> unity{1.0};
  146. int i = 1;
  147. yap::expression<
  148. yap::expr_kind::plus,
  149. bh::tuple<ref<term<double> &>, term<int>>>
  150. unevaluated_expr = unity + std::move(i);
  151. (void)unevaluated_expr;
  152. }
  153. }