call_traits.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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/utility for most recent version including documentation.
  7. // call_traits: defines typedefs for function usage
  8. // (see libs/utility/call_traits.htm)
  9. /* Release notes:
  10. 23rd July 2000:
  11. Fixed array specialization. (JM)
  12. Added Borland specific fixes for reference types
  13. (issue raised by Steve Cleary).
  14. */
  15. #ifndef BOOST_DETAIL_CALL_TRAITS_HPP
  16. #define BOOST_DETAIL_CALL_TRAITS_HPP
  17. #ifndef BOOST_CONFIG_HPP
  18. #include <boost/config.hpp>
  19. #endif
  20. #include <cstddef>
  21. #include <boost/type_traits/is_arithmetic.hpp>
  22. #include <boost/type_traits/is_enum.hpp>
  23. #include <boost/type_traits/is_pointer.hpp>
  24. #include <boost/detail/workaround.hpp>
  25. namespace boost{
  26. namespace detail{
  27. template <typename T, bool small_>
  28. struct ct_imp2
  29. {
  30. typedef const T& param_type;
  31. };
  32. template <typename T>
  33. struct ct_imp2<T, true>
  34. {
  35. typedef const T param_type;
  36. };
  37. template <typename T, bool isp, bool b1, bool b2>
  38. struct ct_imp
  39. {
  40. typedef const T& param_type;
  41. };
  42. template <typename T, bool isp, bool b2>
  43. struct ct_imp<T, isp, true, b2>
  44. {
  45. typedef typename ct_imp2<T, sizeof(T) <= sizeof(void*)>::param_type param_type;
  46. };
  47. template <typename T, bool isp, bool b1>
  48. struct ct_imp<T, isp, b1, true>
  49. {
  50. typedef typename ct_imp2<T, sizeof(T) <= sizeof(void*)>::param_type param_type;
  51. };
  52. template <typename T, bool b1, bool b2>
  53. struct ct_imp<T, true, b1, b2>
  54. {
  55. typedef const T param_type;
  56. };
  57. }
  58. template <typename T>
  59. struct call_traits
  60. {
  61. public:
  62. typedef T value_type;
  63. typedef T& reference;
  64. typedef const T& const_reference;
  65. //
  66. // C++ Builder workaround: we should be able to define a compile time
  67. // constant and pass that as a single template parameter to ct_imp<T,bool>,
  68. // however compiler bugs prevent this - instead pass three bool's to
  69. // ct_imp<T,bool,bool,bool> and add an extra partial specialisation
  70. // of ct_imp to handle the logic. (JM)
  71. typedef typename boost::detail::ct_imp<
  72. T,
  73. ::boost::is_pointer<T>::value,
  74. ::boost::is_arithmetic<T>::value,
  75. ::boost::is_enum<T>::value
  76. >::param_type param_type;
  77. };
  78. template <typename T>
  79. struct call_traits<T&>
  80. {
  81. typedef T& value_type;
  82. typedef T& reference;
  83. typedef const T& const_reference;
  84. typedef T& param_type; // hh removed const
  85. };
  86. #if BOOST_WORKAROUND( BOOST_BORLANDC, < 0x5A0 )
  87. // these are illegal specialisations; cv-qualifies applied to
  88. // references have no effect according to [8.3.2p1],
  89. // C++ Builder requires them though as it treats cv-qualified
  90. // references as distinct types...
  91. template <typename T>
  92. struct call_traits<T&const>
  93. {
  94. typedef T& value_type;
  95. typedef T& reference;
  96. typedef const T& const_reference;
  97. typedef T& param_type; // hh removed const
  98. };
  99. template <typename T>
  100. struct call_traits<T&volatile>
  101. {
  102. typedef T& value_type;
  103. typedef T& reference;
  104. typedef const T& const_reference;
  105. typedef T& param_type; // hh removed const
  106. };
  107. template <typename T>
  108. struct call_traits<T&const volatile>
  109. {
  110. typedef T& value_type;
  111. typedef T& reference;
  112. typedef const T& const_reference;
  113. typedef T& param_type; // hh removed const
  114. };
  115. template <typename T>
  116. struct call_traits< T * >
  117. {
  118. typedef T * value_type;
  119. typedef T * & reference;
  120. typedef T * const & const_reference;
  121. typedef T * const param_type; // hh removed const
  122. };
  123. #endif
  124. #if !defined(BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS)
  125. template <typename T, std::size_t N>
  126. struct call_traits<T [N]>
  127. {
  128. private:
  129. typedef T array_type[N];
  130. public:
  131. // degrades array to pointer:
  132. typedef const T* value_type;
  133. typedef array_type& reference;
  134. typedef const array_type& const_reference;
  135. typedef const T* const param_type;
  136. };
  137. template <typename T, std::size_t N>
  138. struct call_traits<const T [N]>
  139. {
  140. private:
  141. typedef const T array_type[N];
  142. public:
  143. // degrades array to pointer:
  144. typedef const T* value_type;
  145. typedef array_type& reference;
  146. typedef const array_type& const_reference;
  147. typedef const T* const param_type;
  148. };
  149. #endif
  150. }
  151. #endif // BOOST_DETAIL_CALL_TRAITS_HPP