indirect_traits.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // Copyright David Abrahams 2002.
  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 INDIRECT_TRAITS_DWA2002131_HPP
  6. # define INDIRECT_TRAITS_DWA2002131_HPP
  7. # include <boost/type_traits/integral_constant.hpp>
  8. # include <boost/type_traits/is_function.hpp>
  9. # include <boost/type_traits/is_reference.hpp>
  10. # include <boost/type_traits/is_pointer.hpp>
  11. # include <boost/type_traits/is_class.hpp>
  12. # include <boost/type_traits/is_const.hpp>
  13. # include <boost/type_traits/is_volatile.hpp>
  14. # include <boost/type_traits/is_member_function_pointer.hpp>
  15. # include <boost/type_traits/is_member_pointer.hpp>
  16. # include <boost/type_traits/remove_cv.hpp>
  17. # include <boost/type_traits/remove_reference.hpp>
  18. # include <boost/type_traits/remove_pointer.hpp>
  19. # include <boost/detail/workaround.hpp>
  20. # include <boost/detail/select_type.hpp>
  21. namespace boost { namespace detail {
  22. namespace indirect_traits {
  23. template <class T>
  24. struct is_reference_to_const : boost::false_type
  25. {
  26. };
  27. template <class T>
  28. struct is_reference_to_const<T const&> : boost::true_type
  29. {
  30. };
  31. # if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
  32. template<class T>
  33. struct is_reference_to_const<T const volatile&> : boost::true_type
  34. {
  35. };
  36. # endif
  37. template <class T>
  38. struct is_reference_to_function : boost::false_type
  39. {
  40. };
  41. template <class T>
  42. struct is_reference_to_function<T&> : is_function<T>
  43. {
  44. };
  45. template <class T>
  46. struct is_pointer_to_function : boost::false_type
  47. {
  48. };
  49. // There's no such thing as a pointer-to-cv-function, so we don't need
  50. // specializations for those
  51. template <class T>
  52. struct is_pointer_to_function<T*> : is_function<T>
  53. {
  54. };
  55. template <class T>
  56. struct is_reference_to_member_function_pointer_impl : boost::false_type
  57. {
  58. };
  59. template <class T>
  60. struct is_reference_to_member_function_pointer_impl<T&>
  61. : is_member_function_pointer<typename remove_cv<T>::type>
  62. {
  63. };
  64. template <class T>
  65. struct is_reference_to_member_function_pointer
  66. : is_reference_to_member_function_pointer_impl<T>
  67. {
  68. };
  69. template <class T>
  70. struct is_reference_to_function_pointer_aux
  71. : boost::integral_constant<bool,
  72. is_reference<T>::value &&
  73. is_pointer_to_function<
  74. typename remove_cv<
  75. typename remove_reference<T>::type
  76. >::type
  77. >::value
  78. >
  79. {
  80. // There's no such thing as a pointer-to-cv-function, so we don't need specializations for those
  81. };
  82. template <class T>
  83. struct is_reference_to_function_pointer
  84. : boost::detail::if_true<
  85. is_reference_to_function<T>::value
  86. >::template then<
  87. boost::false_type
  88. , is_reference_to_function_pointer_aux<T>
  89. >::type
  90. {
  91. };
  92. template <class T>
  93. struct is_reference_to_non_const
  94. : boost::integral_constant<bool,
  95. is_reference<T>::value &&
  96. !is_reference_to_const<T>::value
  97. >
  98. {
  99. };
  100. template <class T>
  101. struct is_reference_to_volatile : boost::false_type
  102. {
  103. };
  104. template <class T>
  105. struct is_reference_to_volatile<T volatile&> : boost::true_type
  106. {
  107. };
  108. # if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
  109. template <class T>
  110. struct is_reference_to_volatile<T const volatile&> : boost::true_type
  111. {
  112. };
  113. # endif
  114. template <class T>
  115. struct is_reference_to_pointer : boost::false_type
  116. {
  117. };
  118. template <class T>
  119. struct is_reference_to_pointer<T*&> : boost::true_type
  120. {
  121. };
  122. template <class T>
  123. struct is_reference_to_pointer<T* const&> : boost::true_type
  124. {
  125. };
  126. template <class T>
  127. struct is_reference_to_pointer<T* volatile&> : boost::true_type
  128. {
  129. };
  130. template <class T>
  131. struct is_reference_to_pointer<T* const volatile&> : boost::true_type
  132. {
  133. };
  134. template <class T>
  135. struct is_reference_to_class
  136. : boost::integral_constant<bool,
  137. is_reference<T>::value &&
  138. is_class<
  139. typename remove_cv<
  140. typename remove_reference<T>::type
  141. >::type
  142. >::value
  143. >
  144. {
  145. };
  146. template <class T>
  147. struct is_pointer_to_class
  148. : boost::integral_constant<bool,
  149. is_pointer<T>::value &&
  150. is_class<
  151. typename remove_cv<
  152. typename remove_pointer<T>::type
  153. >::type
  154. >::value
  155. >
  156. {
  157. };
  158. }
  159. using namespace indirect_traits;
  160. }} // namespace boost::python::detail
  161. #endif // INDIRECT_TRAITS_DWA2002131_HPP