bases.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BASES_DWA2002321_HPP
  6. # define BASES_DWA2002321_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/type_traits/object_traits.hpp>
  9. # include <boost/python/detail/type_list.hpp>
  10. # include <boost/mpl/if.hpp>
  11. # include <boost/mpl/bool.hpp>
  12. # include <boost/preprocessor/enum_params_with_a_default.hpp>
  13. # include <boost/preprocessor/enum_params.hpp>
  14. namespace boost { namespace python {
  15. # define BOOST_PYTHON_BASE_PARAMS BOOST_PP_ENUM_PARAMS_Z(1, BOOST_PYTHON_MAX_BASES, Base)
  16. // A type list for specifying bases
  17. template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PYTHON_MAX_BASES, typename Base, mpl::void_) >
  18. struct bases : detail::type_list< BOOST_PYTHON_BASE_PARAMS >::type
  19. {};
  20. namespace detail
  21. {
  22. # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  23. template <class T> struct specifies_bases
  24. : mpl::false_
  25. {
  26. };
  27. template < BOOST_PP_ENUM_PARAMS_Z(1, BOOST_PYTHON_MAX_BASES, class Base) >
  28. struct specifies_bases< bases< BOOST_PYTHON_BASE_PARAMS > >
  29. : mpl::true_
  30. {
  31. };
  32. # else
  33. template < BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, class Base) >
  34. static char is_bases_helper(bases< BOOST_PYTHON_BASE_PARAMS > const&);
  35. static char (& is_bases_helper(...) )[256];
  36. template <class T>
  37. struct specifies_bases
  38. {
  39. private:
  40. static typename add_reference<T>::type make();
  41. BOOST_STATIC_CONSTANT(bool, non_ref = !is_reference<T>::value);
  42. public:
  43. BOOST_STATIC_CONSTANT(bool, value = non_ref & (sizeof(is_bases_helper(make())) == 1));
  44. typedef mpl::bool_<value> type;
  45. };
  46. # endif
  47. template <class T, class Prev = bases<> >
  48. struct select_bases
  49. : mpl::if_<
  50. specifies_bases<T>
  51. , T
  52. , Prev
  53. >
  54. {
  55. };
  56. }
  57. # undef BOOST_PYTHON_BASE_PARAMS
  58. }} // namespace boost::python
  59. #endif // BASES_DWA2002321_HPP