is_abstract.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef BOOST_TT_IS_ABSTRACT_CLASS_HPP
  2. #define BOOST_TT_IS_ABSTRACT_CLASS_HPP
  3. #if defined(_MSC_VER)
  4. # pragma once
  5. #endif
  6. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  7. // is_abstract_class.hpp:
  8. //
  9. // (C) Copyright 2002 Rani Sharoni (rani_sharoni@hotmail.com) and Robert Ramey
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. //
  14. // See http://www.boost.org for updates, documentation, and revision history.
  15. //
  16. // Compile type discovery whether given type is abstract class or not.
  17. //
  18. // Requires DR 337 to be supported by compiler
  19. // (http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#337).
  20. //
  21. //
  22. // Believed (Jan 2004) to work on:
  23. // - GCC 3.4
  24. // - VC++ 7.1
  25. // - compilers with new EDG frontend (Intel C++ 7, Comeau 4.3.2)
  26. //
  27. // Doesn't work on:
  28. // - VC++6, VC++7.0 and less
  29. // - GCC 3.3.X and less
  30. // - Borland C++ 6 and less
  31. //
  32. //
  33. // History:
  34. // - Originally written by Rani Sharoni, see
  35. // http://groups.google.com/groups?selm=df893da6.0207110613.75b2fe90%40posting.google.com
  36. // At this time supported by EDG (Intel C++ 7, Comeau 4.3.2) and VC7.1.
  37. // - Adapted and added into Boost.Serialization library by Robert Ramey
  38. // (starting with submission #10).
  39. // - Jan 2004: GCC 3.4 fixed to support DR337 (Giovanni Bajo).
  40. // - Jan 2004: modified to be part of Boost.TypeTraits (Pavel Vozenilek).
  41. // - Nov 2004: Christoph Ludwig found that the implementation did not work with
  42. // template types and gcc-3.4 or VC7.1, fix due to Christoph Ludwig
  43. // and John Maddock.
  44. // - Dec 2004: Added new config macro BOOST_NO_IS_ABSTRACT which causes the template
  45. // to degrade gracefully, rather than trash the compiler (John Maddock).
  46. //
  47. #include <cstddef> // size_t
  48. #include <boost/type_traits/intrinsics.hpp>
  49. #include <boost/type_traits/integral_constant.hpp>
  50. #ifndef BOOST_IS_ABSTRACT
  51. #include <boost/static_assert.hpp>
  52. #include <boost/type_traits/detail/yes_no_type.hpp>
  53. #include <boost/type_traits/is_class.hpp>
  54. #ifdef BOOST_NO_IS_ABSTRACT
  55. #include <boost/type_traits/is_polymorphic.hpp>
  56. #endif
  57. #endif
  58. namespace boost {
  59. namespace detail{
  60. #ifdef BOOST_IS_ABSTRACT
  61. template <class T>
  62. struct is_abstract_imp
  63. {
  64. BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_ABSTRACT(T));
  65. };
  66. #elif !defined(BOOST_NO_IS_ABSTRACT)
  67. template<class T>
  68. struct is_abstract_imp2
  69. {
  70. // Deduction fails if T is void, function type,
  71. // reference type (14.8.2/2)or an abstract class type
  72. // according to review status issue #337
  73. //
  74. template<class U>
  75. static type_traits::no_type check_sig(U (*)[1]);
  76. template<class U>
  77. static type_traits::yes_type check_sig(...);
  78. //
  79. // T must be a complete type, further if T is a template then
  80. // it must be instantiated in order for us to get the right answer:
  81. //
  82. BOOST_STATIC_ASSERT(sizeof(T) != 0);
  83. // GCC2 won't even parse this template if we embed the computation
  84. // of s1 in the computation of value.
  85. #ifdef __GNUC__
  86. BOOST_STATIC_CONSTANT(std::size_t, s1 = sizeof(is_abstract_imp2<T>::template check_sig<T>(0)));
  87. #else
  88. #if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000)
  89. #pragma warning(push)
  90. #pragma warning(disable:6334)
  91. #endif
  92. BOOST_STATIC_CONSTANT(std::size_t, s1 = sizeof(check_sig<T>(0)));
  93. #if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000)
  94. #pragma warning(pop)
  95. #endif
  96. #endif
  97. BOOST_STATIC_CONSTANT(bool, value =
  98. (s1 == sizeof(type_traits::yes_type)));
  99. };
  100. template <bool v>
  101. struct is_abstract_select
  102. {
  103. template <class T>
  104. struct rebind
  105. {
  106. typedef is_abstract_imp2<T> type;
  107. };
  108. };
  109. template <>
  110. struct is_abstract_select<false>
  111. {
  112. template <class T>
  113. struct rebind
  114. {
  115. typedef false_type type;
  116. };
  117. };
  118. template <class T>
  119. struct is_abstract_imp
  120. {
  121. typedef is_abstract_select< ::boost::is_class<T>::value> selector;
  122. typedef typename selector::template rebind<T> binder;
  123. typedef typename binder::type type;
  124. BOOST_STATIC_CONSTANT(bool, value = type::value);
  125. };
  126. #endif
  127. }
  128. #ifndef BOOST_NO_IS_ABSTRACT
  129. template <class T> struct is_abstract : public integral_constant<bool, ::boost::detail::is_abstract_imp<T>::value> {};
  130. #else
  131. template <class T> struct is_abstract : public integral_constant<bool, ::boost::detail::is_polymorphic_imp<T>::value> {};
  132. #endif
  133. } // namespace boost
  134. #endif //BOOST_TT_IS_ABSTRACT_CLASS_HPP