Chris@16
|
1 // Boost result_of library
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright Douglas Gregor 2004. Use, modification and
|
Chris@16
|
4 // distribution is subject to the Boost Software License, Version
|
Chris@16
|
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7
|
Chris@16
|
8 // For more information, see http://www.boost.org/libs/utility
|
Chris@16
|
9 #ifndef BOOST_RESULT_OF_HPP
|
Chris@16
|
10 #define BOOST_RESULT_OF_HPP
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/config.hpp>
|
Chris@16
|
13 #include <boost/preprocessor/cat.hpp>
|
Chris@16
|
14 #include <boost/preprocessor/iteration/iterate.hpp>
|
Chris@16
|
15 #include <boost/preprocessor/repetition/enum_params.hpp>
|
Chris@16
|
16 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
|
Chris@16
|
17 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
Chris@16
|
18 #include <boost/preprocessor/repetition/enum_shifted_params.hpp>
|
Chris@16
|
19 #include <boost/preprocessor/facilities/intercept.hpp>
|
Chris@16
|
20 #include <boost/detail/workaround.hpp>
|
Chris@16
|
21 #include <boost/mpl/has_xxx.hpp>
|
Chris@16
|
22 #include <boost/mpl/if.hpp>
|
Chris@16
|
23 #include <boost/mpl/eval_if.hpp>
|
Chris@16
|
24 #include <boost/mpl/bool.hpp>
|
Chris@16
|
25 #include <boost/mpl/identity.hpp>
|
Chris@16
|
26 #include <boost/mpl/or.hpp>
|
Chris@16
|
27 #include <boost/type_traits/is_class.hpp>
|
Chris@16
|
28 #include <boost/type_traits/is_pointer.hpp>
|
Chris@16
|
29 #include <boost/type_traits/is_member_function_pointer.hpp>
|
Chris@16
|
30 #include <boost/type_traits/remove_cv.hpp>
|
Chris@16
|
31 #include <boost/type_traits/remove_reference.hpp>
|
Chris@16
|
32 #include <boost/utility/declval.hpp>
|
Chris@16
|
33 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
34
|
Chris@16
|
35 #ifndef BOOST_RESULT_OF_NUM_ARGS
|
Chris@16
|
36 # define BOOST_RESULT_OF_NUM_ARGS 16
|
Chris@16
|
37 #endif
|
Chris@16
|
38
|
Chris@16
|
39 // Use the decltype-based version of result_of by default if the compiler
|
Chris@16
|
40 // supports N3276 <http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2011/n3276.pdf>.
|
Chris@16
|
41 // The user can force the choice by defining BOOST_RESULT_OF_USE_DECLTYPE,
|
Chris@16
|
42 // BOOST_RESULT_OF_USE_TR1, or BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK but not more than one!
|
Chris@16
|
43 #if (defined(BOOST_RESULT_OF_USE_DECLTYPE) && defined(BOOST_RESULT_OF_USE_TR1)) || \
|
Chris@16
|
44 (defined(BOOST_RESULT_OF_USE_DECLTYPE) && defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK)) || \
|
Chris@16
|
45 (defined(BOOST_RESULT_OF_USE_TR1) && defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK))
|
Chris@16
|
46 # error More than one of BOOST_RESULT_OF_USE_DECLTYPE, BOOST_RESULT_OF_USE_TR1 and \
|
Chris@16
|
47 BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK cannot be defined at the same time.
|
Chris@16
|
48 #endif
|
Chris@16
|
49
|
Chris@16
|
50 #if defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK) && defined(BOOST_MPL_CFG_NO_HAS_XXX_TEMPLATE)
|
Chris@16
|
51 # error Cannot fallback to decltype if BOOST_MPL_CFG_NO_HAS_XXX_TEMPLATE is not defined.
|
Chris@16
|
52 #endif
|
Chris@16
|
53
|
Chris@16
|
54 #ifndef BOOST_RESULT_OF_USE_TR1
|
Chris@16
|
55 # ifndef BOOST_RESULT_OF_USE_DECLTYPE
|
Chris@16
|
56 # ifndef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
|
Chris@16
|
57 # ifndef BOOST_NO_CXX11_DECLTYPE_N3276 // this implies !defined(BOOST_NO_CXX11_DECLTYPE)
|
Chris@16
|
58 # define BOOST_RESULT_OF_USE_DECLTYPE
|
Chris@16
|
59 # else
|
Chris@16
|
60 # define BOOST_RESULT_OF_USE_TR1
|
Chris@16
|
61 # endif
|
Chris@16
|
62 # endif
|
Chris@16
|
63 # endif
|
Chris@16
|
64 #endif
|
Chris@16
|
65
|
Chris@16
|
66 namespace boost {
|
Chris@16
|
67
|
Chris@16
|
68 template<typename F> struct result_of;
|
Chris@16
|
69 template<typename F> struct tr1_result_of; // a TR1-style implementation of result_of
|
Chris@16
|
70
|
Chris@16
|
71 #if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
Chris@16
|
72 namespace detail {
|
Chris@16
|
73
|
Chris@16
|
74 BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
|
Chris@16
|
75
|
Chris@16
|
76 BOOST_MPL_HAS_XXX_TEMPLATE_DEF(result)
|
Chris@16
|
77
|
Chris@16
|
78 template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl;
|
Chris@16
|
79
|
Chris@16
|
80 template<typename F> struct cpp0x_result_of;
|
Chris@16
|
81
|
Chris@16
|
82 #ifdef BOOST_NO_SFINAE_EXPR
|
Chris@16
|
83
|
Chris@16
|
84 // There doesn't seem to be any other way to turn this off such that the presence of
|
Chris@16
|
85 // the user-defined operator,() below doesn't cause spurious warning all over the place,
|
Chris@16
|
86 // so unconditionally turn it off.
|
Chris@16
|
87 #if BOOST_MSVC
|
Chris@16
|
88 # pragma warning(disable: 4913) // user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used
|
Chris@16
|
89 #endif
|
Chris@16
|
90
|
Chris@16
|
91 struct result_of_private_type {};
|
Chris@16
|
92
|
Chris@16
|
93 struct result_of_weird_type {
|
Chris@16
|
94 friend result_of_private_type operator,(result_of_private_type, result_of_weird_type);
|
Chris@16
|
95 };
|
Chris@16
|
96
|
Chris@16
|
97 typedef char result_of_yes_type; // sizeof(result_of_yes_type) == 1
|
Chris@16
|
98 typedef char (&result_of_no_type)[2]; // sizeof(result_of_no_type) == 2
|
Chris@16
|
99
|
Chris@16
|
100 template<typename T>
|
Chris@16
|
101 result_of_no_type result_of_is_private_type(T const &);
|
Chris@16
|
102 result_of_yes_type result_of_is_private_type(result_of_private_type);
|
Chris@16
|
103
|
Chris@16
|
104 template<typename C>
|
Chris@16
|
105 struct result_of_callable_class : C {
|
Chris@16
|
106 result_of_callable_class();
|
Chris@16
|
107 typedef result_of_private_type const &(*pfn_t)(...);
|
Chris@16
|
108 operator pfn_t() const volatile;
|
Chris@16
|
109 };
|
Chris@16
|
110
|
Chris@16
|
111 template<typename C>
|
Chris@16
|
112 struct result_of_wrap_callable_class {
|
Chris@16
|
113 typedef result_of_callable_class<C> type;
|
Chris@16
|
114 };
|
Chris@16
|
115
|
Chris@16
|
116 template<typename C>
|
Chris@16
|
117 struct result_of_wrap_callable_class<C const> {
|
Chris@16
|
118 typedef result_of_callable_class<C> const type;
|
Chris@16
|
119 };
|
Chris@16
|
120
|
Chris@16
|
121 template<typename C>
|
Chris@16
|
122 struct result_of_wrap_callable_class<C volatile> {
|
Chris@16
|
123 typedef result_of_callable_class<C> volatile type;
|
Chris@16
|
124 };
|
Chris@16
|
125
|
Chris@16
|
126 template<typename C>
|
Chris@16
|
127 struct result_of_wrap_callable_class<C const volatile> {
|
Chris@16
|
128 typedef result_of_callable_class<C> const volatile type;
|
Chris@16
|
129 };
|
Chris@16
|
130
|
Chris@16
|
131 template<typename C>
|
Chris@16
|
132 struct result_of_wrap_callable_class<C &> {
|
Chris@16
|
133 typedef typename result_of_wrap_callable_class<C>::type &type;
|
Chris@16
|
134 };
|
Chris@16
|
135
|
Chris@16
|
136 template<typename F, bool TestCallability = true> struct cpp0x_result_of_impl;
|
Chris@16
|
137
|
Chris@16
|
138 #else // BOOST_NO_SFINAE_EXPR
|
Chris@16
|
139
|
Chris@16
|
140 template<typename T>
|
Chris@16
|
141 struct result_of_always_void
|
Chris@16
|
142 {
|
Chris@16
|
143 typedef void type;
|
Chris@16
|
144 };
|
Chris@16
|
145
|
Chris@16
|
146 template<typename F, typename Enable = void> struct cpp0x_result_of_impl {};
|
Chris@16
|
147
|
Chris@16
|
148 #endif // BOOST_NO_SFINAE_EXPR
|
Chris@16
|
149
|
Chris@16
|
150 template<typename F>
|
Chris@16
|
151 struct result_of_void_impl
|
Chris@16
|
152 {
|
Chris@16
|
153 typedef void type;
|
Chris@16
|
154 };
|
Chris@16
|
155
|
Chris@16
|
156 template<typename R>
|
Chris@16
|
157 struct result_of_void_impl<R (*)(void)>
|
Chris@16
|
158 {
|
Chris@16
|
159 typedef R type;
|
Chris@16
|
160 };
|
Chris@16
|
161
|
Chris@16
|
162 template<typename R>
|
Chris@16
|
163 struct result_of_void_impl<R (&)(void)>
|
Chris@16
|
164 {
|
Chris@16
|
165 typedef R type;
|
Chris@16
|
166 };
|
Chris@16
|
167
|
Chris@16
|
168 // Determine the return type of a function pointer or pointer to member.
|
Chris@16
|
169 template<typename F, typename FArgs>
|
Chris@16
|
170 struct result_of_pointer
|
Chris@16
|
171 : tr1_result_of_impl<typename remove_cv<F>::type, FArgs, false> { };
|
Chris@16
|
172
|
Chris@16
|
173 template<typename F, typename FArgs>
|
Chris@16
|
174 struct tr1_result_of_impl<F, FArgs, true>
|
Chris@16
|
175 {
|
Chris@16
|
176 typedef typename F::result_type type;
|
Chris@16
|
177 };
|
Chris@16
|
178
|
Chris@16
|
179 template<typename FArgs>
|
Chris@16
|
180 struct is_function_with_no_args : mpl::false_ {};
|
Chris@16
|
181
|
Chris@16
|
182 template<typename F>
|
Chris@16
|
183 struct is_function_with_no_args<F(void)> : mpl::true_ {};
|
Chris@16
|
184
|
Chris@16
|
185 template<typename F, typename FArgs>
|
Chris@16
|
186 struct result_of_nested_result : F::template result<FArgs>
|
Chris@16
|
187 {};
|
Chris@16
|
188
|
Chris@16
|
189 template<typename F, typename FArgs>
|
Chris@16
|
190 struct tr1_result_of_impl<F, FArgs, false>
|
Chris@16
|
191 : mpl::if_<is_function_with_no_args<FArgs>,
|
Chris@16
|
192 result_of_void_impl<F>,
|
Chris@16
|
193 result_of_nested_result<F, FArgs> >::type
|
Chris@16
|
194 {};
|
Chris@16
|
195
|
Chris@16
|
196 } // end namespace detail
|
Chris@16
|
197
|
Chris@16
|
198 #define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,<boost/utility/detail/result_of_iterate.hpp>))
|
Chris@16
|
199 #include BOOST_PP_ITERATE()
|
Chris@16
|
200
|
Chris@16
|
201 #else
|
Chris@16
|
202 # define BOOST_NO_RESULT_OF 1
|
Chris@16
|
203 #endif
|
Chris@16
|
204
|
Chris@16
|
205 }
|
Chris@16
|
206
|
Chris@16
|
207 #endif // BOOST_RESULT_OF_HPP
|