1 // Copyright Daniel Wallin 2005. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef BOOST_PARAMETER_FOR_EACH_051217_HPP
6 # define BOOST_PARAMETER_FOR_EACH_051217_HPP
8 # include <boost/preprocessor/cat.hpp>
9 # include <boost/preprocessor/detail/split.hpp>
10 # include <boost/preprocessor/logical/not.hpp>
11 # include <boost/preprocessor/facilities/is_empty.hpp>
12 # include <boost/preprocessor/tuple/eat.hpp>
13 # include <boost/preprocessor/arithmetic/inc.hpp>
14 # include <boost/preprocessor/repeat.hpp>
15 # include <boost/preprocessor/punctuation/comma_if.hpp>
16 # include <boost/preprocessor/for.hpp>
17 # include <boost/preprocessor/repetition/deduce_r.hpp>
19 # define BOOST_PARAMETER_FOR_EACH_head_aux2(x,y) (x,y), ~
20 # define BOOST_PARAMETER_FOR_EACH_head_aux3(x,y,z) (x,y,z), ~
21 # define BOOST_PARAMETER_FOR_EACH_head_aux4(x,y,z,u) (x,y,z,u), ~
22 # define BOOST_PARAMETER_FOR_EACH_head(n,x) \
23 BOOST_PP_SPLIT(0, BOOST_PP_CAT(BOOST_PARAMETER_FOR_EACH_head_aux,n) x)
25 # define BOOST_PARAMETER_FOR_EACH_pred_aux_BOOST_PARAMETER_FOR_EACH_END_SENTINEL
26 # define BOOST_PARAMETER_FOR_EACH_pred_aux_check(x) \
27 BOOST_PP_NOT(BOOST_PP_IS_EMPTY( \
28 BOOST_PP_CAT(BOOST_PARAMETER_FOR_EACH_pred_aux_, x) \
31 # define BOOST_PARAMETER_FOR_EACH_pred_aux2(x,y) \
32 BOOST_PARAMETER_FOR_EACH_pred_aux_check(x)
33 # define BOOST_PARAMETER_FOR_EACH_pred_aux3(x,y,z) \
34 BOOST_PARAMETER_FOR_EACH_pred_aux_check(x)
35 # define BOOST_PARAMETER_FOR_EACH_pred_aux4(x,y,z,u) \
36 BOOST_PARAMETER_FOR_EACH_pred_aux_check(x)
38 # define BOOST_PARAMETER_FOR_EACH_pred_aux0(n,x) \
39 BOOST_PP_CAT(BOOST_PARAMETER_FOR_EACH_pred_aux,n) x
41 # if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MSVC()
42 # define BOOST_PARAMETER_FOR_EACH_pred_SPLIT_FIRST(x) \
45 # define BOOST_PARAMETER_FOR_EACH_pred(r, state) \
46 BOOST_PARAMETER_FOR_EACH_pred_SPLIT_FIRST( \
47 BOOST_PARAMETER_FOR_EACH_pred_aux0( \
48 BOOST_PP_TUPLE_ELEM(5,3,state) \
49 , BOOST_PP_TUPLE_ELEM(5,0,state) \
53 # define BOOST_PARAMETER_FOR_EACH_pred(r, state) \
56 , BOOST_PARAMETER_FOR_EACH_pred_aux0( \
57 BOOST_PP_TUPLE_ELEM(5,3,state) \
58 , BOOST_PP_TUPLE_ELEM(5,0,state) \
63 # define BOOST_PARAMETER_FOR_EACH_op(r, state) \
65 BOOST_PP_TUPLE_EAT(BOOST_PP_TUPLE_ELEM(5,3,state)) \
66 BOOST_PP_TUPLE_ELEM(5,0,state) \
67 , BOOST_PP_TUPLE_ELEM(5,1,state) \
68 , BOOST_PP_TUPLE_ELEM(5,2,state) \
69 , BOOST_PP_TUPLE_ELEM(5,3,state) \
70 , BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(5,4,state)) \
73 # define BOOST_PARAMETER_FOR_EACH_macro(r, state) \
74 BOOST_PP_TUPLE_ELEM(5,2,state)( \
76 , BOOST_PP_TUPLE_ELEM(5,4,state) \
77 , BOOST_PARAMETER_FOR_EACH_head( \
78 BOOST_PP_TUPLE_ELEM(5,3,state) \
79 , BOOST_PP_TUPLE_ELEM(5,0,state) \
81 , BOOST_PP_TUPLE_ELEM(5,1,state) \
84 # define BOOST_PARAMETER_FOR_EACH_build_end_sentinel(z,n,text) \
85 BOOST_PP_COMMA_IF(n) BOOST_PARAMETER_FOR_EACH_END_SENTINEL
86 # define BOOST_PARAMETER_FOR_EACH_build_end_sentinel_tuple(arity) \
88 BOOST_PP_REPEAT(arity, BOOST_PARAMETER_FOR_EACH_build_end_sentinel, _) \
91 # define BOOST_PARAMETER_FOR_EACH_R(r, arity, list, data, macro) \
92 BOOST_PP_CAT(BOOST_PP_FOR_, r)( \
93 (list BOOST_PARAMETER_FOR_EACH_build_end_sentinel_tuple(arity), data, macro, arity, 0) \
94 , BOOST_PARAMETER_FOR_EACH_pred \
95 , BOOST_PARAMETER_FOR_EACH_op \
96 , BOOST_PARAMETER_FOR_EACH_macro \
99 # define BOOST_PARAMETER_FOR_EACH(arity, list, data, macro) \
100 BOOST_PARAMETER_FOR_EACH_R(BOOST_PP_DEDUCE_R(), arity, list, data, macro)
102 #endif // BOOST_PARAMETER_FOR_EACH_051217_HPP