deduce.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/fusion/support/config.hpp>
  10. #include <boost/ref.hpp>
  11. #ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
  12. #include <functional>
  13. #endif
  14. namespace boost { namespace fusion { namespace traits
  15. {
  16. template <typename T> struct deduce;
  17. //----- ---- --- -- - - - -
  18. // Non-references pass unchanged
  19. template <typename T>
  20. struct deduce
  21. {
  22. typedef T type;
  23. };
  24. template <typename T>
  25. struct deduce<T const>
  26. {
  27. typedef T type;
  28. };
  29. template <typename T>
  30. struct deduce<T volatile>
  31. {
  32. typedef T type;
  33. };
  34. template <typename T>
  35. struct deduce<T const volatile>
  36. {
  37. typedef T type;
  38. };
  39. // Keep references on mutable LValues
  40. template <typename T>
  41. struct deduce<T &>
  42. {
  43. typedef T & type;
  44. };
  45. template <typename T>
  46. struct deduce<T volatile&>
  47. {
  48. typedef T volatile& type;
  49. };
  50. // Store away potential RValues
  51. template <typename T>
  52. struct deduce<T const&>
  53. {
  54. typedef T type;
  55. };
  56. template <typename T>
  57. struct deduce<T const volatile&>
  58. {
  59. typedef T type;
  60. };
  61. // Unwrap Boost.RefS (referencee cv is deduced)
  62. template <typename T>
  63. struct deduce<reference_wrapper<T> & >
  64. {
  65. typedef T& type;
  66. };
  67. template <typename T>
  68. struct deduce<reference_wrapper<T> const & >
  69. {
  70. typedef T& type;
  71. };
  72. // Also unwrap C++11 std::ref if available (referencee cv is deduced)
  73. #ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
  74. template <typename T>
  75. struct deduce<std::reference_wrapper<T> &>
  76. {
  77. typedef T& type;
  78. };
  79. template <typename T>
  80. struct deduce<std::reference_wrapper<T> const &>
  81. {
  82. typedef T& type;
  83. };
  84. #endif
  85. // Keep references on arrays, even if const
  86. template <typename T, int N>
  87. struct deduce<T(&)[N]>
  88. {
  89. typedef T(&type)[N];
  90. };
  91. template <typename T, int N>
  92. struct deduce<volatile T(&)[N]>
  93. {
  94. typedef volatile T(&type)[N];
  95. };
  96. template <typename T, int N>
  97. struct deduce<const T(&)[N]>
  98. {
  99. typedef const T(&type)[N];
  100. };
  101. template <typename T, int N>
  102. struct deduce<const volatile T(&)[N]>
  103. {
  104. typedef const volatile T(&type)[N];
  105. };
  106. }}}
  107. #endif