is_class.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // (C) Copyright Dave Abrahams, Steve Cleary, Beman Dawes, Howard
  2. // Hinnant & John Maddock 2000-2003.
  3. // Use, modification and distribution are subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt).
  6. //
  7. // See http://www.boost.org/libs/type_traits for most recent version including documentation.
  8. #ifndef BOOST_TT_IS_CLASS_HPP_INCLUDED
  9. #define BOOST_TT_IS_CLASS_HPP_INCLUDED
  10. #include <boost/type_traits/detail/config.hpp>
  11. #include <boost/type_traits/intrinsics.hpp>
  12. #include <boost/type_traits/integral_constant.hpp>
  13. #ifndef BOOST_IS_CLASS
  14. # include <boost/type_traits/is_union.hpp>
  15. #ifdef BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
  16. # include <boost/type_traits/detail/yes_no_type.hpp>
  17. #else
  18. # include <boost/type_traits/is_scalar.hpp>
  19. # include <boost/type_traits/is_array.hpp>
  20. # include <boost/type_traits/is_reference.hpp>
  21. # include <boost/type_traits/is_void.hpp>
  22. # include <boost/type_traits/is_function.hpp>
  23. #endif
  24. #endif // BOOST_IS_CLASS
  25. namespace boost {
  26. namespace detail {
  27. #ifndef BOOST_IS_CLASS
  28. #ifdef BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
  29. // This is actually the conforming implementation which works with
  30. // abstract classes. However, enough compilers have trouble with
  31. // it that most will use the one in
  32. // boost/type_traits/object_traits.hpp. This implementation
  33. // actually works with VC7.0, but other interactions seem to fail
  34. // when we use it.
  35. // is_class<> metafunction due to Paul Mensonides
  36. // (leavings@attbi.com). For more details:
  37. // http://groups.google.com/groups?hl=en&selm=000001c1cc83%24e154d5e0%247772e50c%40c161550a&rnum=1
  38. #if defined(__GNUC__) && !defined(__EDG_VERSION__)
  39. template <class U> ::boost::type_traits::yes_type is_class_tester(void(U::*)(void));
  40. template <class U> ::boost::type_traits::no_type is_class_tester(...);
  41. template <typename T>
  42. struct is_class_impl
  43. {
  44. BOOST_STATIC_CONSTANT(bool, value =
  45. sizeof(is_class_tester<T>(0)) == sizeof(::boost::type_traits::yes_type)
  46. && ! ::boost::is_union<T>::value
  47. );
  48. };
  49. #else
  50. template <typename T>
  51. struct is_class_impl
  52. {
  53. template <class U> static ::boost::type_traits::yes_type is_class_tester(void(U::*)(void));
  54. template <class U> static ::boost::type_traits::no_type is_class_tester(...);
  55. BOOST_STATIC_CONSTANT(bool, value =
  56. sizeof(is_class_tester<T>(0)) == sizeof(::boost::type_traits::yes_type)
  57. && ! ::boost::is_union<T>::value
  58. );
  59. };
  60. #endif
  61. #else
  62. template <typename T>
  63. struct is_class_impl
  64. {
  65. BOOST_STATIC_CONSTANT(bool, value =
  66. ! ::boost::is_union<T>::value >::value
  67. && ! ::boost::is_scalar<T>::value
  68. && ! ::boost::is_array<T>::value
  69. && ! ::boost::is_reference<T>::value
  70. && ! ::boost::is_void<T>::value
  71. && ! ::boost::is_function<T>::value
  72. );
  73. };
  74. # endif // BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
  75. # else // BOOST_IS_CLASS
  76. template <typename T>
  77. struct is_class_impl
  78. {
  79. BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_CLASS(T));
  80. };
  81. # endif // BOOST_IS_CLASS
  82. } // namespace detail
  83. template <class T> struct is_class : public integral_constant<bool, ::boost::detail::is_class_impl<T>::value> {};
  84. # ifdef __EDG_VERSION__
  85. template <class T> struct is_class<const T> : public is_class<T>{};
  86. template <class T> struct is_class<const volatile T> : public is_class<T>{};
  87. template <class T> struct is_class<volatile T> : public is_class<T>{};
  88. # endif
  89. } // namespace boost
  90. #endif // BOOST_TT_IS_CLASS_HPP_INCLUDED