evaluate_category.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // Copyright Cromwell D. Enage 2017.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef LIBS_PARAMETER_TEST_EVALUTE_CATEGORY_HPP
  6. #define LIBS_PARAMETER_TEST_EVALUTE_CATEGORY_HPP
  7. namespace test {
  8. enum invoked
  9. {
  10. passed_by_lvalue_reference_to_const
  11. , passed_by_lvalue_reference
  12. , passed_by_rvalue_reference_to_const
  13. , passed_by_rvalue_reference
  14. };
  15. float rvalue_float()
  16. {
  17. return 0.0f;
  18. }
  19. float const rvalue_const_float()
  20. {
  21. return 0.0f;
  22. }
  23. float& lvalue_float()
  24. {
  25. static float lfloat = 0.0f;
  26. return lfloat;
  27. }
  28. float const& lvalue_const_float()
  29. {
  30. static float const clfloat = 0.0f;
  31. return clfloat;
  32. }
  33. char const* rvalue_char_ptr()
  34. {
  35. return "foo";
  36. }
  37. char const* const rvalue_const_char_ptr()
  38. {
  39. return "foo";
  40. }
  41. char const*& lvalue_char_ptr()
  42. {
  43. static char const* larr = "foo";
  44. return larr;
  45. }
  46. char const* const& lvalue_const_char_ptr()
  47. {
  48. static char const* const clarr = "foo";
  49. return clarr;
  50. }
  51. } // namespace test
  52. #include <string>
  53. namespace test {
  54. std::string rvalue_str()
  55. {
  56. return std::string("bar");
  57. }
  58. std::string const rvalue_const_str()
  59. {
  60. return std::string("bar");
  61. }
  62. std::string& lvalue_str()
  63. {
  64. static std::string lstr = std::string("bar");
  65. return lstr;
  66. }
  67. std::string const& lvalue_const_str()
  68. {
  69. static std::string const clstr = std::string("bar");
  70. return clstr;
  71. }
  72. } // namespace test
  73. #include <bitset>
  74. namespace test {
  75. template <std::size_t N>
  76. std::bitset<N + 1> rvalue_bitset()
  77. {
  78. return std::bitset<N + 1>();
  79. }
  80. template <std::size_t N>
  81. std::bitset<N + 1> const rvalue_const_bitset()
  82. {
  83. return std::bitset<N + 1>();
  84. }
  85. template <std::size_t N>
  86. std::bitset<N + 1>& lvalue_bitset()
  87. {
  88. static std::bitset<N + 1> lset = std::bitset<N + 1>();
  89. return lset;
  90. }
  91. template <std::size_t N>
  92. std::bitset<N + 1> const& lvalue_const_bitset()
  93. {
  94. static std::bitset<N + 1> const clset = std::bitset<N + 1>();
  95. return clset;
  96. }
  97. template <std::size_t N>
  98. struct lvalue_bitset_function
  99. {
  100. typedef std::bitset<N + 1>& result_type;
  101. result_type operator()() const
  102. {
  103. return test::lvalue_bitset<N>();
  104. }
  105. };
  106. template <std::size_t N>
  107. struct lvalue_const_bitset_function
  108. {
  109. typedef std::bitset<N + 1> const& result_type;
  110. result_type operator()() const
  111. {
  112. return test::lvalue_const_bitset<N>();
  113. }
  114. };
  115. template <std::size_t N>
  116. struct rvalue_bitset_function
  117. {
  118. typedef std::bitset<N + 1> result_type;
  119. result_type operator()() const
  120. {
  121. return test::rvalue_bitset<N>();
  122. }
  123. };
  124. template <std::size_t N>
  125. struct rvalue_const_bitset_function
  126. {
  127. typedef std::bitset<N + 1> const result_type;
  128. result_type operator()() const
  129. {
  130. return test::rvalue_const_bitset<N>();
  131. }
  132. };
  133. } // namespace test
  134. #include <boost/parameter/config.hpp>
  135. namespace test {
  136. template <typename T>
  137. struct A
  138. {
  139. static test::invoked evaluate_category(T const&)
  140. {
  141. return test::passed_by_lvalue_reference_to_const;
  142. }
  143. static test::invoked evaluate_category(T&)
  144. {
  145. return test::passed_by_lvalue_reference;
  146. }
  147. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  148. static test::invoked evaluate_category(T const&&)
  149. {
  150. return test::passed_by_rvalue_reference_to_const;
  151. }
  152. static test::invoked evaluate_category(T&&)
  153. {
  154. return test::passed_by_rvalue_reference;
  155. }
  156. #endif
  157. };
  158. struct U
  159. {
  160. template <std::size_t N>
  161. static test::invoked evaluate_category(std::bitset<N + 1> const&)
  162. {
  163. return test::passed_by_lvalue_reference_to_const;
  164. }
  165. template <std::size_t N>
  166. static test::invoked evaluate_category(std::bitset<N + 1>&)
  167. {
  168. return test::passed_by_lvalue_reference;
  169. }
  170. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  171. template <std::size_t N>
  172. static test::invoked evaluate_category(std::bitset<N + 1> const&&)
  173. {
  174. return test::passed_by_rvalue_reference_to_const;
  175. }
  176. template <std::size_t N>
  177. static test::invoked evaluate_category(std::bitset<N + 1>&&)
  178. {
  179. return test::passed_by_rvalue_reference;
  180. }
  181. #endif
  182. };
  183. } // namespace test
  184. #include <boost/parameter/value_type.hpp>
  185. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  186. #include <type_traits>
  187. #else
  188. #include <boost/mpl/bool.hpp>
  189. #include <boost/mpl/if.hpp>
  190. #include <boost/type_traits/is_convertible.hpp>
  191. #include <boost/type_traits/remove_const.hpp>
  192. #include <boost/type_traits/remove_pointer.hpp>
  193. #endif
  194. namespace test {
  195. template <typename CharConstPtrParamTag>
  196. struct string_predicate
  197. {
  198. template <typename Arg, typename Args>
  199. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  200. using fn = std::is_convertible<
  201. Arg
  202. , std::basic_string<
  203. typename std::remove_const<
  204. typename std::remove_pointer<
  205. typename boost::parameter::value_type<
  206. Args
  207. , CharConstPtrParamTag
  208. #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
  209. , char const*
  210. #endif
  211. >::type
  212. >::type
  213. >::type
  214. >
  215. >;
  216. #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
  217. struct apply
  218. : boost::mpl::if_<
  219. boost::is_convertible<
  220. Arg
  221. , std::basic_string<
  222. typename boost::remove_const<
  223. typename boost::remove_pointer<
  224. typename boost::parameter::value_type<
  225. Args
  226. , CharConstPtrParamTag
  227. #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE)
  228. , char const*
  229. #endif
  230. >::type
  231. >::type
  232. >::type
  233. >
  234. >
  235. , boost::mpl::true_
  236. , boost::mpl::false_
  237. >
  238. {
  239. };
  240. #endif // BOOST_PARAMETER_CAN_USE_MP11
  241. };
  242. } // namespace test
  243. #endif // include guard