Ticket #6828: forward_adaptor.patch
File forward_adaptor.patch, 10.6 KB (added by , 10 years ago) |
---|
-
boost/functional/detail/forward_adaptor_detail.hpp
1 /*============================================================================= 2 Copyright (c) 2012 Eric Niebler 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 #ifndef BOOST_FUNCTIONAL_FORWARD_ADAPTER_DETAIL_HPP_INCLUDED 10 #define BOOST_FUNCTIONAL_FORWARD_ADAPTER_DETAIL_HPP_INCLUDED 11 12 #include <boost/config.hpp> 13 #include <boost/utility/result_of.hpp> 14 15 namespace boost 16 { 17 namespace detail 18 { 19 struct not_a_valid_type {}; 20 typedef not_a_valid_type (*pfn_vararg_t)(...); 21 22 template< class Sig, class Result = BOOST_DEDUCED_TYPENAME boost::result_of< Sig >::type > 23 struct result_of_wrap 24 { 25 typedef Result type; 26 }; 27 28 template< class Sig > 29 struct result_of_wrap< Sig, not_a_valid_type > 30 { }; 31 32 template< class F > 33 struct vararg_function_wrapper 34 : F 35 { 36 using F::operator(); 37 operator pfn_vararg_t() const volatile; 38 vararg_function_wrapper(); 39 }; 40 41 template< class F > 42 struct wrap_vararg_function 43 { 44 typedef vararg_function_wrapper< F > type; 45 }; 46 47 template< class F > 48 struct wrap_vararg_function< F const > 49 { 50 typedef vararg_function_wrapper< F > const type; 51 }; 52 } 53 } 54 55 #endif 56 -
boost/functional/lightweight_forward_adapter.hpp
19 19 # include <boost/preprocessor/repetition/enum_binary_params.hpp> 20 20 # include <boost/preprocessor/facilities/intercept.hpp> 21 21 22 # include <boost/functional/detail/forward_adaptor_detail.hpp> 22 23 # include <boost/utility/result_of.hpp> 23 24 # include <boost/ref.hpp> 24 25 … … 153 154 struct lightweight_forward_adapter_impl<MD,F,FC,0,0> 154 155 : lightweight_forward_adapter_result 155 156 { 156 inline typename boost::result_of< FC() >::type 157 typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< FC >::type WFC; 158 inline typename boost::result_of< WFC() >::type 157 159 operator()() const 158 160 { 159 161 return static_cast<MD const*>(this)->target_function()(); 160 162 } 161 163 162 inline typename boost::result_of< F() >::type 164 typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< F >::type WF; 165 inline typename boost::result_of< WF() >::type 163 166 operator()() 164 167 { 165 168 return static_cast<MD*>(this)->target_function()(); … … 213 216 struct lightweight_forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),N> 214 217 : lightweight_forward_adapter_result 215 218 { 219 typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< F >::type WF; 216 220 template< BOOST_PP_ENUM_PARAMS(N,typename T) > 217 inline typename boost::result_of<F(BOOST_PP_ENUM_BINARY_PARAMS(N,221 inline typename result_of_wrap< WF(BOOST_PP_ENUM_BINARY_PARAMS(N, 218 222 T,const& BOOST_PP_INTERCEPT)) >::type 219 223 operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)); 220 224 }; -
boost/functional/forward_adapter.hpp
19 19 # include <boost/preprocessor/arithmetic/dec.hpp> 20 20 21 21 # include <boost/utility/result_of.hpp> 22 # include <boost/functional/detail/forward_adaptor_detail.hpp> 22 23 23 24 # ifndef BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY 24 25 # define BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY 6 … … 147 148 template< class MD, class F, class FC > 148 149 struct forward_adapter_impl<MD,F,FC,0,0> 149 150 { 150 inline typename boost::result_of< FC() >::type 151 typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< FC >::type WFC; 152 inline typename boost::result_of< WFC() >::type 151 153 operator()() const 152 154 { 153 155 return static_cast<MD const*>(this)->target_function()(); 154 156 } 155 157 156 inline typename boost::result_of< F() >::type 158 typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< F >::type WF; 159 inline typename boost::result_of< WF() >::type 157 160 operator()() 158 161 { 159 162 return static_cast<MD*>(this)->target_function()(); … … 161 164 162 165 // closing brace gets generated by preprocessing code, below 163 166 164 # define BOOST_TMP_MACRO(tpl_params,arg_types,params,args) \167 # define BOOST_TMP_MACRO(tpl_params,arg_types,params,args) \ 165 168 template< tpl_params > \ 166 inline typename boost::result_of< FC(arg_types) >::type\169 inline typename result_of_wrap< WFC(arg_types) >::type \ 167 170 operator()(params) const \ 168 171 { \ 169 172 return static_cast<MD const*>(this)->target_function()(args); \ 170 173 } \ 171 174 template< tpl_params > \ 172 inline typename boost::result_of< F(arg_types)>::type\175 inline typename result_of_wrap< WF(arg_types)>::type \ 173 176 operator()(params) \ 174 177 { \ 175 178 return static_cast<MD*>(this)->target_function()(args); \ … … 333 336 struct forward_adapter_impl<MD,F,FC,N,MinArity> 334 337 : forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity> 335 338 { 339 typedef BOOST_DEDUCED_TYPENAME forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>::WF WF; 340 typedef BOOST_DEDUCED_TYPENAME forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>::WFC WFC; 336 341 using forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>::operator(); 337 342 338 343 # endif … … 424 429 425 430 # if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1400)) 426 431 template< BOOST_PP_ENUM_PARAMS(N,typename T) > 427 inline typename boost::result_of<FC(BOOST_PP_ENUM_PARAMS(N,PT))432 inline typename result_of_wrap< WFC(BOOST_PP_ENUM_PARAMS(N,PT)) 428 433 >::type 429 434 operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,PT,a)) const 430 435 { … … 432 437 ->target_function()(BOOST_PP_ENUM_PARAMS(N,a)); 433 438 } 434 439 template< BOOST_PP_ENUM_PARAMS(N,typename T) > 435 inline typename boost::result_of<F(BOOST_PP_ENUM_PARAMS(N,PT))440 inline typename result_of_wrap< WF(BOOST_PP_ENUM_PARAMS(N,PT)) 436 441 >::type 437 442 operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,PT,a)) 438 443 { -
libs/functional/forward/test/lightweight_forward_adapter.cpp
60 60 struct result< Self(int&,int const&) > { typedef long type; }; 61 61 62 62 template <class Self> 63 struct result< Self(int&,int&) > { typedef char type; }; 63 struct result< Self const(int&,int&) > { typedef int type; }; 64 65 template <class Self> 66 struct result< Self(int&,int&) > { typedef long type; }; 64 67 }; 65 68 66 69 enum { int_, long_, char_ }; … … 90 93 result_of< f const (ref, cref) >::type, int >::value )); 91 94 // lvalue,lvalue 92 95 BOOST_TEST(( is_same< 93 result_of< f(ref, ref) >::type, char>::value ));96 result_of< f(ref, ref) >::type, long >::value )); 94 97 BOOST_TEST(( is_same< 95 result_of< f const (ref, ref) >::type, char>::value ));98 result_of< f const (ref, ref) >::type, int >::value )); 96 99 } 97 100 { 98 101 using boost::noncopyable; … … 113 116 BOOST_TEST( type_of( func_c(x,1) ) == int_ ); 114 117 BOOST_TEST( type_of( func_c2(x,1) ) == int_ ); 115 118 BOOST_TEST( type_of( func_c_ref(x,1) ) == int_ ); 116 BOOST_TEST( type_of( func(x,x) ) == char_ );119 BOOST_TEST( type_of( func(x,x) ) == long_ ); 117 120 118 121 BOOST_TEST( func(x,1) == -8 ); 119 122 BOOST_TEST( func_ref(x,1) == -8 ); -
libs/functional/forward/test/forward_adapter.cpp
60 60 struct result< Self(int&,int const&) > { typedef long type; }; 61 61 62 62 template <class Self> 63 struct result< Self(int&,int&) > { typedef char type; }; 63 struct result< Self const(int&,int&) > { typedef int type; }; 64 65 template <class Self> 66 struct result< Self(int&,int&) > { typedef long type; }; 64 67 }; 65 68 66 69 enum { int_, long_, char_ }; … … 88 91 result_of< f const (int&, int const &) >::type, int >::value )); 89 92 // lvalue,lvalue 90 93 BOOST_TEST(( is_same< 91 result_of< f(int&, int&) >::type, char>::value ));94 result_of< f(int&, int&) >::type, long >::value )); 92 95 BOOST_TEST(( is_same< 93 result_of< f const (int&, int&) >::type, char>::value ));96 result_of< f const (int&, int&) >::type, int >::value )); 94 97 } 95 98 96 99 { … … 112 115 BOOST_TEST( type_of( func_c(x,1) ) == int_ ); 113 116 BOOST_TEST( type_of( func_c2(x,1) ) == int_ ); 114 117 BOOST_TEST( type_of( func_c_ref(x,1) ) == int_ ); 115 BOOST_TEST( type_of( func(x,x) ) == char_ );118 BOOST_TEST( type_of( func(x,x) ) == long_ ); 116 119 117 120 BOOST_TEST( func(x,1) == -8 ); 118 121 BOOST_TEST( func_ref(x,1) == -8 );