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_FUNCTION_OBJECT_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_params.hpp>
20 #include <boost/utility/result_of.hpp>
21 #include <boost/core/enable_if.hpp>
23 #include <boost/type_traits/remove_reference.hpp>
24 #include <boost/type_traits/remove_const.hpp>
26 #include <boost/fusion/support/category_of.hpp>
27 #include <boost/fusion/sequence/intrinsic/size.hpp>
28 #include <boost/fusion/sequence/intrinsic/at.hpp>
29 #include <boost/fusion/sequence/intrinsic/begin.hpp>
30 #include <boost/fusion/iterator/next.hpp>
31 #include <boost/fusion/iterator/deref.hpp>
32 #include <boost/fusion/functional/invocation/limits.hpp>
34 namespace boost { namespace fusion
39 class Function, class Sequence,
40 int N = result_of::size<Sequence>::value,
41 bool RandomAccess = traits::is_random_access<Sequence>::value,
42 typename Enable = void
44 struct invoke_function_object_impl;
46 template <class Sequence, int N>
47 struct invoke_function_object_param_types;
49 #define BOOST_PP_FILENAME_1 \
50 <boost/fusion/functional/invocation/invoke_function_object.hpp>
51 #define BOOST_PP_ITERATION_LIMITS \
52 (0, BOOST_FUSION_INVOKE_FUNCTION_OBJECT_MAX_ARITY)
53 #include BOOST_PP_ITERATE()
58 template <class Function, class Sequence, class Enable = void>
59 struct invoke_function_object;
61 template <class Function, class Sequence>
62 struct invoke_function_object<Function, Sequence,
63 typename enable_if_has_type<
64 typename detail::invoke_function_object_impl<
65 typename boost::remove_reference<Function>::type, Sequence
69 typedef typename detail::invoke_function_object_impl<
70 typename boost::remove_reference<Function>::type, Sequence
75 template <class Function, class Sequence>
76 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
77 inline typename result_of::invoke_function_object<Function,Sequence>::type
78 invoke_function_object(Function f, Sequence & s)
80 return detail::invoke_function_object_impl<
81 typename boost::remove_reference<Function>::type,Sequence
85 template <class Function, class Sequence>
86 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
87 inline typename result_of::invoke_function_object<Function,Sequence const>::type
88 invoke_function_object(Function f, Sequence const & s)
90 return detail::invoke_function_object_impl<
91 typename boost::remove_reference<Function>::type,Sequence const
97 #define BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_FUNCTION_OBJECT_HPP_INCLUDED
98 #else // defined(BOOST_PP_IS_ITERATING)
99 ///////////////////////////////////////////////////////////////////////////////
101 // Preprocessor vertical repetition code
103 ///////////////////////////////////////////////////////////////////////////////
104 #define N BOOST_PP_ITERATION()
106 #define M(z,j,data) \
107 typename result_of::at_c<Sequence,j>::type
109 template <class Function, class Sequence>
110 struct invoke_function_object_impl<Function,Sequence,N,true,
111 typename enable_if_has_type<
112 typename boost::result_of<Function (BOOST_PP_ENUM(N,M,~)) >::type
117 typedef typename boost::result_of<
118 Function (BOOST_PP_ENUM(N,M,~)) >::type result_type;
124 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
125 static inline result_type
126 call(F & f, Sequence & s)
128 #define M(z,j,data) fusion::at_c<j>(s)
129 return f( BOOST_PP_ENUM(N,M,~) );
136 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
137 static inline result_type
138 call(F & f, Sequence & /*s*/)
147 #define M(z,j,data) \
148 typename invoke_function_object_param_types<Sequence,N>::T ## j
150 template <class Function, class Sequence>
151 struct invoke_function_object_impl<Function,Sequence,N,false,
152 typename enable_if_has_type<
153 typename boost::result_of<Function (BOOST_PP_ENUM(N,M,~)) >::type
158 typedef invoke_function_object_param_types<Sequence,N> seq;
160 typedef typename boost::result_of<
161 Function (BOOST_PP_ENUM_PARAMS(N,typename seq::T))
167 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
168 static inline result_type
169 call(F & f, Sequence & s)
171 typename seq::I0 i0 = fusion::begin(s);
172 #define M(z,j,data) \
173 typename seq::I##j i##j = \
174 fusion::next(BOOST_PP_CAT(i,BOOST_PP_DEC(j)));
175 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
177 return f( BOOST_PP_ENUM_PARAMS(N,*i) );
183 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
184 static inline result_type
185 call(F & f, Sequence & /*s*/)
194 template <class Sequence>
195 struct invoke_function_object_param_types<Sequence,N>
198 typedef typename result_of::begin<Sequence>::type I0;
199 typedef typename result_of::deref<I0>::type T0;
201 #define M(z,i,data) \
202 typedef typename result_of::next< \
203 BOOST_PP_CAT(I,BOOST_PP_DEC(i))>::type I##i; \
204 typedef typename result_of::deref<I##i>::type T##i;
206 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
212 #endif // defined(BOOST_PP_IS_ITERATING)