Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame^] | 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 | // Copyright Daniel Walker, Eric Niebler, Michel Morin 2008-2012. |
| 9 | // Use, modification and distribution is subject to the Boost Software |
| 10 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or |
| 11 | // copy at http://www.boost.org/LICENSE_1_0.txt) |
| 12 | |
| 13 | // For more information, see http://www.boost.org/libs/utility |
| 14 | #if !defined(BOOST_PP_IS_ITERATING) |
| 15 | # error Boost result_of - do not include this file! |
| 16 | #endif |
| 17 | |
| 18 | // CWPro8 requires an argument in a function type specialization |
| 19 | #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0 |
| 20 | # define BOOST_RESULT_OF_ARGS void |
| 21 | #else |
| 22 | # define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T) |
| 23 | #endif |
| 24 | |
| 25 | #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) |
| 26 | template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 27 | struct tr1_result_of<F(BOOST_RESULT_OF_ARGS)> |
| 28 | : mpl::if_< |
| 29 | mpl::or_< is_pointer<F>, is_member_function_pointer<F> > |
| 30 | , ndnboost::detail::tr1_result_of_impl< |
| 31 | typename remove_cv<F>::type, |
| 32 | typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS), |
| 33 | (ndnboost::detail::has_result_type<F>::value)> |
| 34 | , ndnboost::detail::tr1_result_of_impl< |
| 35 | F, |
| 36 | F(BOOST_RESULT_OF_ARGS), |
| 37 | (ndnboost::detail::has_result_type<F>::value)> >::type { }; |
| 38 | #endif |
| 39 | |
| 40 | #ifdef BOOST_RESULT_OF_USE_DECLTYPE |
| 41 | |
| 42 | // Uses declval following N3225 20.7.7.6 when F is not a pointer. |
| 43 | template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 44 | struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))> |
| 45 | : mpl::if_< |
| 46 | 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 | #ifdef BOOST_NO_SFINAE_EXPR |
| 60 | |
| 61 | template<typename F> |
| 62 | struct BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION()); |
| 63 | |
| 64 | template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), typename T)> |
| 65 | struct BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<R(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), T))> { |
| 66 | R operator()(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), T)) const; |
| 67 | typedef result_of_private_type const &(*pfn_t)(...); |
| 68 | operator pfn_t() const volatile; |
| 69 | }; |
| 70 | |
| 71 | template<typename F> |
| 72 | struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION()); |
| 73 | |
| 74 | template<typename F> |
| 75 | struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())<F *> |
| 76 | : BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<F> |
| 77 | {}; |
| 78 | |
| 79 | template<typename F> |
| 80 | struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())<F &> |
| 81 | : BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<F> |
| 82 | {}; |
| 83 | |
| 84 | template<typename F> |
| 85 | struct BOOST_PP_CAT(result_of_select_call_wrapper_type_, BOOST_PP_ITERATION()) |
| 86 | : mpl::eval_if< |
| 87 | is_class<typename remove_reference<F>::type>, |
| 88 | result_of_wrap_callable_class<F>, |
| 89 | mpl::identity<BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())<typename remove_cv<F>::type> > |
| 90 | > |
| 91 | {}; |
| 92 | |
| 93 | template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), typename T)> |
| 94 | struct BOOST_PP_CAT(result_of_is_callable_, BOOST_PP_ITERATION()) { |
| 95 | typedef typename BOOST_PP_CAT(result_of_select_call_wrapper_type_, BOOST_PP_ITERATION())<F>::type wrapper_t; |
| 96 | static const bool value = ( |
| 97 | sizeof(result_of_no_type) == sizeof(detail::result_of_is_private_type( |
| 98 | (ndnboost::declval<wrapper_t>()(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), ndnboost::declval<T, >() BOOST_PP_INTERCEPT)), result_of_weird_type()) |
| 99 | )) |
| 100 | ); |
| 101 | typedef mpl::bool_<value> type; |
| 102 | }; |
| 103 | |
| 104 | template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 105 | struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), true> |
| 106 | : lazy_enable_if< |
| 107 | BOOST_PP_CAT(result_of_is_callable_, BOOST_PP_ITERATION())<F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), T)> |
| 108 | , cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false> |
| 109 | > |
| 110 | {}; |
| 111 | |
| 112 | template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 113 | struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false> |
| 114 | { |
| 115 | typedef decltype( |
| 116 | ndnboost::declval<F>()( |
| 117 | BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), ndnboost::declval<T, >() BOOST_PP_INTERCEPT) |
| 118 | ) |
| 119 | ) type; |
| 120 | }; |
| 121 | |
| 122 | #else // BOOST_NO_SFINAE_EXPR |
| 123 | |
| 124 | template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 125 | struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), |
| 126 | typename result_of_always_void<decltype( |
| 127 | ndnboost::declval<F>()( |
| 128 | BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), ndnboost::declval<T, >() BOOST_PP_INTERCEPT) |
| 129 | ) |
| 130 | )>::type> { |
| 131 | typedef decltype( |
| 132 | ndnboost::declval<F>()( |
| 133 | BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), ndnboost::declval<T, >() BOOST_PP_INTERCEPT) |
| 134 | ) |
| 135 | ) type; |
| 136 | }; |
| 137 | |
| 138 | #endif // BOOST_NO_SFINAE_EXPR |
| 139 | |
| 140 | } // namespace detail |
| 141 | |
| 142 | #else // defined(BOOST_RESULT_OF_USE_DECLTYPE) |
| 143 | |
| 144 | #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) |
| 145 | template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 146 | struct result_of<F(BOOST_RESULT_OF_ARGS)> |
| 147 | : tr1_result_of<F(BOOST_RESULT_OF_ARGS)> { }; |
| 148 | #endif |
| 149 | |
| 150 | #endif // defined(BOOST_RESULT_OF_USE_DECLTYPE) |
| 151 | |
| 152 | #undef BOOST_RESULT_OF_ARGS |
| 153 | |
| 154 | #if BOOST_PP_ITERATION() >= 1 |
| 155 | |
| 156 | namespace detail { |
| 157 | |
| 158 | template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 159 | struct tr1_result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false> |
| 160 | { |
| 161 | typedef R type; |
| 162 | }; |
| 163 | |
| 164 | template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 165 | struct tr1_result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false> |
| 166 | { |
| 167 | typedef R type; |
| 168 | }; |
| 169 | |
| 170 | #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) |
| 171 | template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 172 | struct tr1_result_of_impl<R (T0::*) |
| 173 | (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)), |
| 174 | FArgs, false> |
| 175 | { |
| 176 | typedef R type; |
| 177 | }; |
| 178 | |
| 179 | template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 180 | struct tr1_result_of_impl<R (T0::*) |
| 181 | (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) |
| 182 | const, |
| 183 | FArgs, false> |
| 184 | { |
| 185 | typedef R type; |
| 186 | }; |
| 187 | |
| 188 | template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 189 | struct tr1_result_of_impl<R (T0::*) |
| 190 | (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) |
| 191 | volatile, |
| 192 | FArgs, false> |
| 193 | { |
| 194 | typedef R type; |
| 195 | }; |
| 196 | |
| 197 | template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)> |
| 198 | struct tr1_result_of_impl<R (T0::*) |
| 199 | (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) |
| 200 | const volatile, |
| 201 | FArgs, false> |
| 202 | { |
| 203 | typedef R type; |
| 204 | }; |
| 205 | #endif |
| 206 | |
| 207 | } |
| 208 | #endif |