• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
2 
3     #include <boost/proto/transform/detail/preprocessed/fold_impl.hpp>
4 
5 #elif !defined(BOOST_PP_IS_ITERATING)
6 
7     #define BOOST_PROTO_CHILD_N_TYPE(N)                                                             \
8         BOOST_PP_CAT(proto_child, N)                                                                \
9         /**/
10 
11     #define BOOST_PROTO_FOLD_STATE_TYPE(Z, N, DATA)                                                 \
12         typedef                                                                                     \
13             typename when<_, Fun>::template impl<                                                   \
14                 typename result_of::child_c<Expr, N>::type                                          \
15               , BOOST_PP_CAT(state, N)                                                              \
16               , Data                                                                                \
17             >::result_type                                                                          \
18         BOOST_PP_CAT(state, BOOST_PP_INC(N));                                                       \
19         /**/
20 
21     #define BOOST_PROTO_FOLD_STATE(Z, N, DATA)                                                      \
22         BOOST_PP_CAT(state, BOOST_PP_INC(N))                                                        \
23         BOOST_PP_CAT(s, BOOST_PP_INC(N))                                                            \
24           = typename when<_, Fun>::template impl<                                                   \
25                 typename result_of::child_c<Expr, N>::type                                          \
26               , BOOST_PP_CAT(state, N)                                                              \
27               , Data                                                                                \
28             >()(                                                                                    \
29                 proto::child_c<N>(e)                                                                \
30               , BOOST_PP_CAT(s, N)                                                                  \
31               , d                                                                                   \
32             );                                                                                      \
33         /**/
34 
35     #define BOOST_PROTO_REVERSE_FOLD_STATE_TYPE(Z, N, DATA)                                         \
36         typedef                                                                                     \
37             typename when<_, Fun>::template impl<                                                   \
38                 typename result_of::child_c<                                                        \
39                     Expr                                                                            \
40                   , BOOST_PP_SUB(DATA, BOOST_PP_INC(N))                                             \
41                 >::type                                                                             \
42               , BOOST_PP_CAT(state, BOOST_PP_SUB(DATA, N))                                          \
43               , Data                                                                                \
44             >::result_type                                                                          \
45         BOOST_PP_CAT(state, BOOST_PP_SUB(DATA, BOOST_PP_INC(N)));                                   \
46         /**/
47 
48     #define BOOST_PROTO_REVERSE_FOLD_STATE(Z, N, DATA)                                              \
49         BOOST_PP_CAT(state, BOOST_PP_SUB(DATA, BOOST_PP_INC(N)))                                    \
50         BOOST_PP_CAT(s, BOOST_PP_SUB(DATA, BOOST_PP_INC(N)))                                        \
51           = typename when<_, Fun>::template impl<                                                   \
52                 typename result_of::child_c<                                                        \
53                     Expr                                                                            \
54                   , BOOST_PP_SUB(DATA, BOOST_PP_INC(N))                                             \
55                 >::type                                                                             \
56               , BOOST_PP_CAT(state, BOOST_PP_SUB(DATA, N))                                          \
57               , Data                                                                                \
58             >()(                                                                                    \
59                 proto::child_c<BOOST_PP_SUB(DATA, BOOST_PP_INC(N))>(e)                              \
60               , BOOST_PP_CAT(s, BOOST_PP_SUB(DATA, N))                                              \
61               , d                                                                                   \
62             );                                                                                      \
63         /**/
64 
65     #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
66         #pragma wave option(preserve: 2, line: 0, output: "preprocessed/fold_impl.hpp")
67     #endif
68 
69     ///////////////////////////////////////////////////////////////////////////////
70     /// \file fold_impl.hpp
71     /// Contains definition of fold_impl<> and reverse_fold_impl<> templates.
72     //
73     //  Copyright 2008 Eric Niebler. Distributed under the Boost
74     //  Software License, Version 1.0. (See accompanying file
75     //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
76 
77     #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
78         #pragma wave option(preserve: 1)
79     #endif
80 
81     #define BOOST_PP_ITERATION_PARAMS_1                                                             \
82         (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/transform/detail/fold_impl.hpp>))
83     #include BOOST_PP_ITERATE()
84 
85     #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
86         #pragma wave option(output: null)
87     #endif
88 
89     #undef BOOST_PROTO_REVERSE_FOLD_STATE
90     #undef BOOST_PROTO_REVERSE_FOLD_STATE_TYPE
91     #undef BOOST_PROTO_FOLD_STATE
92     #undef BOOST_PROTO_FOLD_STATE_TYPE
93     #undef BOOST_PROTO_CHILD_N_TYPE
94 
95 #else
96 
97     #define N BOOST_PP_ITERATION()
98 
99     template<typename State0, typename Fun, typename Expr, typename State, typename Data>
100     struct fold_impl<State0, Fun, Expr, State, Data, N>
101       : transform_impl<Expr, State, Data>
102     {
103         typedef typename when<_, State0>::template impl<Expr, State, Data>::result_type state0;
104         BOOST_PP_REPEAT(N, BOOST_PROTO_FOLD_STATE_TYPE, N)
105         typedef BOOST_PP_CAT(state, N) result_type;
106 
operator ()fold_impl107         result_type operator ()(
108             typename fold_impl::expr_param e
109           , typename fold_impl::state_param s
110           , typename fold_impl::data_param d
111         ) const
112         {
113             state0 s0 =
114                 typename when<_, State0>::template impl<Expr, State, Data>()(e, s, d);
115             BOOST_PP_REPEAT(N, BOOST_PROTO_FOLD_STATE, N)
116             return BOOST_PP_CAT(s, N);
117         }
118     };
119 
120     template<typename State0, typename Fun, typename Expr, typename State, typename Data>
121     struct reverse_fold_impl<State0, Fun, Expr, State, Data, N>
122       : transform_impl<Expr, State, Data>
123     {
124         typedef typename when<_, State0>::template impl<Expr, State, Data>::result_type BOOST_PP_CAT(state, N);
125         BOOST_PP_REPEAT(N, BOOST_PROTO_REVERSE_FOLD_STATE_TYPE, N)
126         typedef state0 result_type;
127 
operator ()reverse_fold_impl128         result_type operator ()(
129             typename reverse_fold_impl::expr_param e
130           , typename reverse_fold_impl::state_param s
131           , typename reverse_fold_impl::data_param d
132         ) const
133         {
134             BOOST_PP_CAT(state, N) BOOST_PP_CAT(s, N) =
135                 typename when<_, State0>::template impl<Expr, State, Data>()(e, s, d);
136             BOOST_PP_REPEAT(N, BOOST_PROTO_REVERSE_FOLD_STATE, N)
137             return s0;
138         }
139     };
140 
141     #undef N
142 
143 #endif
144