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>
23 #include <boost/core/enable_if.hpp>
25 #include <boost/mpl/front.hpp>
27 #include <boost/function_types/is_callable_builtin.hpp>
28 #include <boost/function_types/is_member_function_pointer.hpp>
29 #include <boost/function_types/parameter_types.hpp>
31 #include <boost/fusion/support/category_of.hpp>
32 #include <boost/fusion/sequence/intrinsic/at.hpp>
33 #include <boost/fusion/sequence/intrinsic/size.hpp>
34 #include <boost/fusion/sequence/intrinsic/begin.hpp>
35 #include <boost/fusion/iterator/next.hpp>
36 #include <boost/fusion/iterator/deref.hpp>
37 #include <boost/fusion/functional/invocation/limits.hpp>
38 #include <boost/fusion/functional/invocation/detail/that_ptr.hpp>
40 namespace boost { namespace fusion
44 namespace ft = function_types;
47 typename Function, class Sequence,
48 int N = result_of::size<Sequence>::value,
49 bool MFP = ft::is_member_function_pointer<Function>::value,
50 bool RandomAccess = traits::is_random_access<Sequence>::value
52 struct invoke_procedure_impl;
54 #define BOOST_PP_FILENAME_1 \
55 <boost/fusion/functional/invocation/invoke_procedure.hpp>
56 #define BOOST_PP_ITERATION_LIMITS \
57 (0, BOOST_FUSION_INVOKE_PROCEDURE_MAX_ARITY)
58 #include BOOST_PP_ITERATE()
64 template <typename Function, class Sequence, class Enable = void>
65 struct invoke_procedure;
67 template <typename Function, class Sequence>
68 struct invoke_procedure<Function, Sequence,
69 typename enable_if_has_type<
70 typename detail::invoke_procedure_impl<
71 typename boost::remove_reference<Function>::type,Sequence
79 template <typename Function, class Sequence>
80 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
81 inline typename result_of::invoke_procedure<Function, Sequence>::type
82 invoke_procedure(Function f, Sequence & s)
84 detail::invoke_procedure_impl<
85 typename boost::remove_reference<Function>::type,Sequence
89 template <typename Function, class Sequence>
90 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
91 inline typename result_of::invoke_procedure<Function, Sequence const>::type
92 invoke_procedure(Function f, Sequence const & s)
94 detail::invoke_procedure_impl<
95 typename boost::remove_reference<Function>::type,Sequence const
101 #define BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_PROCEDURE_HPP_INCLUDED
102 #else // defined(BOOST_PP_IS_ITERATING)
103 ///////////////////////////////////////////////////////////////////////////////
105 // Preprocessor vertical repetition code
107 ///////////////////////////////////////////////////////////////////////////////
108 #define N BOOST_PP_ITERATION()
110 #define M(z,j,data) fusion::at_c<j>(s)
112 template <typename Function, class Sequence>
113 struct invoke_procedure_impl<Function,Sequence,N,false,true>
115 typedef void result_type;
119 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
120 static inline void call(Function & f, Sequence & s)
122 f(BOOST_PP_ENUM(N,M,~));
127 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
128 static inline void call(Function & f, Sequence & /*s*/)
138 template <typename Function, class Sequence>
139 struct invoke_procedure_impl<Function,Sequence,N,true,true>
141 typedef void result_type;
143 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
144 static inline void call(Function & f, Sequence & s)
146 (that_ptr<typename mpl::front<
147 ft::parameter_types<Function> >::type
148 >::get(fusion::at_c<0>(s))->*f)(BOOST_PP_ENUM_SHIFTED(N,M,~));
155 #define M(z,j,data) \
156 typedef typename result_of::next< BOOST_PP_CAT(I,BOOST_PP_DEC(j)) \
158 I##j i##j = fusion::next(BOOST_PP_CAT(i,BOOST_PP_DEC(j)));
160 template <typename Function, class Sequence>
161 struct invoke_procedure_impl<Function,Sequence,N,false,false>
163 typedef void result_type;
167 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
168 static inline void call(Function & f, Sequence & s)
170 typedef typename result_of::begin<Sequence>::type I0;
171 I0 i0 = fusion::begin(s);
172 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
173 f( BOOST_PP_ENUM_PARAMS(N,*i) );
177 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
178 static inline void call(Function & f, Sequence & /*s*/)
188 template <typename Function, class Sequence>
189 struct invoke_procedure_impl<Function,Sequence,N,true,false>
191 typedef void result_type;
193 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
194 static inline void call(Function & f, Sequence & s)
196 typedef typename result_of::begin<Sequence>::type I0;
197 I0 i0 = fusion::begin(s);
198 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
200 (that_ptr<typename mpl::front<
201 ft::parameter_types<Function> >::type
202 >::get(*i0)->*f)(BOOST_PP_ENUM_SHIFTED_PARAMS(N,*i));
210 #endif // defined(BOOST_PP_IS_ITERATING)