/*============================================================================= Copyright (c) 2005-2006 Joao Abecasis Copyright (c) 2006-2007 Tobias Schwinger Use modification and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). ==============================================================================*/ #if !defined(BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_FUNCTION_OBJECT_HPP_INCLUDED) #if !defined(BOOST_PP_IS_ITERATING) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace fusion { namespace result_of { template struct invoke_function_object; } template BOOST_FUSION_GPU_ENABLED inline typename result_of::invoke_function_object::type invoke_function_object(Function, Sequence &); template BOOST_FUSION_GPU_ENABLED inline typename result_of::invoke_function_object::type invoke_function_object(Function, Sequence const &); //----- ---- --- -- - - - - namespace detail { template< class Function, class Sequence, int N = result_of::size::value, bool RandomAccess = traits::is_random_access::value > struct invoke_function_object_impl; template struct invoke_function_object_param_types; #define BOOST_PP_FILENAME_1 \ #define BOOST_PP_ITERATION_LIMITS \ (0, BOOST_FUSION_INVOKE_FUNCTION_OBJECT_MAX_ARITY) #include BOOST_PP_ITERATE() } namespace result_of { template struct invoke_function_object { typedef typename detail::invoke_function_object_impl< typename boost::remove_reference::type, Sequence >::result_type type; }; } template BOOST_FUSION_GPU_ENABLED inline typename result_of::invoke_function_object::type invoke_function_object(Function f, Sequence & s) { return detail::invoke_function_object_impl< typename boost::remove_reference::type,Sequence >::call(f,s); } template BOOST_FUSION_GPU_ENABLED inline typename result_of::invoke_function_object::type invoke_function_object(Function f, Sequence const & s) { return detail::invoke_function_object_impl< typename boost::remove_reference::type,Sequence const >::call(f,s); } }} #define BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_FUNCTION_OBJECT_HPP_INCLUDED #else // defined(BOOST_PP_IS_ITERATING) /////////////////////////////////////////////////////////////////////////////// // // Preprocessor vertical repetition code // /////////////////////////////////////////////////////////////////////////////// #define N BOOST_PP_ITERATION() template struct invoke_function_object_impl { public: typedef typename boost::result_of< #define M(z,j,data) \ typename result_of::at_c::type Function (BOOST_PP_ENUM(N,M,~)) >::type result_type; #undef M #if N > 0 template BOOST_FUSION_GPU_ENABLED static inline result_type call(F & f, Sequence & s) { #define M(z,j,data) fusion::at_c(s) return f( BOOST_PP_ENUM(N,M,~) ); #undef M } #else template BOOST_FUSION_GPU_ENABLED static inline result_type call(F & f, Sequence & /*s*/) { return f(); } #endif }; template struct invoke_function_object_impl { private: typedef invoke_function_object_param_types seq; public: typedef typename boost::result_of< Function (BOOST_PP_ENUM_PARAMS(N,typename seq::T)) >::type result_type; #if N > 0 template BOOST_FUSION_GPU_ENABLED static inline result_type call(F & f, Sequence & s) { typename seq::I0 i0 = fusion::begin(s); #define M(z,j,data) \ typename seq::I##j i##j = \ fusion::next(BOOST_PP_CAT(i,BOOST_PP_DEC(j))); BOOST_PP_REPEAT_FROM_TO(1,N,M,~) #undef M return f( BOOST_PP_ENUM_PARAMS(N,*i) ); } #else template BOOST_FUSION_GPU_ENABLED static inline result_type call(F & f, Sequence & /*s*/) { return f(); } #endif }; template struct invoke_function_object_param_types { #if N > 0 typedef typename result_of::begin::type I0; typedef typename result_of::deref::type T0; #define M(z,i,data) \ typedef typename result_of::next< \ BOOST_PP_CAT(I,BOOST_PP_DEC(i))>::type I##i; \ typedef typename result_of::deref::type T##i; BOOST_PP_REPEAT_FROM_TO(1,N,M,~) #undef M #endif }; #undef N #endif // defined(BOOST_PP_IS_ITERATING) #endif