value_is_xxx.hpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright David Abrahams 2003.
  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 VALUE_IS_XXX_DWA2003224_HPP
  6. # define VALUE_IS_XXX_DWA2003224_HPP
  7. # include <boost/config.hpp>
  8. # include <boost/mpl/bool.hpp>
  9. # include <boost/preprocessor/enum_params.hpp>
  10. # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  11. # include <boost/type_traits/is_reference.hpp>
  12. # include <boost/type_traits/add_reference.hpp>
  13. # define BOOST_PYTHON_VALUE_IS_XXX_DEF(name, qualified_name, nargs) \
  14. template <class X_> \
  15. struct value_is_##name \
  16. { \
  17. typedef char yes; \
  18. typedef char (&no)[2]; \
  19. \
  20. static typename add_reference<X_>::type dummy; \
  21. \
  22. template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class U) > \
  23. static yes test( \
  24. qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, U) > const&, int \
  25. ); \
  26. \
  27. template <class U> \
  28. static no test(U&, ...); \
  29. \
  30. BOOST_STATIC_CONSTANT( \
  31. bool, value \
  32. = (sizeof(test(dummy, 0)) == sizeof(yes))); \
  33. \
  34. typedef mpl::bool_<value> type; \
  35. };
  36. # else
  37. # include <boost/type_traits/remove_reference.hpp>
  38. # include <boost/type_traits/remove_cv.hpp>
  39. # include <boost/python/detail/is_xxx.hpp>
  40. # define BOOST_PYTHON_VALUE_IS_XXX_DEF(name, qualified_name, nargs) \
  41. template <class X_> \
  42. struct value_is_##name \
  43. { \
  44. BOOST_PYTHON_IS_XXX_DEF(name,qualified_name,nargs) \
  45. BOOST_STATIC_CONSTANT(bool, value = is_##name< \
  46. typename remove_cv< \
  47. typename remove_reference<X_>::type \
  48. >::type \
  49. >::value); \
  50. typedef mpl::bool_<value> type; \
  51. \
  52. };
  53. # endif
  54. #endif // VALUE_IS_XXX_DWA2003224_HPP