OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
variadic_to_vmpl.hpp
1 /*
2  * to_variadic.hpp
3  *
4  * Set of classes to convert from a boost::mpl::vector into an S variadic template
5  * class appling a metafunction F on each element
6  *
7  * boost::mpl::vector<T,A,B> is converted into
8  *
9  * S<F<T>,F<A>,F<B>>
10  *
11  * \see to_variadic
12  *
13  * Created on: Aug 27, 2014
14  * Author: Pietro Incardona
15  */
16 
17 #ifndef V_TRANSFORM_HPP
18 #define V_TRANSFORM_HPP
19 
20 #include <boost/fusion/container/vector.hpp>
21 #include <boost/mpl/int.hpp>
22 #include <boost/mpl/reverse.hpp>
23 #include <boost/mpl/vector.hpp>
24 #include <boost/mpl/range_c.hpp>
25 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
26 #include <boost/fusion/include/at_c.hpp>
27 #include <boost/mpl/accumulate.hpp>
28 
30 
40 template<typename F,typename L>
41 struct exit_impl : boost::mpl::equal_to<typename boost::mpl::distance<F,L>::type,boost::mpl::int_<0>>
42 {};
43 
51 template<template<typename> class H, typename F,typename L, bool exit,typename ...Args>
53 {
55  typedef typename boost::mpl::deref<F>::type front_;
56 
58  typedef typename boost::mpl::next<F>::type next_;
59 
61  typedef typename exit_impl<next_,L>::type exit_;
62 
65 };
66 
67 
69 template<template<typename> class H,typename F,typename L,typename ...Args>
70 struct v_transform_impl<H,F,L,true,Args...>
71 {
73  typedef boost::fusion::vector<Args...> type;
74 };
75 
77 template<typename Seq>
78 struct seq_traits_impl
79 {
81  typedef typename boost::mpl::begin<Seq>::type first_;
82 
84  typedef typename boost::mpl::end<Seq>::type last_;
85 
88 };
89 
106 template<template<typename> class H,typename L>
108 {
110  typedef typename boost::mpl::reverse<L>::type reversed_;
111 
113  typedef typename seq_traits_impl<reversed_>::first_ first;
114 
116  typedef typename seq_traits_impl<reversed_>::last_ last;
117 
120 
123 };
124 
125 
127 
128 
137 template<template<typename,typename> class H, typename arg0, typename F,typename L, bool exit,typename ...Args>
139 {
141  typedef typename boost::mpl::deref<F>::type front_;
142 
144  typedef typename boost::mpl::next<F>::type next_;
145 
147  typedef typename exit_impl<next_,L>::type exit_;
148 
151 };
152 
153 
155 template<template<typename,typename> class H,typename arg0, typename F,typename L,typename ...Args>
156 struct v_transform_two_impl<H,arg0,F,L,true,Args...>
157 {
159  typedef boost::fusion::vector<Args...> type;
160 };
161 
178 template<template<typename,typename> class H,typename arg0, typename L>
180 {
182  typedef typename boost::mpl::reverse<L>::type reversed_;
183 
185  typedef typename seq_traits_impl<reversed_>::first_ first;
186 
188  typedef typename seq_traits_impl<reversed_>::last_ last;
189 
192 
195 };
196 
198 
200 template <int a, int... id>
202 {
204  typedef typename boost::mpl::push_front<typename to_boost_vmpl_impl<id...>::type,boost::mpl::int_<a>>::type type;
205 };
206 
208 template <int a>
210 {
212  typedef boost::mpl::vector<boost::mpl::int_<a>> type;
213 };
214 
226 template <int... id>
228 {
230  typedef typename to_boost_vmpl_impl<id...>::type type;
231 };
232 
234 template <>
236 {
238  typedef typename boost::mpl::vector<>::type type;
239 };
240 
242 
243 template <unsigned T1, unsigned int ...T>
245 {
246  typedef boost::mpl::int_<T1> type;
247 };
248 
249 template <unsigned int T1, unsigned int ...T>
251 {
252  typedef typename last_variadic<T...>::type type;
253 };
254 
255 template <unsigned int T1>
256 struct last_variadic<T1>
257 {
258  typedef boost::mpl::int_<T1> type;
259 };
260 
261 template <unsigned int ... prp>
263 {
264  typedef boost::mpl::range_c<int,first_variadic<prp...>::type::value,last_variadic<prp...>::type::value + 1> rangec;
265 
266  typedef typename boost::mpl::size<rangec>::type size_range;
267 
268  typedef typename boost::mpl::accumulate<rangec,
269  boost::mpl::int_<0>,
270  boost::mpl::plus<typename boost::mpl::placeholders::_2,
271  typename boost::mpl::placeholders::_1>
272  >::type accum;
273 
274  typedef typename to_boost_vmpl<prp...>::type prop_vector;
275 
276  typedef typename boost::mpl::accumulate<prop_vector,
277  boost::mpl::int_<0>,
278  boost::mpl::plus<typename boost::mpl::placeholders::_2,
279  typename boost::mpl::placeholders::_1>
280  >::type accum_prp;
281 
282  typedef boost::mpl::bool_<sizeof...(prp) == size_range::value && accum_prp::value == accum::value > type;
283 };
284 
285 #endif
boost::mpl::vector< boost::mpl::int_< a > > type
create a boost mpl vector with the last number
seq_traits_impl< reversed_ >::last_ last
last element
boost::mpl::next< F >::type next_
next element of the vector
boost::fusion::vector< Args...> type
required transformed type
Recursive specialization of v_transform in case of metafunction with 2 argument.
exit_impl< first, last >::type exit_
calculate the exit condition
Recursive specialization of v_transform.
seq_traits_impl< reversed_ >::first_ first
first element
boost::mpl::push_front< typename to_boost_vmpl_impl< id...>::type, boost::mpl::int_< a > >::type type
push in front the next number
v_transform_impl< H, first, last, exit_::value >::type type
generate the boost::fusion::vector apply H on each term
implementation of to_boost_vmpl
boost::mpl::vector::type type
terminator
boost::mpl::deref< F >::type front_
last element of the vector
exit_impl< first_, last_ >::type exit_
exit condition (first == last)
v_transform_impl< H, next_, L, exit_::value, typename H< front_ >::type, Args...>::type type
recursive call
boost::mpl::end< Seq >::type last_
Last element.
to_boost_vmpl_impl< id...>::type type
constrict an mpl vector from the variadic
boost::mpl::deref< F >::type front_
last element of the vector
implementation of seq_traits
v_transform_two_impl< H, arg0, first, last, exit_::value >::type type
generate the boost::fusion::vector apply H on each term
boost::mpl::next< F >::type next_
next element
boost::mpl::reverse< L >::type reversed_
reverse the sequence
boost::fusion::vector< Args...> type
Required type.
boost::mpl::reverse< L >::type reversed_
reverse the sequence
Exit condition.
seq_traits_impl< reversed_ >::last_ last
last element
exit_impl< first, last >::type exit_
calculate the exit condition
seq_traits_impl< reversed_ >::first_ first
first element
boost::mpl::begin< Seq >::type first_
first element
exit_impl< next_, L >::type exit_
exit condition
exit_impl< next_, L >::type exit_
exit condition
v_transform_two_impl< H, arg0, next_, L, exit_::value, typename H< arg0, front_ >::type, Args...>::type type
Recursive call.
[v_transform metafunction]