deduce.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*=============================================================================
  2. Copyright (c) 2007 Tobias Schwinger
  3. Use modification and distribution are subject to the Boost Software
  4. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ==============================================================================*/
  7. #if !defined(BOOST_FUSION_SUPPORT_DEDUCE_HPP_INCLUDED)
  8. #define BOOST_FUSION_SUPPORT_DEDUCE_HPP_INCLUDED
  9. #include <boost/ref.hpp>
  10. namespace boost { namespace fusion { namespace traits
  11. {
  12. template <typename T> struct deduce;
  13. //----- ---- --- -- - - - -
  14. // Non-references pass unchanged
  15. template <typename T>
  16. struct deduce
  17. {
  18. typedef T type;
  19. };
  20. template <typename T>
  21. struct deduce<T const>
  22. {
  23. typedef T type;
  24. };
  25. template <typename T>
  26. struct deduce<T volatile>
  27. {
  28. typedef T type;
  29. };
  30. template <typename T>
  31. struct deduce<T const volatile>
  32. {
  33. typedef T type;
  34. };
  35. // Keep references on mutable LValues
  36. template <typename T>
  37. struct deduce<T &>
  38. {
  39. typedef T & type;
  40. };
  41. template <typename T>
  42. struct deduce<T volatile&>
  43. {
  44. typedef T volatile& type;
  45. };
  46. // Store away potential RValues
  47. template <typename T>
  48. struct deduce<T const&>
  49. {
  50. typedef T type;
  51. };
  52. template <typename T>
  53. struct deduce<T const volatile&>
  54. {
  55. typedef T type;
  56. };
  57. // Unwrap Boost.RefS (referencee cv is deduced)
  58. template <typename T>
  59. struct deduce<reference_wrapper<T> & >
  60. {
  61. typedef T& type;
  62. };
  63. template <typename T>
  64. struct deduce<reference_wrapper<T> const & >
  65. {
  66. typedef T& type;
  67. };
  68. // Keep references on arrays, even if const
  69. template <typename T, int N>
  70. struct deduce<T(&)[N]>
  71. {
  72. typedef T(&type)[N];
  73. };
  74. template <typename T, int N>
  75. struct deduce<volatile T(&)[N]>
  76. {
  77. typedef volatile T(&type)[N];
  78. };
  79. template <typename T, int N>
  80. struct deduce<const T(&)[N]>
  81. {
  82. typedef const T(&type)[N];
  83. };
  84. template <typename T, int N>
  85. struct deduce<const volatile T(&)[N]>
  86. {
  87. typedef const volatile T(&type)[N];
  88. };
  89. }}}
  90. #endif