1# /* **************************************************************************
2# * *
3# * (C) Copyright Paul Mensonides 2002.
4# * Distributed under the Boost Software License, Version 1.0. (See
5# * accompanying file LICENSE_1_0.txt or copy at
6# * http://www.boost.org/LICENSE_1_0.txt)
7# * *
8# ************************************************************************** */
9#
10# /* See http://www.boost.org for most recent version. */
11#
12# ifndef BOOST_PREPROCESSOR_SEQ_FOR_EACH_HPP
13# define BOOST_PREPROCESSOR_SEQ_FOR_EACH_HPP
14#
15# include <boost/preprocessor/arithmetic/dec.hpp>
16# include <boost/preprocessor/config/config.hpp>
17# include <boost/preprocessor/control/if.hpp>
18# include <boost/preprocessor/control/iif.hpp>
19# include <boost/preprocessor/repetition/for.hpp>
20# include <boost/preprocessor/seq/seq.hpp>
21# include <boost/preprocessor/seq/size.hpp>
22# include <boost/preprocessor/seq/detail/is_empty.hpp>
23# include <boost/preprocessor/tuple/elem.hpp>
24# include <boost/preprocessor/tuple/rem.hpp>
25#
26# /* BOOST_PP_SEQ_FOR_EACH */
27#
28# if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG()
29# define BOOST_PP_SEQ_FOR_EACH(macro, data, seq) BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK(macro, data, seq)
30# else
31# define BOOST_PP_SEQ_FOR_EACH(macro, data, seq) BOOST_PP_SEQ_FOR_EACH_D(macro, data, seq)
32# define BOOST_PP_SEQ_FOR_EACH_D(macro, data, seq) BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK(macro, data, seq)
33# endif
34#
35# define BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_EXEC(macro, data, seq) BOOST_PP_FOR((macro, data, seq, BOOST_PP_SEQ_SIZE(seq)), BOOST_PP_SEQ_FOR_EACH_P, BOOST_PP_SEQ_FOR_EACH_O, BOOST_PP_SEQ_FOR_EACH_M)
36# define BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_EMPTY(macro, data, seq)
37#
38# define BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK(macro, data, seq) \
39 BOOST_PP_IIF \
40 ( \
41 BOOST_PP_SEQ_DETAIL_IS_NOT_EMPTY(seq), \
42 BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_EXEC, \
43 BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_EMPTY \
44 ) \
45 (macro, data, seq) \
46/**/
47#
48# define BOOST_PP_SEQ_FOR_EACH_P(r, x) BOOST_PP_TUPLE_ELEM(4, 3, x)
49#
50# if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT()
51# define BOOST_PP_SEQ_FOR_EACH_O(r, x) BOOST_PP_SEQ_FOR_EACH_O_I x
52# else
53# define BOOST_PP_SEQ_FOR_EACH_O(r, x) BOOST_PP_SEQ_FOR_EACH_O_I(BOOST_PP_TUPLE_ELEM(4, 0, x), BOOST_PP_TUPLE_ELEM(4, 1, x), BOOST_PP_TUPLE_ELEM(4, 2, x), BOOST_PP_TUPLE_ELEM(4, 3, x))
54# endif
55#
56# define BOOST_PP_SEQ_FOR_EACH_O_I(macro, data, seq, sz) \
57 BOOST_PP_SEQ_FOR_EACH_O_I_DEC(macro, data, seq, BOOST_PP_DEC(sz)) \
58/**/
59# define BOOST_PP_SEQ_FOR_EACH_O_I_DEC(macro, data, seq, sz) \
60 ( \
61 macro, \
62 data, \
63 BOOST_PP_IF \
64 ( \
65 sz, \
66 BOOST_PP_SEQ_FOR_EACH_O_I_TAIL, \
67 BOOST_PP_SEQ_FOR_EACH_O_I_NIL \
68 ) \
69 (seq), \
70 sz \
71 ) \
72/**/
73# define BOOST_PP_SEQ_FOR_EACH_O_I_TAIL(seq) BOOST_PP_SEQ_TAIL(seq)
74# define BOOST_PP_SEQ_FOR_EACH_O_I_NIL(seq) BOOST_PP_NIL
75#
76# if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT()
77# define BOOST_PP_SEQ_FOR_EACH_M(r, x) BOOST_PP_SEQ_FOR_EACH_M_IM(r, BOOST_PP_TUPLE_REM_4 x)
78# define BOOST_PP_SEQ_FOR_EACH_M_IM(r, im) BOOST_PP_SEQ_FOR_EACH_M_I(r, im)
79# else
80# define BOOST_PP_SEQ_FOR_EACH_M(r, x) BOOST_PP_SEQ_FOR_EACH_M_I(r, BOOST_PP_TUPLE_ELEM(4, 0, x), BOOST_PP_TUPLE_ELEM(4, 1, x), BOOST_PP_TUPLE_ELEM(4, 2, x), BOOST_PP_TUPLE_ELEM(4, 3, x))
81# endif
82#
83# define BOOST_PP_SEQ_FOR_EACH_M_I(r, macro, data, seq, sz) macro(r, data, BOOST_PP_SEQ_HEAD(seq))
84#
85# /* BOOST_PP_SEQ_FOR_EACH_R */
86#
87# if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG()
88# define BOOST_PP_SEQ_FOR_EACH_R(r, macro, data, seq) BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_R(r, macro, data, seq)
89# else
90# define BOOST_PP_SEQ_FOR_EACH_R(r, macro, data, seq) BOOST_PP_SEQ_FOR_EACH_R_I(r, macro, data, seq)
91# define BOOST_PP_SEQ_FOR_EACH_R_I(r, macro, data, seq) BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_R(r, macro, data, seq)
92# endif
93#
94# define BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_EXEC_R(r, macro, data, seq) BOOST_PP_FOR_ ## r((macro, data, seq, BOOST_PP_SEQ_SIZE(seq)), BOOST_PP_SEQ_FOR_EACH_P, BOOST_PP_SEQ_FOR_EACH_O, BOOST_PP_SEQ_FOR_EACH_M)
95# define BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_EMPTY_R(r, macro, data, seq)
96#
97# define BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_R(r, macro, data, seq) \
98 BOOST_PP_IIF \
99 ( \
100 BOOST_PP_SEQ_DETAIL_IS_NOT_EMPTY(seq), \
101 BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_EXEC_R, \
102 BOOST_PP_SEQ_FOR_EACH_DETAIL_CHECK_EMPTY_R \
103 ) \
104 (r, macro, data, seq) \
105/**/
106#
107# endif
108

source code of include/boost/preprocessor/seq/for_each.hpp