ntp.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. // Copyright Daniel Wallin 2006.
  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. namespace test {
  10. struct X
  11. {
  12. };
  13. struct Y : X
  14. {
  15. };
  16. } // namespace test
  17. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  18. #include <type_traits>
  19. #else
  20. #include <boost/mpl/bool.hpp>
  21. #include <boost/mpl/if.hpp>
  22. #include <boost/type_traits/is_base_of.hpp>
  23. #include <boost/type_traits/remove_const.hpp>
  24. #include <boost/type_traits/remove_reference.hpp>
  25. #endif
  26. namespace test {
  27. struct Z
  28. {
  29. template <typename T, typename Args>
  30. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  31. using fn = std::is_base_of<
  32. X
  33. , typename std::remove_const<
  34. typename std::remove_reference<T>::type
  35. >::type
  36. >;
  37. #else
  38. struct apply
  39. : boost::mpl::if_<
  40. boost::is_base_of<
  41. X
  42. , typename boost::remove_const<
  43. typename boost::remove_reference<T>::type
  44. >::type
  45. >
  46. , boost::mpl::true_
  47. , boost::mpl::false_
  48. >::type
  49. {
  50. };
  51. #endif // BOOST_PARAMETER_CAN_USE_MP11
  52. };
  53. } // namespace test
  54. #include <boost/parameter/template_keyword.hpp>
  55. namespace test {
  56. template <typename T = int>
  57. struct a0_is : boost::parameter::template_keyword<test::a0_is<>,T>
  58. {
  59. };
  60. template <typename T = int>
  61. struct a1_is : boost::parameter::template_keyword<test::a1_is<>,T>
  62. {
  63. };
  64. template <typename T = int>
  65. struct a2_is : boost::parameter::template_keyword<test::a2_is<>,T>
  66. {
  67. };
  68. template <typename T = int>
  69. struct a3_is : boost::parameter::template_keyword<test::a3_is<>,T>
  70. {
  71. };
  72. } // namespace test
  73. #include <boost/parameter/parameters.hpp>
  74. #include <boost/parameter/optional.hpp>
  75. #include <boost/parameter/deduced.hpp>
  76. #include <boost/parameter/binding.hpp>
  77. namespace test {
  78. template <
  79. typename A0 = boost::parameter::void_
  80. , typename A1 = boost::parameter::void_
  81. , typename A2 = boost::parameter::void_
  82. , typename A3 = boost::parameter::void_
  83. >
  84. struct with_ntp
  85. {
  86. typedef typename boost::parameter::parameters<
  87. test::a0_is<>
  88. , test::a1_is<>
  89. , test::a2_is<>
  90. , boost::parameter::optional<
  91. boost::parameter::deduced<test::a3_is<> >
  92. , Z
  93. >
  94. >::BOOST_NESTED_TEMPLATE bind<
  95. A0
  96. , A1
  97. , A2
  98. , A3
  99. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  100. , boost::parameter::void_
  101. #endif
  102. >::type args;
  103. typedef typename boost::parameter::binding<
  104. args
  105. , test::a0_is<>
  106. , void*
  107. >::type a0;
  108. typedef typename boost::parameter::binding<
  109. args
  110. , test::a1_is<>
  111. , void*
  112. >::type a1;
  113. typedef typename boost::parameter::binding<
  114. args
  115. , test::a2_is<>
  116. , void*
  117. >::type a2;
  118. typedef typename boost::parameter::binding<
  119. args
  120. , test::a3_is<>
  121. , void*
  122. >::type a3;
  123. typedef void(*type)(a0, a1, a2, a3);
  124. };
  125. } // namespace test
  126. #include <boost/mpl/aux_/test.hpp>
  127. #if !defined(BOOST_PARAMETER_CAN_USE_MP11)
  128. #include <boost/mpl/assert.hpp>
  129. #include <boost/type_traits/is_same.hpp>
  130. #endif
  131. MPL_TEST_CASE()
  132. {
  133. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  134. static_assert(
  135. std::is_same<
  136. test::with_ntp<>::type
  137. , void(*)(void*, void*, void*, void*)
  138. >::value
  139. , "type must be void(*)(void*, void*, void*, void*)"
  140. );
  141. static_assert(
  142. std::is_same<
  143. test::with_ntp<test::a2_is<int> >::type
  144. , void(*)(void*, void*, int, void*)
  145. >::value
  146. , "type must be void(*)(void*, void*, int, void*)"
  147. );
  148. static_assert(
  149. std::is_same<
  150. test::with_ntp<test::a1_is<int> >::type
  151. , void(*)(void*, int, void*, void*)
  152. >::value
  153. , "type must be void(*)(void*, int, void*, void*)"
  154. );
  155. static_assert(
  156. std::is_same<
  157. test::with_ntp<test::a2_is<int const>,test::a1_is<float> >::type
  158. , void(*)(void*, float, int const, void*)
  159. >::value
  160. , "type must be void(*)(void*, float, int const, void*)"
  161. );
  162. static_assert(
  163. std::is_same<
  164. test::with_ntp<int const>::type
  165. , void(*)(int const, void*, void*, void*)
  166. >::value
  167. , "type must be void(*)(int const, void*, void*, void*)"
  168. );
  169. static_assert(
  170. std::is_same<
  171. test::with_ntp<int,float>::type
  172. , void(*)(int, float, void*, void*)
  173. >::value
  174. , "type must be void(*)(int, float, void*, void*)"
  175. );
  176. static_assert(
  177. std::is_same<
  178. test::with_ntp<int,float,char>::type
  179. , void(*)(int, float, char, void*)
  180. >::value
  181. , "type must be void(*)(int, float, char, void*)"
  182. );
  183. static_assert(
  184. std::is_same<
  185. test::with_ntp<test::a0_is<int>,test::Y>::type
  186. , void(*)(int, void*, void*, test::Y)
  187. >::value
  188. , "type must be must be void(*)(int, void*, void*, test::Y)"
  189. );
  190. static_assert(
  191. std::is_same<
  192. test::with_ntp<int&,test::a2_is<char>,test::Y>::type
  193. , void(*)(int&, void*, char, test::Y)
  194. >::value
  195. , "type must be void(*)(int&, void*, char, test::Y)"
  196. );
  197. #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
  198. BOOST_MPL_ASSERT((
  199. boost::mpl::if_<
  200. boost::is_same<
  201. test::with_ntp<>::type
  202. , void(*)(void*, void*, void*, void*)
  203. >
  204. , boost::mpl::true_
  205. , boost::mpl::false_
  206. >::type
  207. ));
  208. BOOST_MPL_ASSERT((
  209. boost::mpl::if_<
  210. boost::is_same<
  211. test::with_ntp<test::a2_is<int> >::type
  212. , void(*)(void*, void*, int, void*)
  213. >
  214. , boost::mpl::true_
  215. , boost::mpl::false_
  216. >::type
  217. ));
  218. BOOST_MPL_ASSERT((
  219. boost::mpl::if_<
  220. boost::is_same<
  221. test::with_ntp<test::a1_is<int> >::type
  222. , void(*)(void*, int, void*, void*)
  223. >
  224. , boost::mpl::true_
  225. , boost::mpl::false_
  226. >::type
  227. ));
  228. BOOST_MPL_ASSERT((
  229. boost::mpl::if_<
  230. boost::is_same<
  231. test::with_ntp<
  232. test::a2_is<int const>
  233. , test::a1_is<float>
  234. >::type
  235. , void(*)(void*, float, int const, void*)
  236. >
  237. , boost::mpl::true_
  238. , boost::mpl::false_
  239. >::type
  240. ));
  241. BOOST_MPL_ASSERT((
  242. boost::mpl::if_<
  243. boost::is_same<
  244. test::with_ntp<int const>::type
  245. , void(*)(int const, void*, void*, void*)
  246. >
  247. , boost::mpl::true_
  248. , boost::mpl::false_
  249. >::type
  250. ));
  251. BOOST_MPL_ASSERT((
  252. boost::mpl::if_<
  253. boost::is_same<
  254. test::with_ntp<int,float>::type
  255. , void(*)(int, float, void*, void*)
  256. >
  257. , boost::mpl::true_
  258. , boost::mpl::false_
  259. >::type
  260. ));
  261. BOOST_MPL_ASSERT((
  262. boost::mpl::if_<
  263. boost::is_same<
  264. test::with_ntp<int,float,char>::type
  265. , void(*)(int, float, char, void*)
  266. >
  267. , boost::mpl::true_
  268. , boost::mpl::false_
  269. >::type
  270. ));
  271. BOOST_MPL_ASSERT((
  272. boost::mpl::if_<
  273. boost::is_same<
  274. test::with_ntp<test::a0_is<int>,test::Y>::type
  275. , void(*)(int, void*, void*, test::Y)
  276. >
  277. , boost::mpl::true_
  278. , boost::mpl::false_
  279. >::type
  280. ));
  281. BOOST_MPL_ASSERT((
  282. boost::mpl::if_<
  283. boost::is_same<
  284. test::with_ntp<int&,test::a2_is<char>,test::Y>::type
  285. , void(*)(int&, void*, char, test::Y)
  286. >
  287. , boost::mpl::true_
  288. , boost::mpl::false_
  289. >::type
  290. ));
  291. #endif // BOOST_PARAMETER_CAN_USE_MP11
  292. typedef int test_array[1];
  293. typedef void(*test_function)();
  294. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  295. static_assert(
  296. std::is_same<
  297. test::with_ntp<test_array,test_function>::type
  298. , void(*)(test_array&, test_function, void*, void*)
  299. >::value
  300. , "type must be void(*)(test_array&, test_function, void*, void*)"
  301. );
  302. #else
  303. BOOST_MPL_ASSERT((
  304. boost::mpl::if_<
  305. boost::is_same<
  306. test::with_ntp<test_array,test_function>::type
  307. , void(*)(test_array&, test_function, void*, void*)
  308. >
  309. , boost::mpl::true_
  310. , boost::mpl::false_
  311. >::type
  312. ));
  313. #endif
  314. }