Ticket #4084: tr1_result_of.patch
File tr1_result_of.patch, 13.7 KB (added by , 13 years ago) |
---|
-
boost/utility/detail/result_of_iterate.hpp
10 10 # error Boost result_of - do not include this file! 11 11 #endif 12 12 13 #if defined(BOOST_HAS_DECLTYPE) 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 14 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 15 38 // As of N2588, C++0x result_of only supports function call 16 39 // expressions of the form f(x). This precludes support for member 17 40 // function pointers, which are invoked with expressions of the form … … 21 44 struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))> 22 45 : mpl::if_< 23 46 mpl::or_< is_pointer<F>, is_member_function_pointer<F> > 24 , detail:: result_of_impl<47 , detail::tr1_result_of_impl< 25 48 typename remove_cv<F>::type, 26 49 typename remove_cv<F>::type(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false 27 50 > 28 , detail:: result_of_decltype_impl<51 , detail::cpp0x_result_of_impl< 29 52 F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)) 30 53 > 31 54 >::type … … 39 62 40 63 template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) 41 64 BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> 42 class result_of_decltype_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>65 class cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))> 43 66 { 44 67 static F f; 45 68 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), BOOST_RESULT_OF_STATIC_MEMBERS, _) … … 51 74 52 75 #else // defined(BOOST_NO_DECLTYPE) 53 76 54 // CWPro8 requires an argument in a function type specialization55 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 056 # define BOOST_RESULT_OF_ARGS void57 #else58 # define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)59 #endif60 61 77 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) 62 78 template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) 63 79 BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> 64 80 struct result_of<F(BOOST_RESULT_OF_ARGS)> 65 : mpl::if_< 66 mpl::or_< is_pointer<F>, is_member_function_pointer<F> > 67 , boost::detail::result_of_impl< 68 typename remove_cv<F>::type, 69 typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS), 70 (boost::detail::has_result_type<F>::value)> 71 , boost::detail::result_of_impl< 72 F, 73 F(BOOST_RESULT_OF_ARGS), 74 (boost::detail::has_result_type<F>::value)> >::type { }; 81 : tr1_result_of<F(BOOST_RESULT_OF_ARGS)> { }; 75 82 #endif 76 83 84 #endif // defined(BOOST_NO_DECLTYPE) 85 77 86 #undef BOOST_RESULT_OF_ARGS 78 87 79 #endif // defined(BOOST_NO_DECLTYPE)80 81 88 #if BOOST_PP_ITERATION() >= 1 82 89 83 90 namespace detail { 84 91 85 92 template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) 86 93 BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> 87 struct result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>94 struct tr1_result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false> 88 95 { 89 96 typedef R type; 90 97 }; 91 98 92 99 template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) 93 100 BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> 94 struct result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>101 struct tr1_result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false> 95 102 { 96 103 typedef R type; 97 104 }; … … 99 106 #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) 100 107 template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) 101 108 BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> 102 struct result_of_impl<R (T0::*)109 struct tr1_result_of_impl<R (T0::*) 103 110 (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)), 104 111 FArgs, false> 105 112 { … … 108 115 109 116 template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) 110 117 BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> 111 struct result_of_impl<R (T0::*)118 struct tr1_result_of_impl<R (T0::*) 112 119 (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) 113 120 const, 114 121 FArgs, false> … … 118 125 119 126 template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) 120 127 BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> 121 struct result_of_impl<R (T0::*)128 struct tr1_result_of_impl<R (T0::*) 122 129 (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) 123 130 volatile, 124 131 FArgs, false> … … 128 135 129 136 template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) 130 137 BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> 131 struct result_of_impl<R (T0::*)138 struct tr1_result_of_impl<R (T0::*) 132 139 (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) 133 140 const volatile, 134 141 FArgs, false> -
boost/utility/result_of.hpp
30 30 namespace boost { 31 31 32 32 template<typename F> struct result_of; 33 template<typename F> struct tr1_result_of; // a TR1-style implementation of result_of 33 34 34 35 #if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) 35 36 namespace detail { 36 37 37 38 BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type) 38 39 39 template<typename F, typename FArgs, bool HasResultType> struct result_of_impl;40 template<typename F> struct result_of_decltype_impl;40 template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl; 41 template<typename F> struct cpp0x_result_of_impl; 41 42 42 43 template<typename F> 43 44 struct result_of_void_impl … … 60 61 // Determine the return type of a function pointer or pointer to member. 61 62 template<typename F, typename FArgs> 62 63 struct result_of_pointer 63 : result_of_impl<typename remove_cv<F>::type, FArgs, false> { };64 : tr1_result_of_impl<typename remove_cv<F>::type, FArgs, false> { }; 64 65 65 66 template<typename F, typename FArgs> 66 struct result_of_impl<F, FArgs, true>67 struct tr1_result_of_impl<F, FArgs, true> 67 68 { 68 69 typedef typename F::result_type type; 69 70 }; … … 79 80 {}; 80 81 81 82 template<typename F, typename FArgs> 82 struct result_of_impl<F, FArgs, false>83 struct tr1_result_of_impl<F, FArgs, false> 83 84 : mpl::if_<is_function_with_no_args<FArgs>, 84 85 result_of_void_impl<F>, 85 86 result_of_nested_result<F, FArgs> >::type -
boost/tr1/functional.hpp
48 48 49 49 namespace std{ namespace tr1{ 50 50 51 using ::boost::result_of; 51 template<class F> 52 struct result_of 53 : ::boost::tr1_result_of<F> 54 {}; 52 55 53 56 } } 54 57 -
libs/utility/test/result_of_test.cpp
5 5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 6 // http://www.boost.org/LICENSE_1_0.txt) 7 7 8 #define BOOST_RESULT_OF_USE_DECLTYPE 9 8 10 // For more information, see http://www.boost.org/libs/utility 9 11 #include <boost/utility/result_of.hpp> 10 12 #include <utility> … … 131 133 BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(double)>::type, int>::value)); 132 134 BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of_template<void>(double)>::type, int>::value)); 133 135 136 BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type(float)>::type, int>::value)); 137 BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of(double)>::type, int>::value)); 138 BOOST_STATIC_ASSERT((is_same<tr1_result_of<const int_result_of(double)>::type, int>::value)); 139 BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_template<void>(float)>::type, int>::value)); 140 BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of_template<void>(double)>::type, int>::value)); 141 BOOST_STATIC_ASSERT((is_same<tr1_result_of<const int_result_of_template<void>(double)>::type, int>::value)); 142 143 BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of(void)>::type, void>::value)); 144 BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile int_result_of(void)>::type, void>::value)); 145 BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of_template<void>(void)>::type, void>::value)); 146 BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile int_result_of_template<void>(void)>::type, void>::value)); 147 134 148 // Prior to decltype, result_of could not deduce the return type 135 149 // nullary function objects unless they exposed a result_type. 136 150 #if !defined(BOOST_NO_DECLTYPE) … … 145 159 BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, void>::value)); 146 160 #endif 147 161 162 BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_and_float_result_of_and_char_return(char)>::type, int>::value)); 163 BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_and_float_result_of_and_char_return_template<void>(char)>::type, int>::value)); 164 148 165 // Prior to decltype, result_of ignored a nested result<> if 149 166 // result_type was defined. After decltype, result_of deduces the 150 167 // actual return type of the function object, ignoring both … … 168 185 BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_0(X)>::type, int>::value)); 169 186 BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(void)>::type, int>::value)); 170 187 188 BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr(char, float)>::type, int>::value)); 189 BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ref(char, float)>::type, int>::value)); 190 BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr_0()>::type, int>::value)); 191 BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ref_0()>::type, int>::value)); 192 BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr(X,char)>::type, int>::value)); 193 BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_c(X,char)>::type, int>::value)); 194 BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_v(X,char)>::type, int>::value)); 195 BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_cv(X,char)>::type, int>::value)); 196 BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_0(X)>::type, int>::value)); 197 BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr(void)>::type, int>::value)); 198 171 199 BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(double)>::type, double>::value)); 172 200 BOOST_STATIC_ASSERT((is_same<result_of<const result_of_member_function_template(double)>::type, const double>::value)); 173 201 BOOST_STATIC_ASSERT((is_same<result_of<volatile result_of_member_function_template(double)>::type, volatile double>::value)); … … 177 205 BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int volatile &, int)>::type, int volatile &>::value)); 178 206 BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int const volatile &, int)>::type, int const volatile &>::value)); 179 207 208 BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(double)>::type, double>::value)); 209 BOOST_STATIC_ASSERT((is_same<tr1_result_of<const result_of_member_function_template(double)>::type, const double>::value)); 210 BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile result_of_member_function_template(double)>::type, volatile double>::value)); 211 BOOST_STATIC_ASSERT((is_same<tr1_result_of<const volatile result_of_member_function_template(double)>::type, const volatile double>::value)); 212 BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int &, int)>::type, int &>::value)); 213 BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int const &, int)>::type, int const &>::value)); 214 BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int volatile &, int)>::type, int volatile &>::value)); 215 BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int const volatile &, int)>::type, int const volatile &>::value)); 216 180 217 typedef int (*pf_t)(int); 181 218 BOOST_STATIC_ASSERT((is_same<result_of<pf_t(int)>::type, int>::value)); 182 219 BOOST_STATIC_ASSERT((is_same<result_of<pf_t const(int)>::type,int>::value)); 183 220 221 BOOST_STATIC_ASSERT((is_same<tr1_result_of<pf_t(int)>::type, int>::value)); 222 BOOST_STATIC_ASSERT((is_same<tr1_result_of<pf_t const(int)>::type,int>::value)); 223 184 224 #if !defined(BOOST_NO_DECLTYPE) 185 225 BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(double)>::type, int>::value)); 186 226 BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(void)>::type, unsigned int>::value));