deduced-template-parameters0.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #include <boost/parameter.hpp>
  2. namespace boost { namespace python {
  3. BOOST_PARAMETER_TEMPLATE_KEYWORD(class_type)
  4. BOOST_PARAMETER_TEMPLATE_KEYWORD(base_list)
  5. BOOST_PARAMETER_TEMPLATE_KEYWORD(held_type)
  6. BOOST_PARAMETER_TEMPLATE_KEYWORD(copyable)
  7. }}
  8. namespace boost { namespace python {
  9. namespace detail {
  10. struct bases_base
  11. {
  12. };
  13. }
  14. template <typename A0 = void, typename A1 = void, typename A2 = void>
  15. struct bases : detail::bases_base
  16. {
  17. };
  18. }}
  19. #include <boost/mpl/bool.hpp>
  20. #include <boost/mpl/placeholders.hpp>
  21. #include <boost/mpl/if.hpp>
  22. #include <boost/mpl/eval_if.hpp>
  23. #include <boost/noncopyable.hpp>
  24. #include <boost/type_traits/is_same.hpp>
  25. #include <boost/type_traits/is_base_of.hpp>
  26. #include <boost/type_traits/is_class.hpp>
  27. #include <boost/config.hpp>
  28. #if !defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) || \
  29. !(1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
  30. #include <boost/type_traits/is_scalar.hpp>
  31. #endif
  32. namespace boost { namespace python {
  33. typedef boost::parameter::parameters<
  34. boost::parameter::required<
  35. tag::class_type
  36. #if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) && \
  37. (1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
  38. , boost::mpl::if_<
  39. boost::is_class<boost::mpl::_>
  40. , boost::mpl::true_
  41. , boost::mpl::false_
  42. >
  43. #else
  44. , boost::mpl::if_<
  45. boost::is_scalar<boost::mpl::_>
  46. , boost::mpl::false_
  47. , boost::mpl::true_
  48. >
  49. #endif
  50. >
  51. , boost::parameter::optional<
  52. boost::parameter::deduced<tag::base_list>
  53. , boost::mpl::if_<
  54. boost::is_base_of<detail::bases_base,boost::mpl::_>
  55. , boost::mpl::true_
  56. , boost::mpl::false_
  57. >
  58. >
  59. , boost::parameter::optional<
  60. boost::parameter::deduced<tag::held_type>
  61. , boost::mpl::eval_if<
  62. boost::is_base_of<detail::bases_base,boost::mpl::_>
  63. , boost::mpl::false_
  64. , boost::mpl::if_<
  65. boost::is_same<boost::noncopyable,boost::mpl::_>
  66. , boost::mpl::false_
  67. , boost::mpl::true_
  68. >
  69. >
  70. >
  71. , boost::parameter::optional<
  72. boost::parameter::deduced<tag::copyable>
  73. , boost::mpl::if_<
  74. boost::is_same<boost::noncopyable,boost::mpl::_>
  75. , boost::mpl::true_
  76. , boost::mpl::false_
  77. >
  78. >
  79. > class_signature;
  80. template <
  81. typename A0
  82. , typename A1 = boost::parameter::void_
  83. , typename A2 = boost::parameter::void_
  84. , typename A3 = boost::parameter::void_
  85. >
  86. struct class_
  87. {
  88. // Create ArgumentPack
  89. typedef typename boost::python::class_signature::BOOST_NESTED_TEMPLATE
  90. bind<A0,A1,A2,A3>::type args;
  91. // Extract first logical parameter.
  92. typedef typename boost::parameter::value_type<
  93. args,boost::python::tag::class_type
  94. >::type class_type;
  95. typedef typename boost::parameter::value_type<
  96. args,boost::python::tag::base_list,boost::python::bases<>
  97. >::type base_list;
  98. typedef typename boost::parameter::value_type<
  99. args,boost::python::tag::held_type,class_type
  100. >::type held_type;
  101. typedef typename boost::parameter::value_type<
  102. args,boost::python::tag::copyable,void
  103. >::type copyable;
  104. };
  105. }}
  106. struct B
  107. {
  108. };
  109. struct D
  110. {
  111. };
  112. typedef boost::python::class_<B,boost::noncopyable> c1;
  113. #include <memory>
  114. #if defined(BOOST_NO_CXX11_SMART_PTR)
  115. typedef boost::python::class_<D,std::auto_ptr<D>,boost::python::bases<B> > c2;
  116. #else
  117. typedef boost::python::class_<
  118. D,std::unique_ptr<D>,boost::python::bases<B>
  119. > c2;
  120. #endif
  121. #include <boost/mpl/assert.hpp>
  122. #include <boost/mpl/aux_/test.hpp>
  123. MPL_TEST_CASE()
  124. {
  125. BOOST_MPL_ASSERT((
  126. boost::mpl::if_<
  127. boost::is_same<c1::class_type,B>
  128. , boost::mpl::true_
  129. , boost::mpl::false_
  130. >::type
  131. ));
  132. BOOST_MPL_ASSERT((
  133. boost::mpl::if_<
  134. boost::is_same<c1::base_list,boost::python::bases<> >
  135. , boost::mpl::true_
  136. , boost::mpl::false_
  137. >::type
  138. ));
  139. BOOST_MPL_ASSERT((
  140. boost::mpl::if_<
  141. boost::is_same<c1::held_type,B>
  142. , boost::mpl::true_
  143. , boost::mpl::false_
  144. >::type
  145. ));
  146. BOOST_MPL_ASSERT((
  147. boost::mpl::if_<
  148. boost::is_same<c1::copyable,boost::noncopyable>
  149. , boost::mpl::true_
  150. , boost::mpl::false_
  151. >::type
  152. ));
  153. BOOST_MPL_ASSERT((
  154. boost::mpl::if_<
  155. boost::is_same<c2::class_type,D>
  156. , boost::mpl::true_
  157. , boost::mpl::false_
  158. >::type
  159. ));
  160. BOOST_MPL_ASSERT((
  161. boost::mpl::if_<
  162. boost::is_same<c2::base_list,boost::python::bases<B> >
  163. , boost::mpl::true_
  164. , boost::mpl::false_
  165. >::type
  166. ));
  167. #if defined(BOOST_NO_CXX11_SMART_PTR)
  168. BOOST_MPL_ASSERT((
  169. boost::mpl::if_<
  170. boost::is_same<c2::held_type,std::auto_ptr<D> >
  171. , boost::mpl::true_
  172. , boost::mpl::false_
  173. >::type
  174. ));
  175. #else
  176. BOOST_MPL_ASSERT((
  177. boost::mpl::if_<
  178. boost::is_same<c2::held_type,std::unique_ptr<D> >
  179. , boost::mpl::true_
  180. , boost::mpl::false_
  181. >::type
  182. ));
  183. #endif // BOOST_NO_CXX11_SMART_PTR
  184. BOOST_MPL_ASSERT((
  185. boost::mpl::if_<
  186. boost::is_same<c2::copyable,void>
  187. , boost::mpl::true_
  188. , boost::mpl::false_
  189. >::type
  190. ));
  191. }