Chris@16
|
1 #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
|
Chris@16
|
2
|
Chris@16
|
3 #include <boost/proto/transform/detail/preprocessed/make.hpp>
|
Chris@16
|
4
|
Chris@16
|
5 #elif !defined(BOOST_PP_IS_ITERATING)
|
Chris@16
|
6
|
Chris@16
|
7 #define BOOST_PROTO_MAKE_IF(Z, M, DATA) \
|
Chris@16
|
8 make_if_<BOOST_PP_CAT(A, M), Expr, State, Data> \
|
Chris@16
|
9 /**/
|
Chris@16
|
10
|
Chris@16
|
11 #define BOOST_PROTO_MAKE_IF_TYPE(Z, M, DATA) \
|
Chris@16
|
12 typename BOOST_PROTO_MAKE_IF(Z, M, DATA) ::type \
|
Chris@16
|
13 /**/
|
Chris@16
|
14
|
Chris@16
|
15 #define BOOST_PROTO_MAKE_IF_APPLIED(Z, M, DATA) \
|
Chris@16
|
16 BOOST_PROTO_MAKE_IF(Z, M, DATA) ::applied || \
|
Chris@16
|
17 /**/
|
Chris@16
|
18
|
Chris@16
|
19 #define BOOST_PROTO_CONSTRUCT_ARG(Z, M, DATA) \
|
Chris@16
|
20 detail::as_lvalue( \
|
Chris@16
|
21 typename when<_, BOOST_PP_CAT(A, M)>::template impl<Expr, State, Data>()(e, s, d) \
|
Chris@16
|
22 ) \
|
Chris@16
|
23 /**/
|
Chris@16
|
24
|
Chris@16
|
25 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
26 #pragma wave option(preserve: 2, line: 0, output: "preprocessed/make.hpp")
|
Chris@16
|
27 #endif
|
Chris@16
|
28
|
Chris@16
|
29 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
30 /// \file make.hpp
|
Chris@16
|
31 /// Contains definition of the make<> transform.
|
Chris@16
|
32 //
|
Chris@16
|
33 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
34 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
35 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
36
|
Chris@16
|
37 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
38 #pragma wave option(preserve: 1)
|
Chris@16
|
39 #endif
|
Chris@16
|
40
|
Chris@16
|
41 #define BOOST_PP_ITERATION_PARAMS_1 \
|
Chris@16
|
42 (3, (0, BOOST_PROTO_MAX_ARITY, <boost/proto/transform/detail/make.hpp>))
|
Chris@16
|
43 #include BOOST_PP_ITERATE()
|
Chris@16
|
44
|
Chris@16
|
45 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
46 #pragma wave option(output: null)
|
Chris@16
|
47 #endif
|
Chris@16
|
48
|
Chris@16
|
49 #undef BOOST_PROTO_CONSTRUCT_ARG
|
Chris@16
|
50 #undef BOOST_PROTO_MAKE_IF_APPLIED
|
Chris@16
|
51 #undef BOOST_PROTO_MAKE_IF_TYPE
|
Chris@16
|
52 #undef BOOST_PROTO_MAKE_IF
|
Chris@16
|
53
|
Chris@16
|
54 #else
|
Chris@16
|
55
|
Chris@16
|
56 #define N BOOST_PP_ITERATION()
|
Chris@16
|
57
|
Chris@16
|
58 namespace detail
|
Chris@16
|
59 {
|
Chris@16
|
60 #if N > 0
|
Chris@16
|
61
|
Chris@16
|
62 template<
|
Chris@16
|
63 template<BOOST_PP_ENUM_PARAMS(N, typename BOOST_PP_INTERCEPT)> class R
|
Chris@16
|
64 BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)
|
Chris@16
|
65 , typename Expr, typename State, typename Data
|
Chris@16
|
66 >
|
Chris@16
|
67 struct make_<
|
Chris@16
|
68 R<BOOST_PP_ENUM_PARAMS(N, A)>
|
Chris@16
|
69 , Expr, State, Data
|
Chris@16
|
70 BOOST_PROTO_TEMPLATE_ARITY_PARAM(N)
|
Chris@16
|
71 >
|
Chris@16
|
72 : nested_type_if<
|
Chris@16
|
73 R<BOOST_PP_ENUM(N, BOOST_PROTO_MAKE_IF_TYPE, ~)>
|
Chris@16
|
74 , (BOOST_PP_REPEAT(N, BOOST_PROTO_MAKE_IF_APPLIED, ~) false)
|
Chris@16
|
75 >
|
Chris@16
|
76 {};
|
Chris@16
|
77
|
Chris@16
|
78 template<
|
Chris@16
|
79 template<BOOST_PP_ENUM_PARAMS(N, typename BOOST_PP_INTERCEPT)> class R
|
Chris@16
|
80 BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)
|
Chris@16
|
81 , typename Expr, typename State, typename Data
|
Chris@16
|
82 >
|
Chris@16
|
83 struct make_<
|
Chris@16
|
84 noinvoke<R<BOOST_PP_ENUM_PARAMS(N, A)> >
|
Chris@16
|
85 , Expr, State, Data
|
Chris@16
|
86 BOOST_PROTO_TEMPLATE_ARITY_PARAM(1)
|
Chris@16
|
87 >
|
Chris@16
|
88 {
|
Chris@16
|
89 typedef R<BOOST_PP_ENUM(N, BOOST_PROTO_MAKE_IF_TYPE, ~)> type;
|
Chris@16
|
90 static bool const applied = true;
|
Chris@16
|
91 };
|
Chris@16
|
92
|
Chris@16
|
93 #endif
|
Chris@16
|
94
|
Chris@16
|
95 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
|
Chris@16
|
96 struct is_applyable<R(BOOST_PP_ENUM_PARAMS(N, A))>
|
Chris@16
|
97 : mpl::true_
|
Chris@16
|
98 {};
|
Chris@16
|
99
|
Chris@16
|
100 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
|
Chris@16
|
101 struct is_applyable<R(*)(BOOST_PP_ENUM_PARAMS(N, A))>
|
Chris@16
|
102 : mpl::true_
|
Chris@16
|
103 {};
|
Chris@16
|
104
|
Chris@16
|
105 template<typename T, typename A>
|
Chris@16
|
106 struct construct_<proto::expr<T, A, N>, true>
|
Chris@16
|
107 {
|
Chris@16
|
108 typedef proto::expr<T, A, N> result_type;
|
Chris@16
|
109
|
Chris@16
|
110 template<BOOST_PP_ENUM_PARAMS(BOOST_PP_MAX(N, 1), typename A)>
|
Chris@16
|
111 BOOST_FORCEINLINE
|
Chris@16
|
112 result_type operator ()(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_MAX(N, 1), A, &a)) const
|
Chris@16
|
113 {
|
Chris@16
|
114 return result_type::make(BOOST_PP_ENUM_PARAMS(BOOST_PP_MAX(N, 1), a));
|
Chris@16
|
115 }
|
Chris@16
|
116 };
|
Chris@16
|
117
|
Chris@16
|
118 template<typename T, typename A>
|
Chris@16
|
119 struct construct_<proto::basic_expr<T, A, N>, true>
|
Chris@16
|
120 {
|
Chris@16
|
121 typedef proto::basic_expr<T, A, N> result_type;
|
Chris@16
|
122
|
Chris@16
|
123 template<BOOST_PP_ENUM_PARAMS(BOOST_PP_MAX(N, 1), typename A)>
|
Chris@16
|
124 BOOST_FORCEINLINE
|
Chris@16
|
125 result_type operator ()(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_MAX(N, 1), A, &a)) const
|
Chris@16
|
126 {
|
Chris@16
|
127 return result_type::make(BOOST_PP_ENUM_PARAMS(BOOST_PP_MAX(N, 1), a));
|
Chris@16
|
128 }
|
Chris@16
|
129 };
|
Chris@16
|
130
|
Chris@16
|
131 template<typename Type BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
|
Chris@16
|
132 BOOST_FORCEINLINE
|
Chris@16
|
133 Type construct(BOOST_PP_ENUM_BINARY_PARAMS(N, A, &a))
|
Chris@16
|
134 {
|
Chris@16
|
135 return construct_<Type>()(BOOST_PP_ENUM_PARAMS(N, a));
|
Chris@16
|
136 }
|
Chris@16
|
137
|
Chris@16
|
138 } // namespace detail
|
Chris@16
|
139
|
Chris@16
|
140 /// \brief A PrimitiveTransform which computes a type by evaluating any
|
Chris@16
|
141 /// nested transforms and then constructs an object of that type with the
|
Chris@16
|
142 /// current expression, state and data, transformed according
|
Chris@16
|
143 /// to \c A0 through \c AN.
|
Chris@16
|
144 template<typename Object BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
|
Chris@16
|
145 struct make<Object(BOOST_PP_ENUM_PARAMS(N, A))>
|
Chris@16
|
146 : transform<make<Object(BOOST_PP_ENUM_PARAMS(N, A))> >
|
Chris@16
|
147 {
|
Chris@16
|
148 template<typename Expr, typename State, typename Data>
|
Chris@16
|
149 struct impl : transform_impl<Expr, State, Data>
|
Chris@16
|
150 {
|
Chris@16
|
151 /// \brief <tt>boost::result_of\<make\<Object\>(Expr, State, Data)\>::type</tt>
|
Chris@16
|
152 typedef typename detail::make_if_<Object, Expr, State, Data>::type result_type;
|
Chris@16
|
153
|
Chris@16
|
154 /// Let \c ax be <tt>when\<_, Ax\>()(e, s, d)</tt>
|
Chris@16
|
155 /// for each \c x in <tt>[0,N]</tt>.
|
Chris@16
|
156 /// Return <tt>result_type(a0, a1,... aN)</tt>.
|
Chris@16
|
157 ///
|
Chris@16
|
158 /// \param e The current expression
|
Chris@16
|
159 /// \param s The current state
|
Chris@16
|
160 /// \param d An arbitrary data
|
Chris@16
|
161 BOOST_FORCEINLINE
|
Chris@16
|
162 result_type operator ()(
|
Chris@16
|
163 typename impl::expr_param e
|
Chris@16
|
164 , typename impl::state_param s
|
Chris@16
|
165 , typename impl::data_param d
|
Chris@16
|
166 ) const
|
Chris@16
|
167 {
|
Chris@16
|
168 proto::detail::ignore_unused(e);
|
Chris@16
|
169 proto::detail::ignore_unused(s);
|
Chris@16
|
170 proto::detail::ignore_unused(d);
|
Chris@16
|
171 return detail::construct<result_type>(BOOST_PP_ENUM(N, BOOST_PROTO_CONSTRUCT_ARG, DATA));
|
Chris@16
|
172 }
|
Chris@16
|
173 };
|
Chris@16
|
174 };
|
Chris@16
|
175
|
Chris@16
|
176 #if N > 0
|
Chris@16
|
177 /// \brief A PrimitiveTransform which computes a type by evaluating any
|
Chris@16
|
178 /// nested transforms and then constructs an object of that type with the
|
Chris@16
|
179 /// current expression, state and data, transformed according
|
Chris@16
|
180 /// to \c A0 through \c AN.
|
Chris@16
|
181 template<typename Object BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
|
Chris@16
|
182 struct make<Object(BOOST_PP_ENUM_PARAMS(N, A)...)>
|
Chris@16
|
183 : transform<make<Object(BOOST_PP_ENUM_PARAMS(N, A)...)> >
|
Chris@16
|
184 {
|
Chris@16
|
185 template<typename Expr, typename State, typename Data>
|
Chris@16
|
186 struct impl
|
Chris@16
|
187 : make<
|
Chris@16
|
188 typename detail::expand_pattern<
|
Chris@16
|
189 proto::arity_of<Expr>::value
|
Chris@16
|
190 , BOOST_PP_CAT(A, BOOST_PP_DEC(N))
|
Chris@16
|
191 , detail::BOOST_PP_CAT(expand_pattern_rest_, BOOST_PP_DEC(N))<
|
Chris@16
|
192 Object
|
Chris@16
|
193 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_DEC(N), A)
|
Chris@16
|
194 >
|
Chris@16
|
195 >::type
|
Chris@16
|
196 >::template impl<Expr, State, Data>
|
Chris@16
|
197 {};
|
Chris@16
|
198 };
|
Chris@16
|
199 #endif
|
Chris@16
|
200 #undef N
|
Chris@16
|
201
|
Chris@16
|
202 #endif
|