exercising-the-code-so-far0.cpp 4.8 KB

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