1 /*============================================================================= 2 Copyright (c) 2007 Tobias Schwinger 3 4 Use modification and distribution are subject to the Boost Software 5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 http://www.boost.org/LICENSE_1_0.txt). 7 ==============================================================================*/ 8 9 #if !defined(BOOST_FUSION_SUPPORT_DEDUCE_HPP_INCLUDED) 10 #define BOOST_FUSION_SUPPORT_DEDUCE_HPP_INCLUDED 11 12 #include <boost/fusion/support/config.hpp> 13 #include <boost/ref.hpp> 14 15 #ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL 16 #include <functional> 17 #endif 18 19 namespace boost { namespace fusion { namespace traits 20 { 21 template <typename T> struct deduce; 22 23 //----- ---- --- -- - - - - 24 25 // Non-references pass unchanged 26 27 template <typename T> 28 struct deduce 29 { 30 typedef T type; 31 }; 32 33 template <typename T> 34 struct deduce<T const> 35 { 36 typedef T type; 37 }; 38 39 template <typename T> 40 struct deduce<T volatile> 41 { 42 typedef T type; 43 }; 44 45 template <typename T> 46 struct deduce<T const volatile> 47 { 48 typedef T type; 49 }; 50 51 // Keep references on mutable LValues 52 53 template <typename T> 54 struct deduce<T &> 55 { 56 typedef T & type; 57 }; 58 59 template <typename T> 60 struct deduce<T volatile&> 61 { 62 typedef T volatile& type; 63 }; 64 65 // Store away potential RValues 66 67 template <typename T> 68 struct deduce<T const&> 69 { 70 typedef T type; 71 }; 72 73 template <typename T> 74 struct deduce<T const volatile&> 75 { 76 typedef T type; 77 }; 78 79 // Unwrap Boost.RefS (referencee cv is deduced) 80 81 template <typename T> 82 struct deduce<reference_wrapper<T> & > 83 { 84 typedef T& type; 85 }; 86 87 template <typename T> 88 struct deduce<reference_wrapper<T> const & > 89 { 90 typedef T& type; 91 }; 92 93 // Also unwrap C++11 std::ref if available (referencee cv is deduced) 94 #ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL 95 template <typename T> 96 struct deduce<std::reference_wrapper<T> &> 97 { 98 typedef T& type; 99 }; 100 101 template <typename T> 102 struct deduce<std::reference_wrapper<T> const &> 103 { 104 typedef T& type; 105 }; 106 #endif 107 108 // Keep references on arrays, even if const 109 110 template <typename T, int N> 111 struct deduce<T(&)[N]> 112 { 113 typedef T(&type)[N]; 114 }; 115 116 template <typename T, int N> 117 struct deduce<volatile T(&)[N]> 118 { 119 typedef volatile T(&type)[N]; 120 }; 121 122 template <typename T, int N> 123 struct deduce<const T(&)[N]> 124 { 125 typedef const T(&type)[N]; 126 }; 127 128 template <typename T, int N> 129 struct deduce<const volatile T(&)[N]> 130 { 131 typedef const volatile T(&type)[N]; 132 }; 133 134 }}} 135 136 #endif 137 138