is_empty.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. //
  6. // See http://www.boost.org/libs/type_traits for most recent version including documentation.
  7. #ifndef BOOST_TT_IS_EMPTY_HPP_INCLUDED
  8. #define BOOST_TT_IS_EMPTY_HPP_INCLUDED
  9. #include <boost/type_traits/is_convertible.hpp>
  10. #include <boost/type_traits/detail/config.hpp>
  11. #include <boost/type_traits/intrinsics.hpp>
  12. #include <boost/type_traits/remove_cv.hpp>
  13. #include <boost/type_traits/is_class.hpp>
  14. #include <boost/type_traits/add_reference.hpp>
  15. #ifndef BOOST_INTERNAL_IS_EMPTY
  16. #define BOOST_INTERNAL_IS_EMPTY(T) false
  17. #else
  18. #define BOOST_INTERNAL_IS_EMPTY(T) BOOST_IS_EMPTY(T)
  19. #endif
  20. namespace boost {
  21. namespace detail {
  22. #ifdef BOOST_MSVC
  23. #pragma warning(push)
  24. #pragma warning(disable:4624) // destructor could not be generated
  25. #endif
  26. template <typename T>
  27. struct empty_helper_t1 : public T
  28. {
  29. empty_helper_t1(); // hh compiler bug workaround
  30. int i[256];
  31. private:
  32. // suppress compiler warnings:
  33. empty_helper_t1(const empty_helper_t1&);
  34. empty_helper_t1& operator=(const empty_helper_t1&);
  35. };
  36. #ifdef BOOST_MSVC
  37. #pragma warning(pop)
  38. #endif
  39. struct empty_helper_t2 { int i[256]; };
  40. #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
  41. template <typename T, bool is_a_class = false>
  42. struct empty_helper
  43. {
  44. BOOST_STATIC_CONSTANT(bool, value = false);
  45. };
  46. template <typename T>
  47. struct empty_helper<T, true>
  48. {
  49. BOOST_STATIC_CONSTANT(
  50. bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
  51. );
  52. };
  53. template <typename T>
  54. struct is_empty_impl
  55. {
  56. typedef typename remove_cv<T>::type cvt;
  57. BOOST_STATIC_CONSTANT(
  58. bool,
  59. value = ( ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value || BOOST_INTERNAL_IS_EMPTY(cvt)));
  60. };
  61. #else // __BORLANDC__
  62. template <typename T, bool is_a_class, bool convertible_to_int>
  63. struct empty_helper
  64. {
  65. BOOST_STATIC_CONSTANT(bool, value = false);
  66. };
  67. template <typename T>
  68. struct empty_helper<T, true, false>
  69. {
  70. BOOST_STATIC_CONSTANT(bool, value = (
  71. sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
  72. ));
  73. };
  74. template <typename T>
  75. struct is_empty_impl
  76. {
  77. typedef typename remove_cv<T>::type cvt;
  78. typedef typename add_reference<T>::type r_type;
  79. BOOST_STATIC_CONSTANT(
  80. bool, value = (
  81. ::boost::detail::empty_helper<
  82. cvt
  83. , ::boost::is_class<T>::value
  84. , ::boost::is_convertible< r_type,int>::value
  85. >::value || BOOST_INTERNAL_IS_EMPTY(cvt));
  86. };
  87. #endif // __BORLANDC__
  88. } // namespace detail
  89. template <class T> struct is_empty : integral_constant<bool, ::boost::detail::is_empty_impl<T>::value> {};
  90. } // namespace boost
  91. #undef BOOST_INTERNAL_IS_EMPTY
  92. #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED