evaluate_category.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. #include <boost/parameter/config.hpp>
  6. #if (BOOST_PARAMETER_MAX_ARITY < 4)
  7. #error Define BOOST_PARAMETER_MAX_ARITY as 4 or greater.
  8. #endif
  9. #if !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) && \
  10. (BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY < 5)
  11. #error Define BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \
  12. as 5 or greater.
  13. #endif
  14. #include <boost/parameter/name.hpp>
  15. namespace test {
  16. BOOST_PARAMETER_NAME((_lrc0, keywords) in(lrc0))
  17. BOOST_PARAMETER_NAME((_lr0, keywords) in_out(lr0))
  18. BOOST_PARAMETER_NAME((_rrc0, keywords) in(rrc0))
  19. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  20. BOOST_PARAMETER_NAME((_rr0, keywords) consume(rr0))
  21. #else
  22. BOOST_PARAMETER_NAME((_rr0, keywords) rr0)
  23. #endif
  24. } // namespace test
  25. #include <boost/parameter/parameters.hpp>
  26. #include <boost/parameter/required.hpp>
  27. namespace test {
  28. struct f_parameters
  29. : boost::parameter::parameters<
  30. boost::parameter::required<test::keywords::lrc0>
  31. , boost::parameter::required<test::keywords::lr0>
  32. , boost::parameter::required<test::keywords::rrc0>
  33. , boost::parameter::required<test::keywords::rr0>
  34. >
  35. {
  36. };
  37. } // namespace test
  38. #include <boost/core/lightweight_test.hpp>
  39. #include "evaluate_category.hpp"
  40. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  41. #include <type_traits>
  42. #else
  43. #include <boost/type_traits/is_scalar.hpp>
  44. #endif
  45. namespace test {
  46. template <typename T>
  47. struct B
  48. {
  49. template <typename Args>
  50. static void evaluate(Args const& args)
  51. {
  52. BOOST_TEST_EQ(
  53. test::passed_by_lvalue_reference_to_const
  54. , test::A<T>::evaluate_category(args[test::_lrc0])
  55. );
  56. BOOST_TEST_EQ(
  57. test::passed_by_lvalue_reference
  58. , test::A<T>::evaluate_category(args[test::_lr0])
  59. );
  60. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  61. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  62. if (std::is_scalar<T>::value)
  63. #else
  64. if (boost::is_scalar<T>::value)
  65. #endif
  66. {
  67. BOOST_TEST_EQ(
  68. test::passed_by_lvalue_reference_to_const
  69. , test::A<T>::evaluate_category(args[test::_rrc0])
  70. );
  71. BOOST_TEST_EQ(
  72. test::passed_by_lvalue_reference_to_const
  73. , test::A<T>::evaluate_category(args[test::_rr0])
  74. );
  75. }
  76. else
  77. {
  78. BOOST_TEST_EQ(
  79. test::passed_by_rvalue_reference_to_const
  80. , test::A<T>::evaluate_category(args[test::_rrc0])
  81. );
  82. BOOST_TEST_EQ(
  83. test::passed_by_rvalue_reference
  84. , test::A<T>::evaluate_category(args[test::_rr0])
  85. );
  86. }
  87. #else // !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  88. BOOST_TEST_EQ(
  89. test::passed_by_lvalue_reference_to_const
  90. , test::A<T>::evaluate_category(args[test::_rrc0])
  91. );
  92. BOOST_TEST_EQ(
  93. test::passed_by_lvalue_reference_to_const
  94. , test::A<T>::evaluate_category(args[test::_rr0])
  95. );
  96. #endif // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
  97. }
  98. };
  99. } // namespace test
  100. #include <boost/parameter/deduced.hpp>
  101. #include <boost/mpl/bool.hpp>
  102. #include <boost/mpl/placeholders.hpp>
  103. #include <boost/mpl/if.hpp>
  104. #include <boost/type_traits/is_convertible.hpp>
  105. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  106. #include <boost/mp11/bind.hpp>
  107. #endif
  108. namespace test {
  109. struct e_parameters
  110. : boost::parameter::parameters<
  111. boost::parameter::required<
  112. boost::parameter::deduced<test::keywords::lrc0>
  113. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  114. , boost::mp11::mp_bind<
  115. std::is_convertible
  116. , boost::mp11::_1
  117. , float
  118. >
  119. #else
  120. , boost::mpl::if_<
  121. boost::is_convertible<boost::mpl::_1,float>
  122. , boost::mpl::true_
  123. , boost::mpl::false_
  124. >
  125. #endif
  126. >
  127. , boost::parameter::required<
  128. boost::parameter::deduced<test::keywords::lr0>
  129. , boost::mpl::if_<
  130. boost::is_convertible<boost::mpl::_1,char const*>
  131. , boost::mpl::true_
  132. , boost::mpl::false_
  133. >
  134. >
  135. , boost::parameter::required<
  136. boost::parameter::deduced<test::keywords::rr0>
  137. , test::string_predicate<test::keywords::lr0>
  138. >
  139. >
  140. {
  141. };
  142. } // namespace test
  143. #include <boost/parameter/value_type.hpp>
  144. #if !defined(BOOST_PARAMETER_CAN_USE_MP11)
  145. #include <boost/type_traits/remove_const.hpp>
  146. #endif
  147. namespace test {
  148. struct E
  149. {
  150. template <typename Args>
  151. static void evaluate(Args const& args)
  152. {
  153. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  154. BOOST_TEST((
  155. test::passed_by_lvalue_reference_to_const == test::A<
  156. typename std::remove_const<
  157. typename boost::parameter::value_type<
  158. Args
  159. , test::keywords::lrc0
  160. >::type
  161. >::type
  162. >::evaluate_category(args[test::_lrc0])
  163. ));
  164. BOOST_TEST((
  165. test::passed_by_lvalue_reference == test::A<
  166. typename std::remove_const<
  167. typename boost::parameter::value_type<
  168. Args
  169. , test::keywords::lr0
  170. >::type
  171. >::type
  172. >::evaluate_category(args[test::_lr0])
  173. ));
  174. #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
  175. BOOST_TEST((
  176. test::passed_by_lvalue_reference_to_const == test::A<
  177. typename boost::remove_const<
  178. typename boost::parameter::value_type<
  179. Args
  180. , test::keywords::lrc0
  181. >::type
  182. >::type
  183. >::evaluate_category(args[test::_lrc0])
  184. ));
  185. BOOST_TEST((
  186. test::passed_by_lvalue_reference == test::A<
  187. typename boost::remove_const<
  188. typename boost::parameter::value_type<
  189. Args
  190. , test::keywords::lr0
  191. >::type
  192. >::type
  193. >::evaluate_category(args[test::_lr0])
  194. ));
  195. #endif // BOOST_PARAMETER_CAN_USE_MP11
  196. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  197. BOOST_TEST((
  198. test::passed_by_rvalue_reference == test::A<
  199. typename std::remove_const<
  200. typename boost::parameter::value_type<
  201. Args
  202. , test::keywords::rr0
  203. >::type
  204. >::type
  205. >::evaluate_category(args[test::_rr0])
  206. ));
  207. #elif defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  208. BOOST_TEST((
  209. test::passed_by_rvalue_reference == test::A<
  210. typename boost::remove_const<
  211. typename boost::parameter::value_type<
  212. Args
  213. , test::keywords::rr0
  214. >::type
  215. >::type
  216. >::evaluate_category(args[test::_rr0])
  217. ));
  218. #else // no MP11 or perfect forwarding support
  219. BOOST_TEST((
  220. test::passed_by_lvalue_reference_to_const == test::A<
  221. typename boost::remove_const<
  222. typename boost::parameter::value_type<
  223. Args
  224. , test::keywords::rr0
  225. >::type
  226. >::type
  227. >::evaluate_category(args[test::_rr0])
  228. ));
  229. #endif // MP11 or perfect forwarding support
  230. }
  231. };
  232. } // namespace test
  233. int main()
  234. {
  235. test::B<float>::evaluate(
  236. test::f_parameters()(
  237. test::lvalue_const_float()
  238. , test::lvalue_float()
  239. , test::rvalue_const_float()
  240. , test::rvalue_float()
  241. )
  242. );
  243. test::B<char const*>::evaluate(
  244. test::f_parameters()(
  245. test::lvalue_const_char_ptr()
  246. , test::lvalue_char_ptr()
  247. , test::rvalue_const_char_ptr()
  248. , test::rvalue_char_ptr()
  249. )
  250. );
  251. test::B<std::string>::evaluate(
  252. test::f_parameters()(
  253. test::lvalue_const_str()
  254. , test::lvalue_str()
  255. , test::rvalue_const_str()
  256. , test::rvalue_str()
  257. )
  258. );
  259. test::B<float>::evaluate((
  260. test::_lr0 = test::lvalue_float()
  261. , test::_rrc0 = test::rvalue_const_float()
  262. , test::_rr0 = test::rvalue_float()
  263. , test::_lrc0 = test::lvalue_const_float()
  264. ));
  265. test::B<char const*>::evaluate((
  266. test::_lr0 = test::lvalue_char_ptr()
  267. , test::_rrc0 = test::rvalue_const_char_ptr()
  268. , test::_rr0 = test::rvalue_char_ptr()
  269. , test::_lrc0 = test::lvalue_const_char_ptr()
  270. ));
  271. test::B<std::string>::evaluate((
  272. test::_lr0 = test::lvalue_str()
  273. , test::_rrc0 = test::rvalue_const_str()
  274. , test::_rr0 = test::rvalue_str()
  275. , test::_lrc0 = test::lvalue_const_str()
  276. ));
  277. char baz_arr[4] = "qux";
  278. typedef char char_arr[4];
  279. #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE_VENDOR_SPECIFIC) && \
  280. BOOST_WORKAROUND(BOOST_MSVC, >= 1800)
  281. // MSVC-12+ treats static_cast<char_arr&&>(baz_arr) as an lvalue.
  282. #else
  283. test::B<char_arr>::evaluate(
  284. test::f_parameters()(
  285. "crg"
  286. , baz_arr
  287. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  288. , static_cast<char_arr const&&>("uir")
  289. , static_cast<char_arr&&>(baz_arr)
  290. #else
  291. , "grl"
  292. , "grp"
  293. #endif
  294. )
  295. );
  296. test::B<char_arr>::evaluate((
  297. test::_lr0 = baz_arr
  298. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  299. , test::_rrc0 = static_cast<char_arr const&&>("wld")
  300. , test::_rr0 = static_cast<char_arr&&>(baz_arr)
  301. #else
  302. , test::_rrc0 = "frd"
  303. , test::_rr0 = "plg"
  304. #endif
  305. , test::_lrc0 = "mos"
  306. ));
  307. #endif // MSVC-12+
  308. test::E::evaluate(
  309. test::e_parameters()(
  310. test::lvalue_char_ptr()
  311. , test::rvalue_str()
  312. , test::lvalue_const_float()
  313. )
  314. );
  315. test::E::evaluate(
  316. test::e_parameters()(
  317. test::rvalue_str()
  318. , test::lvalue_const_float()
  319. , test::lvalue_char_ptr()
  320. )
  321. );
  322. return boost::report_errors();
  323. }