1 /*=============================================================================
2 Copyright (c) 2005-2006 Joao Abecasis
3 Copyright (c) 2006-2007 Tobias Schwinger
5 Use modification and distribution are subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt).
8 ==============================================================================*/
10 #if !defined(BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_PROCEDURE_HPP_INCLUDED)
11 #if !defined(BOOST_PP_IS_ITERATING)
13 #include <boost/preprocessor/cat.hpp>
14 #include <boost/preprocessor/iteration/iterate.hpp>
15 #include <boost/preprocessor/arithmetic/dec.hpp>
16 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
17 #include <boost/preprocessor/repetition/enum.hpp>
18 #include <boost/preprocessor/repetition/enum_shifted.hpp>
19 #include <boost/preprocessor/repetition/enum_params.hpp>
20 #include <boost/preprocessor/repetition/enum_shifted_params.hpp>
22 #include <boost/type_traits/remove_reference.hpp>
24 #include <boost/mpl/front.hpp>
26 #include <boost/function_types/is_callable_builtin.hpp>
27 #include <boost/function_types/is_member_function_pointer.hpp>
28 #include <boost/function_types/parameter_types.hpp>
30 #include <boost/fusion/support/category_of.hpp>
31 #include <boost/fusion/sequence/intrinsic/at.hpp>
32 #include <boost/fusion/sequence/intrinsic/size.hpp>
33 #include <boost/fusion/sequence/intrinsic/begin.hpp>
34 #include <boost/fusion/iterator/next.hpp>
35 #include <boost/fusion/iterator/deref.hpp>
36 #include <boost/fusion/functional/invocation/limits.hpp>
37 #include <boost/fusion/functional/invocation/detail/that_ptr.hpp>
39 namespace boost { namespace fusion
43 template <typename Function, class Sequence> struct invoke_procedure
49 template <typename Function, class Sequence>
50 BOOST_FUSION_GPU_ENABLED
51 inline void invoke_procedure(Function, Sequence &);
53 template <typename Function, class Sequence>
54 BOOST_FUSION_GPU_ENABLED
55 inline void invoke_procedure(Function, Sequence const &);
57 //----- ---- --- -- - - - -
61 namespace ft = function_types;
64 typename Function, class Sequence,
65 int N = result_of::size<Sequence>::value,
66 bool MFP = ft::is_member_function_pointer<Function>::value,
67 bool RandomAccess = traits::is_random_access<Sequence>::value
69 struct invoke_procedure_impl;
71 #define BOOST_PP_FILENAME_1 \
72 <boost/fusion/functional/invocation/invoke_procedure.hpp>
73 #define BOOST_PP_ITERATION_LIMITS \
74 (0, BOOST_FUSION_INVOKE_PROCEDURE_MAX_ARITY)
75 #include BOOST_PP_ITERATE()
79 template <typename Function, class Sequence>
80 BOOST_FUSION_GPU_ENABLED
81 inline void invoke_procedure(Function f, Sequence & s)
83 detail::invoke_procedure_impl<
84 typename boost::remove_reference<Function>::type,Sequence
88 template <typename Function, class Sequence>
89 BOOST_FUSION_GPU_ENABLED
90 inline void invoke_procedure(Function f, Sequence const & s)
92 detail::invoke_procedure_impl<
93 typename boost::remove_reference<Function>::type,Sequence const
99 #define BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_PROCEDURE_HPP_INCLUDED
100 #else // defined(BOOST_PP_IS_ITERATING)
101 ///////////////////////////////////////////////////////////////////////////////
103 // Preprocessor vertical repetition code
105 ///////////////////////////////////////////////////////////////////////////////
106 #define N BOOST_PP_ITERATION()
108 #define M(z,j,data) fusion::at_c<j>(s)
110 template <typename Function, class Sequence>
111 struct invoke_procedure_impl<Function,Sequence,N,false,true>
116 BOOST_FUSION_GPU_ENABLED
117 static inline void call(Function & f, Sequence & s)
119 f(BOOST_PP_ENUM(N,M,~));
124 BOOST_FUSION_GPU_ENABLED
125 static inline void call(Function & f, Sequence & /*s*/)
135 template <typename Function, class Sequence>
136 struct invoke_procedure_impl<Function,Sequence,N,true,true>
138 BOOST_FUSION_GPU_ENABLED
139 static inline void call(Function & f, Sequence & s)
141 (that_ptr<typename mpl::front<
142 ft::parameter_types<Function> >::type
143 >::get(fusion::at_c<0>(s))->*f)(BOOST_PP_ENUM_SHIFTED(N,M,~));
150 #define M(z,j,data) \
151 typedef typename result_of::next< BOOST_PP_CAT(I,BOOST_PP_DEC(j)) \
153 I##j i##j = fusion::next(BOOST_PP_CAT(i,BOOST_PP_DEC(j)));
155 template <typename Function, class Sequence>
156 struct invoke_procedure_impl<Function,Sequence,N,false,false>
161 BOOST_FUSION_GPU_ENABLED
162 static inline void call(Function & f, Sequence & s)
164 typedef typename result_of::begin<Sequence>::type I0;
165 I0 i0 = fusion::begin(s);
166 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
167 f( BOOST_PP_ENUM_PARAMS(N,*i) );
171 BOOST_FUSION_GPU_ENABLED
172 static inline void call(Function & f, Sequence & /*s*/)
182 template <typename Function, class Sequence>
183 struct invoke_procedure_impl<Function,Sequence,N,true,false>
185 BOOST_FUSION_GPU_ENABLED
186 static inline void call(Function & f, Sequence & s)
188 typedef typename result_of::begin<Sequence>::type I0;
189 I0 i0 = fusion::begin(s);
190 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
192 (that_ptr<typename mpl::front<
193 ft::parameter_types<Function> >::type
194 >::get(*i0)->*f)(BOOST_PP_ENUM_SHIFTED_PARAMS(N,*i));
202 #endif // defined(BOOST_PP_IS_ITERATING)