1 | // Boost result_of library |
---|
2 | |
---|
3 | // Copyright Douglas Gregor 2004. Use, modification and |
---|
4 | // distribution is subject to the Boost Software License, Version |
---|
5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
6 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | |
---|
8 | // For more information, see http://www.boost.org/libs/utility |
---|
9 | #if !defined(BOOST_PP_IS_ITERATING) |
---|
10 | # error Boost result_of - do not include this file! |
---|
11 | #endif |
---|
12 | |
---|
13 | // CWPro8 requires an argument in a function type specialization |
---|
14 | #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0 |
---|
15 | # define BOOST_RESULT_OF_ARGS void |
---|
16 | #else |
---|
17 | # define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T) |
---|
18 | #endif |
---|
19 | |
---|
20 | #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) |
---|
21 | template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
22 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
23 | struct tr1_result_of<F(BOOST_RESULT_OF_ARGS)> |
---|
24 | : mpl::if_< |
---|
25 | mpl::or_< is_pointer<F>, is_member_function_pointer<F> > |
---|
26 | , boost::detail::tr1_result_of_impl< |
---|
27 | typename remove_cv<F>::type, |
---|
28 | typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS), |
---|
29 | (boost::detail::has_result_type<F>::value)> |
---|
30 | , boost::detail::tr1_result_of_impl< |
---|
31 | F, |
---|
32 | F(BOOST_RESULT_OF_ARGS), |
---|
33 | (boost::detail::has_result_type<F>::value)> >::type { }; |
---|
34 | #endif |
---|
35 | |
---|
36 | #if !defined(BOOST_NO_DECLTYPE) && defined(BOOST_RESULT_OF_USE_DECLTYPE) |
---|
37 | |
---|
38 | // As of N2588, C++0x result_of only supports function call |
---|
39 | // expressions of the form f(x). This precludes support for member |
---|
40 | // function pointers, which are invoked with expressions of the form |
---|
41 | // o->*f(x). This implementation supports both. |
---|
42 | template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
43 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
44 | struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))> |
---|
45 | : mpl::if_< |
---|
46 | mpl::or_< is_pointer<F>, is_member_function_pointer<F> > |
---|
47 | , detail::tr1_result_of_impl< |
---|
48 | typename remove_cv<F>::type, |
---|
49 | typename remove_cv<F>::type(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false |
---|
50 | > |
---|
51 | , detail::cpp0x_result_of_impl< |
---|
52 | F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)) |
---|
53 | > |
---|
54 | >::type |
---|
55 | {}; |
---|
56 | |
---|
57 | namespace detail { |
---|
58 | |
---|
59 | # define BOOST_RESULT_OF_STATIC_MEMBERS(z, n, _) \ |
---|
60 | static T ## n t ## n; \ |
---|
61 | /**/ |
---|
62 | |
---|
63 | template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
64 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
65 | class cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))> |
---|
66 | { |
---|
67 | static F f; |
---|
68 | BOOST_PP_REPEAT(BOOST_PP_ITERATION(), BOOST_RESULT_OF_STATIC_MEMBERS, _) |
---|
69 | public: |
---|
70 | typedef decltype(f(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),t))) type; |
---|
71 | }; |
---|
72 | |
---|
73 | } // namespace detail |
---|
74 | |
---|
75 | #else // defined(BOOST_NO_DECLTYPE) |
---|
76 | |
---|
77 | #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) |
---|
78 | template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
79 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
80 | struct result_of<F(BOOST_RESULT_OF_ARGS)> |
---|
81 | : tr1_result_of<F(BOOST_RESULT_OF_ARGS)> { }; |
---|
82 | #endif |
---|
83 | |
---|
84 | #endif // defined(BOOST_NO_DECLTYPE) |
---|
85 | |
---|
86 | #undef BOOST_RESULT_OF_ARGS |
---|
87 | |
---|
88 | #if BOOST_PP_ITERATION() >= 1 |
---|
89 | |
---|
90 | namespace detail { |
---|
91 | |
---|
92 | template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
93 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
94 | struct tr1_result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false> |
---|
95 | { |
---|
96 | typedef R type; |
---|
97 | }; |
---|
98 | |
---|
99 | template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
100 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
101 | struct tr1_result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false> |
---|
102 | { |
---|
103 | typedef R type; |
---|
104 | }; |
---|
105 | |
---|
106 | #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) |
---|
107 | template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
108 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
109 | struct tr1_result_of_impl<R (T0::*) |
---|
110 | (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)), |
---|
111 | FArgs, false> |
---|
112 | { |
---|
113 | typedef R type; |
---|
114 | }; |
---|
115 | |
---|
116 | template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
117 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
118 | struct tr1_result_of_impl<R (T0::*) |
---|
119 | (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) |
---|
120 | const, |
---|
121 | FArgs, false> |
---|
122 | { |
---|
123 | typedef R type; |
---|
124 | }; |
---|
125 | |
---|
126 | template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
127 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
128 | struct tr1_result_of_impl<R (T0::*) |
---|
129 | (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) |
---|
130 | volatile, |
---|
131 | FArgs, false> |
---|
132 | { |
---|
133 | typedef R type; |
---|
134 | }; |
---|
135 | |
---|
136 | template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) |
---|
137 | BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> |
---|
138 | struct tr1_result_of_impl<R (T0::*) |
---|
139 | (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) |
---|
140 | const volatile, |
---|
141 | FArgs, false> |
---|
142 | { |
---|
143 | typedef R type; |
---|
144 | }; |
---|
145 | #endif |
---|
146 | |
---|
147 | } |
---|
148 | #endif |
---|