unwrap_cv_reference.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. // Copyright David Abrahams 2005.
  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/aux_/unwrap_cv_reference.hpp>
  6. #include <boost/parameter/config.hpp>
  7. #include <boost/mpl/aux_/test.hpp>
  8. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  9. #include <type_traits>
  10. #else
  11. #include <boost/mpl/bool.hpp>
  12. #include <boost/mpl/if.hpp>
  13. #include <boost/mpl/assert.hpp>
  14. #include <boost/type_traits/is_same.hpp>
  15. #endif
  16. MPL_TEST_CASE()
  17. {
  18. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  19. static_assert(
  20. std::is_same<
  21. boost::parameter::aux::unwrap_cv_reference<int>::type
  22. , int
  23. >::value
  24. , "unwrap_cv_reference<int>::type == int"
  25. );
  26. static_assert(
  27. std::is_same<
  28. boost::parameter::aux::unwrap_cv_reference<int const>::type
  29. , int const
  30. >::value
  31. , "unwrap_cv_reference<int const>::type == int const"
  32. );
  33. static_assert(
  34. std::is_same<
  35. boost::parameter::aux::unwrap_cv_reference<int volatile>::type
  36. , int volatile
  37. >::value
  38. , "unwrap_cv_reference<int volatile>::type == int volatile"
  39. );
  40. static_assert(
  41. std::is_same<
  42. boost::parameter::aux::unwrap_cv_reference<
  43. int const volatile
  44. >::type
  45. , int const volatile
  46. >::value
  47. , "unwrap_cv_reference<int cv>::type == int cv"
  48. );
  49. #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
  50. BOOST_MPL_ASSERT((
  51. boost::mpl::if_<
  52. boost::is_same<
  53. boost::parameter::aux::unwrap_cv_reference<int>::type
  54. , int
  55. >
  56. , boost::mpl::true_
  57. , boost::mpl::false_
  58. >::type
  59. ));
  60. BOOST_MPL_ASSERT((
  61. boost::mpl::if_<
  62. boost::is_same<
  63. boost::parameter::aux::unwrap_cv_reference<int const>::type
  64. , int const
  65. >
  66. , boost::mpl::true_
  67. , boost::mpl::false_
  68. >::type
  69. ));
  70. BOOST_MPL_ASSERT((
  71. boost::mpl::if_<
  72. boost::is_same<
  73. boost::parameter::aux::unwrap_cv_reference<int volatile>::type
  74. , int volatile
  75. >
  76. , boost::mpl::true_
  77. , boost::mpl::false_
  78. >::type
  79. ));
  80. BOOST_MPL_ASSERT((
  81. boost::mpl::if_<
  82. boost::is_same<
  83. boost::parameter::aux::unwrap_cv_reference<
  84. int const volatile
  85. >::type
  86. , int const volatile
  87. >
  88. , boost::mpl::true_
  89. , boost::mpl::false_
  90. >::type
  91. ));
  92. #endif // BOOST_PARAMETER_CAN_USE_MP11
  93. }
  94. namespace test {
  95. struct foo
  96. {
  97. };
  98. } // namespace test
  99. MPL_TEST_CASE()
  100. {
  101. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  102. static_assert(
  103. std::is_same<
  104. boost::parameter::aux::unwrap_cv_reference<test::foo>::type
  105. , test::foo
  106. >::value
  107. , "unwrap_cv_reference<test::foo>::type == test::foo"
  108. );
  109. static_assert(
  110. std::is_same<
  111. boost::parameter::aux::unwrap_cv_reference<test::foo const>::type
  112. , test::foo const
  113. >::value
  114. , "unwrap_cv_reference<test::foo const>::type == test::foo const"
  115. );
  116. static_assert(
  117. std::is_same<
  118. boost::parameter::aux::unwrap_cv_reference<
  119. test::foo volatile
  120. >::type
  121. , test::foo volatile
  122. >::value
  123. , "unwrap_cv_reference<test::foo volatile>::type == test::foo volatile"
  124. );
  125. static_assert(
  126. std::is_same<
  127. boost::parameter::aux::unwrap_cv_reference<
  128. test::foo const volatile
  129. >::type
  130. , test::foo const volatile
  131. >::value
  132. , "unwrap_cv_reference<test::foo cv>::type == test::foo cv"
  133. );
  134. #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
  135. BOOST_MPL_ASSERT((
  136. boost::mpl::if_<
  137. boost::is_same<
  138. boost::parameter::aux::unwrap_cv_reference<test::foo>::type
  139. , test::foo
  140. >
  141. , boost::mpl::true_
  142. , boost::mpl::false_
  143. >::type
  144. ));
  145. BOOST_MPL_ASSERT((
  146. boost::mpl::if_<
  147. boost::is_same<
  148. boost::parameter::aux::unwrap_cv_reference<
  149. test::foo const
  150. >::type
  151. , test::foo const
  152. >
  153. , boost::mpl::true_
  154. , boost::mpl::false_
  155. >::type
  156. ));
  157. BOOST_MPL_ASSERT((
  158. boost::mpl::if_<
  159. boost::is_same<
  160. boost::parameter::aux::unwrap_cv_reference<
  161. test::foo volatile
  162. >::type
  163. , test::foo volatile
  164. >
  165. , boost::mpl::true_
  166. , boost::mpl::false_
  167. >::type
  168. ));
  169. BOOST_MPL_ASSERT((
  170. boost::mpl::if_<
  171. boost::is_same<
  172. boost::parameter::aux::unwrap_cv_reference<
  173. test::foo const volatile
  174. >::type
  175. , test::foo const volatile
  176. >
  177. , boost::mpl::true_
  178. , boost::mpl::false_
  179. >::type
  180. ));
  181. #endif // BOOST_PARAMETER_CAN_USE_MP11
  182. }
  183. #include <boost/ref.hpp>
  184. MPL_TEST_CASE()
  185. {
  186. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  187. static_assert(
  188. std::is_same<
  189. boost::parameter::aux::unwrap_cv_reference<
  190. boost::reference_wrapper<test::foo>
  191. >::type
  192. , test::foo
  193. >::value
  194. , "unwrap_cv_reference<ref(test::foo)>::type == test::foo"
  195. );
  196. static_assert(
  197. std::is_same<
  198. boost::parameter::aux::unwrap_cv_reference<
  199. boost::reference_wrapper<test::foo> const
  200. >::type
  201. , test::foo
  202. >::value
  203. , "unwrap_cv_reference<ref(test::foo) const>::type == test::foo"
  204. );
  205. static_assert(
  206. std::is_same<
  207. boost::parameter::aux::unwrap_cv_reference<
  208. boost::reference_wrapper<test::foo> volatile
  209. >::type
  210. , test::foo
  211. >::value
  212. , "unwrap_cv_reference<ref(test::foo) volatile>::type == test::foo"
  213. );
  214. static_assert(
  215. std::is_same<
  216. boost::parameter::aux::unwrap_cv_reference<
  217. boost::reference_wrapper<test::foo> const volatile
  218. >::type
  219. , test::foo
  220. >::value
  221. , "unwrap_cv_reference<ref(test::foo) cv>::type == test::foo"
  222. );
  223. #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
  224. BOOST_MPL_ASSERT((
  225. boost::mpl::if_<
  226. boost::is_same<
  227. boost::parameter::aux::unwrap_cv_reference<
  228. boost::reference_wrapper<test::foo>
  229. >::type
  230. , test::foo
  231. >
  232. , boost::mpl::true_
  233. , boost::mpl::false_
  234. >::type
  235. ));
  236. BOOST_MPL_ASSERT((
  237. boost::mpl::if_<
  238. boost::is_same<
  239. boost::parameter::aux::unwrap_cv_reference<
  240. boost::reference_wrapper<test::foo> const
  241. >::type
  242. , test::foo
  243. >
  244. , boost::mpl::true_
  245. , boost::mpl::false_
  246. >::type
  247. ));
  248. BOOST_MPL_ASSERT((
  249. boost::mpl::if_<
  250. boost::is_same<
  251. boost::parameter::aux::unwrap_cv_reference<
  252. boost::reference_wrapper<test::foo> volatile
  253. >::type
  254. , test::foo
  255. >
  256. , boost::mpl::true_
  257. , boost::mpl::false_
  258. >::type
  259. ));
  260. BOOST_MPL_ASSERT((
  261. boost::mpl::if_<
  262. boost::is_same<
  263. boost::parameter::aux::unwrap_cv_reference<
  264. boost::reference_wrapper<test::foo> const volatile
  265. >::type
  266. , test::foo
  267. >
  268. , boost::mpl::true_
  269. , boost::mpl::false_
  270. >::type
  271. ));
  272. #endif // BOOST_PARAMETER_CAN_USE_MP11
  273. }
  274. #if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
  275. #include <functional>
  276. MPL_TEST_CASE()
  277. {
  278. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  279. static_assert(
  280. std::is_same<
  281. boost::parameter::aux::unwrap_cv_reference<
  282. std::reference_wrapper<test::foo>
  283. >::type
  284. , test::foo
  285. >::value
  286. , "unwrap_cv_reference<std::ref(test::foo)>::type == test::foo"
  287. );
  288. static_assert(
  289. std::is_same<
  290. boost::parameter::aux::unwrap_cv_reference<
  291. std::reference_wrapper<test::foo> const
  292. >::type
  293. , test::foo
  294. >::value
  295. , "unwrap_cv_reference<std::ref(test::foo) const>::type == test::foo"
  296. );
  297. static_assert(
  298. std::is_same<
  299. boost::parameter::aux::unwrap_cv_reference<
  300. std::reference_wrapper<test::foo> volatile
  301. >::type
  302. , test::foo
  303. >::value
  304. , "unwrap_cv_reference<std::ref(test::foo) volatile>::type == test::foo"
  305. );
  306. static_assert(
  307. std::is_same<
  308. boost::parameter::aux::unwrap_cv_reference<
  309. std::reference_wrapper<test::foo> const volatile
  310. >::type
  311. , test::foo
  312. >::value
  313. , "unwrap_cv_reference<std::ref(test::foo) cv>::type == test::foo"
  314. );
  315. #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
  316. BOOST_MPL_ASSERT((
  317. boost::mpl::if_<
  318. boost::is_same<
  319. boost::parameter::aux::unwrap_cv_reference<
  320. std::reference_wrapper<test::foo>
  321. >::type
  322. , test::foo
  323. >
  324. , boost::mpl::true_
  325. , boost::mpl::false_
  326. >::type
  327. ));
  328. BOOST_MPL_ASSERT((
  329. boost::mpl::if_<
  330. boost::is_same<
  331. boost::parameter::aux::unwrap_cv_reference<
  332. std::reference_wrapper<test::foo> const
  333. >::type
  334. , test::foo
  335. >
  336. , boost::mpl::true_
  337. , boost::mpl::false_
  338. >::type
  339. ));
  340. BOOST_MPL_ASSERT((
  341. boost::mpl::if_<
  342. boost::is_same<
  343. boost::parameter::aux::unwrap_cv_reference<
  344. std::reference_wrapper<test::foo> volatile
  345. >::type
  346. , test::foo
  347. >
  348. , boost::mpl::true_
  349. , boost::mpl::false_
  350. >::type
  351. ));
  352. BOOST_MPL_ASSERT((
  353. boost::mpl::if_<
  354. boost::is_same<
  355. boost::parameter::aux::unwrap_cv_reference<
  356. std::reference_wrapper<test::foo> const volatile
  357. >::type
  358. , test::foo
  359. >
  360. , boost::mpl::true_
  361. , boost::mpl::false_
  362. >::type
  363. ));
  364. #endif // BOOST_PARAMETER_CAN_USE_MP11
  365. }
  366. #endif // BOOST_NO_CXX11_HDR_FUNCTIONAL