ob_call_traits.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. //
  8. // Crippled version for crippled compilers:
  9. // see libs/utility/call_traits.htm
  10. //
  11. /* Release notes:
  12. 01st October 2000:
  13. Fixed call_traits on VC6, using "poor man's partial specialisation",
  14. using ideas taken from "Generative programming" by Krzysztof Czarnecki
  15. & Ulrich Eisenecker.
  16. */
  17. #ifndef BOOST_OB_CALL_TRAITS_HPP
  18. #define BOOST_OB_CALL_TRAITS_HPP
  19. #ifndef BOOST_CONFIG_HPP
  20. #include <boost/config.hpp>
  21. #endif
  22. #ifndef BOOST_ARITHMETIC_TYPE_TRAITS_HPP
  23. #include <boost/type_traits/arithmetic_traits.hpp>
  24. #endif
  25. #ifndef BOOST_COMPOSITE_TYPE_TRAITS_HPP
  26. #include <boost/type_traits/composite_traits.hpp>
  27. #endif
  28. namespace boost{
  29. #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
  30. //
  31. // use member templates to emulate
  32. // partial specialisation:
  33. //
  34. namespace detail{
  35. template <class T>
  36. struct standard_call_traits
  37. {
  38. typedef T value_type;
  39. typedef T& reference;
  40. typedef const T& const_reference;
  41. typedef const T& param_type;
  42. };
  43. template <class T>
  44. struct simple_call_traits
  45. {
  46. typedef T value_type;
  47. typedef T& reference;
  48. typedef const T& const_reference;
  49. typedef const T param_type;
  50. };
  51. template <class T>
  52. struct reference_call_traits
  53. {
  54. typedef T value_type;
  55. typedef T reference;
  56. typedef T const_reference;
  57. typedef T param_type;
  58. };
  59. template <bool pointer, bool arithmetic, bool reference>
  60. struct call_traits_chooser
  61. {
  62. template <class T>
  63. struct rebind
  64. {
  65. typedef standard_call_traits<T> type;
  66. };
  67. };
  68. template <>
  69. struct call_traits_chooser<true, false, false>
  70. {
  71. template <class T>
  72. struct rebind
  73. {
  74. typedef simple_call_traits<T> type;
  75. };
  76. };
  77. template <>
  78. struct call_traits_chooser<false, false, true>
  79. {
  80. template <class T>
  81. struct rebind
  82. {
  83. typedef reference_call_traits<T> type;
  84. };
  85. };
  86. template <bool size_is_small>
  87. struct call_traits_sizeof_chooser2
  88. {
  89. template <class T>
  90. struct small_rebind
  91. {
  92. typedef simple_call_traits<T> small_type;
  93. };
  94. };
  95. template<>
  96. struct call_traits_sizeof_chooser2<false>
  97. {
  98. template <class T>
  99. struct small_rebind
  100. {
  101. typedef standard_call_traits<T> small_type;
  102. };
  103. };
  104. template <>
  105. struct call_traits_chooser<false, true, false>
  106. {
  107. template <class T>
  108. struct rebind
  109. {
  110. enum { sizeof_choice = (sizeof(T) <= sizeof(void*)) };
  111. typedef call_traits_sizeof_chooser2<(sizeof(T) <= sizeof(void*))> chooser;
  112. typedef typename chooser::template small_rebind<T> bound_type;
  113. typedef typename bound_type::small_type type;
  114. };
  115. };
  116. } // namespace detail
  117. template <typename T>
  118. struct call_traits
  119. {
  120. private:
  121. typedef detail::call_traits_chooser<
  122. ::boost::is_pointer<T>::value,
  123. ::boost::is_arithmetic<T>::value,
  124. ::boost::is_reference<T>::value
  125. > chooser;
  126. typedef typename chooser::template rebind<T> bound_type;
  127. typedef typename bound_type::type call_traits_type;
  128. public:
  129. typedef typename call_traits_type::value_type value_type;
  130. typedef typename call_traits_type::reference reference;
  131. typedef typename call_traits_type::const_reference const_reference;
  132. typedef typename call_traits_type::param_type param_type;
  133. };
  134. #else
  135. //
  136. // sorry call_traits is completely non-functional
  137. // blame your broken compiler:
  138. //
  139. template <typename T>
  140. struct call_traits
  141. {
  142. typedef T value_type;
  143. typedef T& reference;
  144. typedef const T& const_reference;
  145. typedef const T& param_type;
  146. };
  147. #endif // member templates
  148. }
  149. #endif // BOOST_OB_CALL_TRAITS_HPP