preprocessor_eval_cat_no_spec.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. // Copyright Cromwell D. Enage 2018.
  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 !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) && \
  7. (BOOST_PARAMETER_COMPOSE_MAX_ARITY < 8)
  8. #error Define BOOST_PARAMETER_COMPOSE_MAX_ARITY as 8 or greater.
  9. #endif
  10. #include <boost/parameter/name.hpp>
  11. namespace test {
  12. BOOST_PARAMETER_NAME((_lrc0, kw0) in(lrc0))
  13. BOOST_PARAMETER_NAME((_lr0, kw1) in_out(lr0))
  14. BOOST_PARAMETER_NAME((_rrc0, kw2) in(rrc0))
  15. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  16. BOOST_PARAMETER_NAME((_rr0, kw3) consume(rr0))
  17. #else
  18. BOOST_PARAMETER_NAME((_rr0, kw3) rr0)
  19. #endif
  20. BOOST_PARAMETER_NAME((_lrc1, kw4) in(lrc1))
  21. BOOST_PARAMETER_NAME((_lr1, kw5) out(lr1))
  22. BOOST_PARAMETER_NAME((_rrc1, kw6) in(rrc1))
  23. BOOST_PARAMETER_NAME((_rr1, kw7) rr1)
  24. } // namespace test
  25. #include <boost/parameter/preprocessor_no_spec.hpp>
  26. #include <boost/parameter/value_type.hpp>
  27. #include <boost/core/lightweight_test.hpp>
  28. #include <boost/type_traits/is_scalar.hpp>
  29. #include <boost/type_traits/remove_const.hpp>
  30. #include "evaluate_category.hpp"
  31. namespace test {
  32. BOOST_PARAMETER_NO_SPEC_FUNCTION((bool), evaluate)
  33. {
  34. BOOST_TEST((
  35. test::passed_by_lvalue_reference_to_const == test::A<
  36. typename boost::remove_const<
  37. typename boost::parameter::value_type<
  38. Args
  39. , test::kw0::lrc0
  40. >::type
  41. >::type
  42. >::evaluate_category(args[test::_lrc0])
  43. ));
  44. BOOST_TEST((
  45. test::passed_by_lvalue_reference == test::A<
  46. typename boost::remove_const<
  47. typename boost::parameter::value_type<
  48. Args
  49. , test::kw1::lr0
  50. >::type
  51. >::type
  52. >::evaluate_category(args[test::_lr0])
  53. ));
  54. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  55. if (
  56. boost::is_scalar<
  57. typename boost::remove_const<
  58. typename boost::parameter::value_type<
  59. Args
  60. , test::kw2::rrc0
  61. >::type
  62. >::type
  63. >::value
  64. )
  65. {
  66. BOOST_TEST((
  67. test::passed_by_lvalue_reference_to_const == test::A<
  68. typename boost::remove_const<
  69. typename boost::parameter::value_type<
  70. Args
  71. , test::kw2::rrc0
  72. >::type
  73. >::type
  74. >::evaluate_category(args[test::_rrc0])
  75. ));
  76. BOOST_TEST((
  77. test::passed_by_lvalue_reference_to_const == test::A<
  78. typename boost::remove_const<
  79. typename boost::parameter::value_type<
  80. Args
  81. , test::kw3::rr0
  82. >::type
  83. >::type
  84. >::evaluate_category(args[test::_rr0])
  85. ));
  86. }
  87. else // rrc0's value type isn't scalar
  88. {
  89. BOOST_TEST((
  90. test::passed_by_rvalue_reference_to_const == test::A<
  91. typename boost::remove_const<
  92. typename boost::parameter::value_type<
  93. Args
  94. , test::kw2::rrc0
  95. >::type
  96. >::type
  97. >::evaluate_category(args[test::_rrc0])
  98. ));
  99. BOOST_TEST((
  100. test::passed_by_rvalue_reference == test::A<
  101. typename boost::remove_const<
  102. typename boost::parameter::value_type<
  103. Args
  104. , test::kw3::rr0
  105. >::type
  106. >::type
  107. >::evaluate_category(args[test::_rr0])
  108. ));
  109. }
  110. #else // !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  111. BOOST_TEST((
  112. test::passed_by_lvalue_reference_to_const == test::A<
  113. typename boost::remove_const<
  114. typename boost::parameter::value_type<
  115. Args
  116. , test::kw2::rrc0
  117. >::type
  118. >::type
  119. >::evaluate_category(args[test::_rrc0])
  120. ));
  121. BOOST_TEST((
  122. test::passed_by_lvalue_reference_to_const == test::A<
  123. typename boost::remove_const<
  124. typename boost::parameter::value_type<
  125. Args
  126. , test::kw3::rr0
  127. >::type
  128. >::type
  129. >::evaluate_category(args[test::_rr0])
  130. ));
  131. #endif // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
  132. return true;
  133. }
  134. } // namespace test
  135. #include <boost/mpl/bool.hpp>
  136. #include <boost/mpl/if.hpp>
  137. #if !defined(BOOST_NO_SFINAE)
  138. #include <boost/parameter/aux_/preprocessor/nullptr.hpp>
  139. #include <boost/core/enable_if.hpp>
  140. #include <boost/type_traits/is_base_of.hpp>
  141. #endif
  142. namespace test {
  143. char const* baz = "baz";
  144. struct B
  145. {
  146. #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE_VENDOR_SPECIFIC) && \
  147. BOOST_WORKAROUND(BOOST_MSVC, >= 1800)
  148. B()
  149. {
  150. }
  151. #endif
  152. template <typename Args>
  153. explicit B(
  154. Args const& args
  155. #if !defined(BOOST_NO_SFINAE)
  156. , typename boost::disable_if<
  157. typename boost::mpl::if_<
  158. boost::is_base_of<B,Args>
  159. , boost::mpl::true_
  160. , boost::mpl::false_
  161. >::type
  162. >::type* = BOOST_PARAMETER_AUX_PP_NULLPTR
  163. #endif // BOOST_NO_SFINAE
  164. )
  165. {
  166. test::evaluate(
  167. test::_lrc0 = args[test::_lrc0]
  168. , test::_lr0 = args[test::_lr0]
  169. , test::_rrc0 = args[test::_rrc0]
  170. , test::_rr0 = args[test::_rr0]
  171. );
  172. }
  173. BOOST_PARAMETER_NO_SPEC_MEMBER_FUNCTION((bool), static evaluate)
  174. {
  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::kw0::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::kw1::lr0
  191. , char const*
  192. >::type
  193. >::type
  194. >::evaluate_category(args[test::_lr0 | test::baz])
  195. ));
  196. BOOST_TEST((
  197. test::passed_by_lvalue_reference_to_const == test::A<
  198. typename boost::remove_const<
  199. typename boost::parameter::value_type<
  200. Args
  201. , test::kw2::rrc0
  202. , float
  203. >::type
  204. >::type
  205. >::evaluate_category(args[test::_rrc0 | 0.0f])
  206. ));
  207. #if 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::kw3::rr0
  214. , std::string
  215. >::type
  216. >::type
  217. >::evaluate_category(
  218. args[
  219. test::_rr0 | std::string(args[test::_lr0 | test::baz])
  220. ]
  221. )
  222. ));
  223. #else // !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  224. BOOST_TEST((
  225. test::passed_by_lvalue_reference_to_const == test::A<
  226. typename boost::remove_const<
  227. typename boost::parameter::value_type<
  228. Args
  229. , test::kw3::rr0
  230. , std::string
  231. >::type
  232. >::type
  233. >::evaluate_category(
  234. args[
  235. test::_rr0 | std::string(args[test::_lr0 | test::baz])
  236. ]
  237. )
  238. ));
  239. #endif // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
  240. return true;
  241. }
  242. };
  243. struct C : B
  244. {
  245. #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE_VENDOR_SPECIFIC) && \
  246. BOOST_WORKAROUND(BOOST_MSVC, >= 1800)
  247. C() : B()
  248. {
  249. }
  250. #endif
  251. BOOST_PARAMETER_NO_SPEC_CONSTRUCTOR(C, (B))
  252. };
  253. struct D
  254. {
  255. BOOST_PARAMETER_NO_SPEC_NO_BASE_CONSTRUCTOR(D, D::_evaluate)
  256. BOOST_PARAMETER_NO_SPEC_CONST_MEMBER_FUNCTION((bool), evaluate_m)
  257. {
  258. return D::_evaluate(args);
  259. }
  260. BOOST_PARAMETER_NO_SPEC_CONST_FUNCTION_CALL_OPERATOR((bool))
  261. {
  262. return D::_evaluate(args);
  263. }
  264. private:
  265. template <typename Args>
  266. static bool _evaluate(Args const& args)
  267. {
  268. BOOST_TEST_EQ(
  269. test::passed_by_lvalue_reference_to_const
  270. , test::U::evaluate_category<0>(args[test::_lrc0])
  271. );
  272. BOOST_TEST_EQ(
  273. test::passed_by_lvalue_reference
  274. , test::U::evaluate_category<1>(args[test::_lr0])
  275. );
  276. BOOST_TEST_EQ(
  277. test::passed_by_lvalue_reference_to_const
  278. , test::U::evaluate_category<4>(args[test::_lrc1])
  279. );
  280. BOOST_TEST_EQ(
  281. test::passed_by_lvalue_reference
  282. , test::U::evaluate_category<5>(
  283. args[test::_lr1 | test::lvalue_bitset<5>()]
  284. )
  285. );
  286. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  287. BOOST_TEST_EQ(
  288. test::passed_by_rvalue_reference_to_const
  289. , test::U::evaluate_category<2>(args[test::_rrc0])
  290. );
  291. BOOST_TEST_EQ(
  292. test::passed_by_rvalue_reference
  293. , test::U::evaluate_category<3>(args[test::_rr0])
  294. );
  295. BOOST_TEST_EQ(
  296. test::passed_by_rvalue_reference_to_const
  297. , test::U::evaluate_category<6>(
  298. args[test::_rrc1 | test::rvalue_const_bitset<6>()]
  299. )
  300. );
  301. BOOST_TEST_EQ(
  302. test::passed_by_rvalue_reference
  303. , test::U::evaluate_category<7>(
  304. args[test::_rr1 | test::rvalue_bitset<7>()]
  305. )
  306. );
  307. #else // !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  308. BOOST_TEST_EQ(
  309. test::passed_by_lvalue_reference_to_const
  310. , test::U::evaluate_category<2>(args[test::_rrc0])
  311. );
  312. BOOST_TEST_EQ(
  313. test::passed_by_lvalue_reference_to_const
  314. , test::U::evaluate_category<3>(args[test::_rr0])
  315. );
  316. BOOST_TEST_EQ(
  317. test::passed_by_lvalue_reference_to_const
  318. , test::U::evaluate_category<6>(
  319. args[test::_rrc1 | test::rvalue_const_bitset<6>()]
  320. )
  321. );
  322. BOOST_TEST_EQ(
  323. test::passed_by_lvalue_reference_to_const
  324. , test::U::evaluate_category<7>(
  325. args[test::_rr1 | test::rvalue_bitset<7>()]
  326. )
  327. );
  328. #endif // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
  329. return true;
  330. }
  331. };
  332. } // namespace test
  333. int main()
  334. {
  335. test::evaluate(
  336. test::_lr0 = test::lvalue_float()
  337. , test::_rrc0 = test::rvalue_const_float()
  338. , test::_rr0 = test::rvalue_float()
  339. , test::_lrc0 = test::lvalue_const_float()
  340. );
  341. test::evaluate(
  342. test::_lr0 = test::lvalue_char_ptr()
  343. , test::_rrc0 = test::rvalue_const_char_ptr()
  344. , test::_rr0 = test::rvalue_char_ptr()
  345. , test::_lrc0 = test::lvalue_const_char_ptr()
  346. );
  347. test::evaluate(
  348. test::_lr0 = test::lvalue_str()
  349. , test::_rrc0 = test::rvalue_const_str()
  350. , test::_rr0 = test::rvalue_str()
  351. , test::_lrc0 = test::lvalue_const_str()
  352. );
  353. test::C cf1(
  354. test::_lr0 = test::lvalue_float()
  355. , test::_rrc0 = test::rvalue_const_float()
  356. , test::_rr0 = test::rvalue_float()
  357. , test::_lrc0 = test::lvalue_const_float()
  358. );
  359. test::C cc1(
  360. test::_lr0 = test::lvalue_char_ptr()
  361. , test::_rrc0 = test::rvalue_const_char_ptr()
  362. , test::_rr0 = test::rvalue_char_ptr()
  363. , test::_lrc0 = test::lvalue_const_char_ptr()
  364. );
  365. test::C cs1(
  366. test::_lr0 = test::lvalue_str()
  367. , test::_rrc0 = test::rvalue_const_str()
  368. , test::_rr0 = test::rvalue_str()
  369. , test::_lrc0 = test::lvalue_const_str()
  370. );
  371. char baz_arr[4] = "qux";
  372. typedef char char_arr[4];
  373. #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE_VENDOR_SPECIFIC) && ( \
  374. BOOST_WORKAROUND(BOOST_GCC, < 40000) || \
  375. BOOST_WORKAROUND(BOOST_MSVC, >= 1800) \
  376. )
  377. // MSVC-12+ treats static_cast<char_arr&&>(baz_arr) as an lvalue.
  378. // GCC 3- tries to bind string literals
  379. // to non-const references to char const*.
  380. #else
  381. test::evaluate(
  382. test::_lr0 = baz_arr
  383. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  384. , test::_rrc0 = static_cast<char_arr const&&>("def")
  385. , test::_rr0 = static_cast<char_arr&&>(baz_arr)
  386. #else
  387. , test::_rrc0 = "grl"
  388. , test::_rr0 = "grp"
  389. #endif
  390. , test::_lrc0 = "wld"
  391. );
  392. #endif // MSVC-12+
  393. test::B::evaluate(test::_lrc0 = test::lvalue_const_str()[0]);
  394. test::C::evaluate(
  395. test::_rrc0 = test::rvalue_const_float()
  396. , test::_lrc0 = test::lvalue_const_str()[0]
  397. );
  398. #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE_VENDOR_SPECIFIC) && \
  399. BOOST_WORKAROUND(BOOST_MSVC, >= 1800)
  400. // MSVC-12+ treats static_cast<char_arr&&>(baz_arr) as an lvalue.
  401. test::C cp0;
  402. test::C cp1;
  403. #else
  404. test::C cp0(
  405. test::_lrc0 = "frd"
  406. , test::_lr0 = baz_arr
  407. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  408. , test::_rrc0 = static_cast<char_arr const&&>("dfs")
  409. , test::_rr0 = static_cast<char_arr&&>(baz_arr)
  410. #else
  411. , test::_rrc0 = "plg"
  412. , test::_rr0 = "thd"
  413. #endif
  414. );
  415. test::C cp1(
  416. test::_lr0 = baz_arr
  417. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  418. , test::_rrc0 = static_cast<char_arr const&&>("dgx")
  419. , test::_rr0 = static_cast<char_arr&&>(baz_arr)
  420. #else
  421. , test::_rrc0 = "hnk"
  422. , test::_rr0 = "xzz"
  423. #endif
  424. , test::_lrc0 = "zts"
  425. );
  426. #endif // MSVC-12+
  427. cp0.evaluate(
  428. test::_lrc0 = test::lvalue_const_str()[0]
  429. , test::_lr0 = test::lvalue_char_ptr()
  430. , test::_rr0 = test::rvalue_str()
  431. , test::_rrc0 = test::rvalue_const_float()
  432. );
  433. cp1.evaluate(
  434. test::_lrc0 = test::lvalue_const_str()[0]
  435. , test::_rr0 = test::rvalue_str()
  436. , test::_rrc0 = test::rvalue_const_float()
  437. , test::_lr0 = test::lvalue_char_ptr()
  438. );
  439. test::D dp0(
  440. test::_lrc1 = test::lvalue_const_bitset<4>()
  441. , test::_lrc0 = test::lvalue_const_bitset<0>()
  442. , test::_lr0 = test::lvalue_bitset<1>()
  443. , test::_rrc0 = test::rvalue_const_bitset<2>()
  444. , test::_rr0 = test::rvalue_bitset<3>()
  445. );
  446. test::D dp1(
  447. test::_lrc1 = test::lvalue_const_bitset<4>()
  448. , test::_lrc0 = test::lvalue_const_bitset<0>()
  449. , test::_rrc1 = test::rvalue_const_bitset<6>()
  450. , test::_lr0 = test::lvalue_bitset<1>()
  451. , test::_rrc0 = test::rvalue_const_bitset<2>()
  452. , test::_rr0 = test::rvalue_bitset<3>()
  453. );
  454. dp0.evaluate_m(
  455. test::_lrc1 = test::lvalue_const_bitset<4>()
  456. , test::_lrc0 = test::lvalue_const_bitset<0>()
  457. , test::_rrc1 = test::rvalue_const_bitset<6>()
  458. , test::_lr0 = test::lvalue_bitset<1>()
  459. , test::_rrc0 = test::rvalue_const_bitset<2>()
  460. , test::_rr0 = test::rvalue_bitset<3>()
  461. );
  462. dp1.evaluate_m(
  463. test::_lr0 = test::lvalue_bitset<1>()
  464. , test::_rrc0 = test::rvalue_const_bitset<2>()
  465. , test::_rr0 = test::rvalue_bitset<3>()
  466. , test::_lrc1 = test::lvalue_const_bitset<4>()
  467. , test::_lr1 = test::lvalue_bitset<5>()
  468. , test::_rrc1 = test::rvalue_const_bitset<6>()
  469. , test::_rr1 = test::rvalue_bitset<7>()
  470. , test::_lrc0 = test::lvalue_const_bitset<0>()
  471. );
  472. dp0(
  473. test::_lrc1 = test::lvalue_const_bitset<4>()
  474. , test::_lrc0 = test::lvalue_const_bitset<0>()
  475. , test::_lr0 = test::lvalue_bitset<1>()
  476. , test::_rrc0 = test::rvalue_const_bitset<2>()
  477. , test::_rr0 = test::rvalue_bitset<3>()
  478. );
  479. dp1(
  480. test::_lr0 = test::lvalue_bitset<1>()
  481. , test::_rrc0 = test::rvalue_const_bitset<2>()
  482. , test::_rr0 = test::rvalue_bitset<3>()
  483. , test::_lrc1 = test::lvalue_const_bitset<4>()
  484. , test::_lr1 = test::lvalue_bitset<5>()
  485. , test::_rrc1 = test::rvalue_const_bitset<6>()
  486. , test::_rr1 = test::rvalue_bitset<7>()
  487. , test::_lrc0 = test::lvalue_const_bitset<0>()
  488. );
  489. return boost::report_errors();
  490. }