comparison DEPENDENCIES/generic/include/boost/fusion/functional/invocation/invoke_procedure.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 /*=============================================================================
2 Copyright (c) 2005-2006 Joao Abecasis
3 Copyright (c) 2006-2007 Tobias Schwinger
4
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 ==============================================================================*/
9
10 #if !defined(BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_PROCEDURE_HPP_INCLUDED)
11 #if !defined(BOOST_PP_IS_ITERATING)
12
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>
21
22 #include <boost/type_traits/remove_reference.hpp>
23
24 #include <boost/mpl/front.hpp>
25
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>
29
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>
38
39 namespace boost { namespace fusion
40 {
41 namespace result_of
42 {
43 template <typename Function, class Sequence> struct invoke_procedure
44 {
45 typedef void type;
46 };
47 }
48
49 template <typename Function, class Sequence>
50 inline void invoke_procedure(Function, Sequence &);
51
52 template <typename Function, class Sequence>
53 inline void invoke_procedure(Function, Sequence const &);
54
55 //----- ---- --- -- - - - -
56
57 namespace detail
58 {
59 namespace ft = function_types;
60
61 template<
62 typename Function, class Sequence,
63 int N = result_of::size<Sequence>::value,
64 bool MFP = ft::is_member_function_pointer<Function>::value,
65 bool RandomAccess = traits::is_random_access<Sequence>::value
66 >
67 struct invoke_procedure_impl;
68
69 #define BOOST_PP_FILENAME_1 \
70 <boost/fusion/functional/invocation/invoke_procedure.hpp>
71 #define BOOST_PP_ITERATION_LIMITS \
72 (0, BOOST_FUSION_INVOKE_PROCEDURE_MAX_ARITY)
73 #include BOOST_PP_ITERATE()
74
75 }
76
77 template <typename Function, class Sequence>
78 inline void invoke_procedure(Function f, Sequence & s)
79 {
80 detail::invoke_procedure_impl<
81 typename boost::remove_reference<Function>::type,Sequence
82 >::call(f,s);
83 }
84
85 template <typename Function, class Sequence>
86 inline void invoke_procedure(Function f, Sequence const & s)
87 {
88 detail::invoke_procedure_impl<
89 typename boost::remove_reference<Function>::type,Sequence const
90 >::call(f,s);
91 }
92
93 }}
94
95 #define BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_PROCEDURE_HPP_INCLUDED
96 #else // defined(BOOST_PP_IS_ITERATING)
97 ///////////////////////////////////////////////////////////////////////////////
98 //
99 // Preprocessor vertical repetition code
100 //
101 ///////////////////////////////////////////////////////////////////////////////
102 #define N BOOST_PP_ITERATION()
103
104 #define M(z,j,data) fusion::at_c<j>(s)
105
106 template <typename Function, class Sequence>
107 struct invoke_procedure_impl<Function,Sequence,N,false,true>
108 {
109
110 #if N > 0
111
112 static inline void call(Function & f, Sequence & s)
113 {
114 f(BOOST_PP_ENUM(N,M,~));
115 }
116
117 #else
118
119 static inline void call(Function & f, Sequence & /*s*/)
120 {
121 f();
122 }
123
124 #endif
125
126 };
127
128 #if N > 0
129 template <typename Function, class Sequence>
130 struct invoke_procedure_impl<Function,Sequence,N,true,true>
131 {
132 static inline void call(Function & f, Sequence & s)
133 {
134 (that_ptr<typename mpl::front<
135 ft::parameter_types<Function> >::type
136 >::get(fusion::at_c<0>(s))->*f)(BOOST_PP_ENUM_SHIFTED(N,M,~));
137 }
138 };
139 #endif
140
141 #undef M
142
143 #define M(z,j,data) \
144 typedef typename result_of::next< BOOST_PP_CAT(I,BOOST_PP_DEC(j)) \
145 >::type I ## j ; \
146 I##j i##j = fusion::next(BOOST_PP_CAT(i,BOOST_PP_DEC(j)));
147
148 template <typename Function, class Sequence>
149 struct invoke_procedure_impl<Function,Sequence,N,false,false>
150 {
151
152 #if N > 0
153
154 static inline void call(Function & f, Sequence & s)
155 {
156 typedef typename result_of::begin<Sequence>::type I0;
157 I0 i0 = fusion::begin(s);
158 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
159 f( BOOST_PP_ENUM_PARAMS(N,*i) );
160 }
161
162 #else
163 static inline void call(Function & f, Sequence & /*s*/)
164 {
165 f();
166 }
167
168 #endif
169
170 };
171
172 #if N > 0
173 template <typename Function, class Sequence>
174 struct invoke_procedure_impl<Function,Sequence,N,true,false>
175 {
176 static inline void call(Function & f, Sequence & s)
177 {
178 typedef typename result_of::begin<Sequence>::type I0;
179 I0 i0 = fusion::begin(s);
180 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
181
182 (that_ptr<typename mpl::front<
183 ft::parameter_types<Function> >::type
184 >::get(*i0)->*f)(BOOST_PP_ENUM_SHIFTED_PARAMS(N,*i));
185 }
186 };
187 #endif
188
189 #undef M
190
191 #undef N
192 #endif // defined(BOOST_PP_IS_ITERATING)
193 #endif
194