call_traits.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_pointer.hpp>
  23. #include <boost/detail/workaround.hpp>
  24. namespace boost{
  25. namespace detail{
  26. template <typename T, bool small_>
  27. struct ct_imp2
  28. {
  29. typedef const T& param_type;
  30. };
  31. template <typename T>
  32. struct ct_imp2<T, true>
  33. {
  34. typedef const T param_type;
  35. };
  36. template <typename T, bool isp, bool b1>
  37. struct ct_imp
  38. {
  39. typedef const T& param_type;
  40. };
  41. template <typename T, bool isp>
  42. struct ct_imp<T, isp, true>
  43. {
  44. typedef typename ct_imp2<T, sizeof(T) <= sizeof(void*)>::param_type param_type;
  45. };
  46. template <typename T, bool b1>
  47. struct ct_imp<T, true, b1>
  48. {
  49. typedef const T param_type;
  50. };
  51. }
  52. template <typename T>
  53. struct call_traits
  54. {
  55. public:
  56. typedef T value_type;
  57. typedef T& reference;
  58. typedef const T& const_reference;
  59. //
  60. // C++ Builder workaround: we should be able to define a compile time
  61. // constant and pass that as a single template parameter to ct_imp<T,bool>,
  62. // however compiler bugs prevent this - instead pass three bool's to
  63. // ct_imp<T,bool,bool,bool> and add an extra partial specialisation
  64. // of ct_imp to handle the logic. (JM)
  65. typedef typename boost::detail::ct_imp<
  66. T,
  67. ::boost::is_pointer<T>::value,
  68. ::boost::is_arithmetic<T>::value
  69. >::param_type param_type;
  70. };
  71. template <typename T>
  72. struct call_traits<T&>
  73. {
  74. typedef T& value_type;
  75. typedef T& reference;
  76. typedef const T& const_reference;
  77. typedef T& param_type; // hh removed const
  78. };
  79. #if BOOST_WORKAROUND( __BORLANDC__, < 0x5A0 )
  80. // these are illegal specialisations; cv-qualifies applied to
  81. // references have no effect according to [8.3.2p1],
  82. // C++ Builder requires them though as it treats cv-qualified
  83. // references as distinct types...
  84. template <typename T>
  85. struct call_traits<T&const>
  86. {
  87. typedef T& value_type;
  88. typedef T& reference;
  89. typedef const T& const_reference;
  90. typedef T& param_type; // hh removed const
  91. };
  92. template <typename T>
  93. struct call_traits<T&volatile>
  94. {
  95. typedef T& value_type;
  96. typedef T& reference;
  97. typedef const T& const_reference;
  98. typedef T& param_type; // hh removed const
  99. };
  100. template <typename T>
  101. struct call_traits<T&const volatile>
  102. {
  103. typedef T& value_type;
  104. typedef T& reference;
  105. typedef const T& const_reference;
  106. typedef T& param_type; // hh removed const
  107. };
  108. template <typename T>
  109. struct call_traits< T * >
  110. {
  111. typedef T * value_type;
  112. typedef T * & reference;
  113. typedef T * const & const_reference;
  114. typedef T * const param_type; // hh removed const
  115. };
  116. #endif
  117. #if !defined(BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS)
  118. template <typename T, std::size_t N>
  119. struct call_traits<T [N]>
  120. {
  121. private:
  122. typedef T array_type[N];
  123. public:
  124. // degrades array to pointer:
  125. typedef const T* value_type;
  126. typedef array_type& reference;
  127. typedef const array_type& const_reference;
  128. typedef const T* const param_type;
  129. };
  130. template <typename T, std::size_t N>
  131. struct call_traits<const T [N]>
  132. {
  133. private:
  134. typedef const T array_type[N];
  135. public:
  136. // degrades array to pointer:
  137. typedef const T* value_type;
  138. typedef array_type& reference;
  139. typedef const array_type& const_reference;
  140. typedef const T* const param_type;
  141. };
  142. #endif
  143. }
  144. #endif // BOOST_DETAIL_CALL_TRAITS_HPP