is_xxx.hpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright David Abrahams 2005. Distributed under the Boost
  2. // Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_DETAIL_IS_XXX_DWA20051011_HPP
  5. # define BOOST_DETAIL_IS_XXX_DWA20051011_HPP
  6. # include <boost/config.hpp>
  7. # include <boost/mpl/bool.hpp>
  8. # include <boost/preprocessor/enum_params.hpp>
  9. # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  10. # include <boost/type_traits/is_reference.hpp>
  11. # include <boost/type_traits/add_reference.hpp>
  12. # define BOOST_DETAIL_IS_XXX_DEF(name, qualified_name, nargs) \
  13. template <class X_> \
  14. struct is_##name \
  15. { \
  16. typedef char yes; \
  17. typedef char (&no)[2]; \
  18. \
  19. static typename add_reference<X_>::type dummy; \
  20. \
  21. struct helpers \
  22. { \
  23. template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class U) > \
  24. static yes test( \
  25. qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, U) >&, int \
  26. ); \
  27. \
  28. template <class U> \
  29. static no test(U&, ...); \
  30. }; \
  31. \
  32. BOOST_STATIC_CONSTANT( \
  33. bool, value \
  34. = !is_reference<X_>::value \
  35. & (sizeof(helpers::test(dummy, 0)) == sizeof(yes))); \
  36. \
  37. typedef mpl::bool_<value> type; \
  38. };
  39. # else
  40. # define BOOST_DETAIL_IS_XXX_DEF(name, qualified_name, nargs) \
  41. template <class T> \
  42. struct is_##name : mpl::false_ \
  43. { \
  44. }; \
  45. \
  46. template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class T) > \
  47. struct is_##name< \
  48. qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, T) > \
  49. > \
  50. : mpl::true_ \
  51. { \
  52. };
  53. # endif
  54. #endif // BOOST_DETAIL_IS_XXX_DWA20051011_HPP