Chris@16
|
1 #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
|
Chris@16
|
2
|
Chris@16
|
3 #include <boost/proto/detail/preprocessed/traits.hpp>
|
Chris@16
|
4
|
Chris@16
|
5 #elif !defined(BOOST_PP_IS_ITERATING)
|
Chris@16
|
6
|
Chris@16
|
7 #define BOOST_PROTO_CHILD(Z, N, DATA) \
|
Chris@16
|
8 /** INTERNAL ONLY */ \
|
Chris@16
|
9 typedef BOOST_PP_CAT(DATA, N) BOOST_PP_CAT(proto_child, N); \
|
Chris@16
|
10 /**/
|
Chris@16
|
11
|
Chris@16
|
12 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
13 #pragma wave option(preserve: 2, line: 0, output: "preprocessed/traits.hpp")
|
Chris@16
|
14 #endif
|
Chris@16
|
15
|
Chris@16
|
16 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
17 /// \file traits.hpp
|
Chris@16
|
18 /// Definitions of proto::function, proto::nary_expr and proto::result_of::child_c
|
Chris@16
|
19 //
|
Chris@16
|
20 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
21 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
22 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
23
|
Chris@16
|
24 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
25 #pragma wave option(preserve: 1)
|
Chris@16
|
26 #endif
|
Chris@16
|
27
|
Chris@16
|
28 #define BOOST_PP_ITERATION_PARAMS_1 \
|
Chris@16
|
29 (3, (0, BOOST_PROTO_MAX_ARITY, <boost/proto/detail/traits.hpp>))
|
Chris@16
|
30 #include BOOST_PP_ITERATE()
|
Chris@16
|
31
|
Chris@16
|
32 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
33 #pragma wave option(output: null)
|
Chris@16
|
34 #endif
|
Chris@16
|
35
|
Chris@16
|
36 #undef BOOST_PROTO_CHILD
|
Chris@16
|
37
|
Chris@16
|
38 #else // BOOST_PP_IS_ITERATING
|
Chris@16
|
39
|
Chris@16
|
40 #define N BOOST_PP_ITERATION()
|
Chris@16
|
41
|
Chris@16
|
42 #if N > 0
|
Chris@16
|
43 /// \brief A metafunction for generating function-call expression types,
|
Chris@16
|
44 /// a grammar element for matching function-call expressions, and a
|
Chris@16
|
45 /// PrimitiveTransform that dispatches to the <tt>pass_through\<\></tt>
|
Chris@16
|
46 /// transform.
|
Chris@16
|
47 template<BOOST_PP_ENUM_PARAMS(N, typename A)>
|
Chris@16
|
48 struct function
|
Chris@16
|
49 #if N != BOOST_PROTO_MAX_ARITY
|
Chris@16
|
50 <
|
Chris@16
|
51 BOOST_PP_ENUM_PARAMS(N, A)
|
Chris@16
|
52 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_SUB(BOOST_PROTO_MAX_ARITY, N), void BOOST_PP_INTERCEPT)
|
Chris@16
|
53 >
|
Chris@16
|
54 #endif
|
Chris@16
|
55 : proto::transform<
|
Chris@16
|
56 function<
|
Chris@16
|
57 BOOST_PP_ENUM_PARAMS(N, A)
|
Chris@16
|
58 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_SUB(BOOST_PROTO_MAX_ARITY, N), void BOOST_PP_INTERCEPT)
|
Chris@16
|
59 >
|
Chris@16
|
60 , int
|
Chris@16
|
61 >
|
Chris@16
|
62 {
|
Chris@16
|
63 typedef proto::expr<proto::tag::function, BOOST_PP_CAT(list, N)<BOOST_PP_ENUM_PARAMS(N, A)>, N> type;
|
Chris@16
|
64 typedef proto::basic_expr<proto::tag::function, BOOST_PP_CAT(list, N)<BOOST_PP_ENUM_PARAMS(N, A)>, N> proto_grammar;
|
Chris@16
|
65
|
Chris@16
|
66 template<typename Expr, typename State, typename Data>
|
Chris@16
|
67 struct impl
|
Chris@16
|
68 : detail::pass_through_impl<function, deduce_domain, Expr, State, Data>
|
Chris@16
|
69 {};
|
Chris@16
|
70
|
Chris@16
|
71 /// INTERNAL ONLY
|
Chris@16
|
72 typedef proto::tag::function proto_tag;
|
Chris@16
|
73 BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD, A)
|
Chris@16
|
74 BOOST_PP_REPEAT_FROM_TO(
|
Chris@16
|
75 N
|
Chris@16
|
76 , BOOST_PROTO_MAX_ARITY
|
Chris@16
|
77 , BOOST_PROTO_CHILD
|
Chris@16
|
78 , detail::if_vararg<BOOST_PP_CAT(A, BOOST_PP_DEC(N))> BOOST_PP_INTERCEPT
|
Chris@16
|
79 )
|
Chris@16
|
80 };
|
Chris@16
|
81
|
Chris@16
|
82 /// \brief A metafunction for generating n-ary expression types with a
|
Chris@16
|
83 /// specified tag type,
|
Chris@16
|
84 /// a grammar element for matching n-ary expressions, and a
|
Chris@16
|
85 /// PrimitiveTransform that dispatches to the <tt>pass_through\<\></tt>
|
Chris@16
|
86 /// transform.
|
Chris@16
|
87 ///
|
Chris@16
|
88 /// Use <tt>nary_expr\<_, vararg\<_\> \></tt> as a grammar element to match any
|
Chris@16
|
89 /// n-ary expression; that is, any non-terminal.
|
Chris@16
|
90 template<typename Tag BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
|
Chris@16
|
91 struct nary_expr
|
Chris@16
|
92 #if N != BOOST_PROTO_MAX_ARITY
|
Chris@16
|
93 <
|
Chris@16
|
94 Tag
|
Chris@16
|
95 BOOST_PP_ENUM_TRAILING_PARAMS(N, A)
|
Chris@16
|
96 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_SUB(BOOST_PROTO_MAX_ARITY, N), void BOOST_PP_INTERCEPT)
|
Chris@16
|
97 >
|
Chris@16
|
98 #endif
|
Chris@16
|
99 : proto::transform<
|
Chris@16
|
100 nary_expr<
|
Chris@16
|
101 Tag
|
Chris@16
|
102 BOOST_PP_ENUM_TRAILING_PARAMS(N, A)
|
Chris@16
|
103 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_SUB(BOOST_PROTO_MAX_ARITY, N), void BOOST_PP_INTERCEPT)
|
Chris@16
|
104 >
|
Chris@16
|
105 , int
|
Chris@16
|
106 >
|
Chris@16
|
107 {
|
Chris@16
|
108 typedef proto::expr<Tag, BOOST_PP_CAT(list, N)<BOOST_PP_ENUM_PARAMS(N, A)>, N> type;
|
Chris@16
|
109 typedef proto::basic_expr<Tag, BOOST_PP_CAT(list, N)<BOOST_PP_ENUM_PARAMS(N, A)>, N> proto_grammar;
|
Chris@16
|
110
|
Chris@16
|
111 template<typename Expr, typename State, typename Data>
|
Chris@16
|
112 struct impl
|
Chris@16
|
113 : detail::pass_through_impl<nary_expr, deduce_domain, Expr, State, Data>
|
Chris@16
|
114 {};
|
Chris@16
|
115
|
Chris@16
|
116 /// INTERNAL ONLY
|
Chris@16
|
117 typedef Tag proto_tag;
|
Chris@16
|
118 BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD, A)
|
Chris@16
|
119 BOOST_PP_REPEAT_FROM_TO(
|
Chris@16
|
120 N
|
Chris@16
|
121 , BOOST_PROTO_MAX_ARITY
|
Chris@16
|
122 , BOOST_PROTO_CHILD
|
Chris@16
|
123 , detail::if_vararg<BOOST_PP_CAT(A, BOOST_PP_DEC(N))> BOOST_PP_INTERCEPT
|
Chris@16
|
124 )
|
Chris@16
|
125 };
|
Chris@16
|
126
|
Chris@16
|
127 namespace detail
|
Chris@16
|
128 {
|
Chris@16
|
129 template<
|
Chris@16
|
130 template<BOOST_PP_ENUM_PARAMS(N, typename BOOST_PP_INTERCEPT)> class T
|
Chris@16
|
131 , BOOST_PP_ENUM_PARAMS(N, typename A)
|
Chris@16
|
132 >
|
Chris@16
|
133 struct is_callable_<T<BOOST_PP_ENUM_PARAMS(N, A)> BOOST_PROTO_TEMPLATE_ARITY_PARAM(N)>
|
Chris@16
|
134 : is_same<BOOST_PP_CAT(A, BOOST_PP_DEC(N)), callable>
|
Chris@16
|
135 {};
|
Chris@16
|
136 }
|
Chris@16
|
137
|
Chris@16
|
138 #endif
|
Chris@16
|
139
|
Chris@16
|
140 namespace result_of
|
Chris@16
|
141 {
|
Chris@16
|
142 /// \brief A metafunction that returns the type of the Nth child
|
Chris@16
|
143 /// of a Proto expression.
|
Chris@16
|
144 ///
|
Chris@16
|
145 /// A metafunction that returns the type of the Nth child
|
Chris@16
|
146 /// of a Proto expression. \c N must be less than
|
Chris@16
|
147 /// \c Expr::proto_arity::value.
|
Chris@16
|
148 template<typename Expr>
|
Chris@16
|
149 struct child_c<Expr, N>
|
Chris@16
|
150 {
|
Chris@16
|
151 /// Verify that we are not operating on a terminal
|
Chris@16
|
152 BOOST_STATIC_ASSERT(0 != Expr::proto_arity_c);
|
Chris@16
|
153
|
Chris@16
|
154 /// The raw type of the Nth child as it is stored within
|
Chris@16
|
155 /// \c Expr. This may be a value or a reference
|
Chris@16
|
156 typedef typename Expr::BOOST_PP_CAT(proto_child, N) value_type;
|
Chris@16
|
157
|
Chris@16
|
158 /// The "value" type of the child, suitable for return by value,
|
Chris@16
|
159 /// computed as follows:
|
Chris@16
|
160 /// \li <tt>T const &</tt> becomes <tt>T</tt>
|
Chris@16
|
161 /// \li <tt>T &</tt> becomes <tt>T</tt>
|
Chris@16
|
162 /// \li <tt>T</tt> becomes <tt>T</tt>
|
Chris@16
|
163 typedef typename detail::expr_traits<typename Expr::BOOST_PP_CAT(proto_child, N)>::value_type type;
|
Chris@16
|
164 };
|
Chris@16
|
165
|
Chris@16
|
166 template<typename Expr>
|
Chris@16
|
167 struct child_c<Expr &, N>
|
Chris@16
|
168 {
|
Chris@16
|
169 /// Verify that we are not operating on a terminal
|
Chris@16
|
170 BOOST_STATIC_ASSERT(0 != Expr::proto_arity_c);
|
Chris@16
|
171
|
Chris@16
|
172 /// The raw type of the Nth child as it is stored within
|
Chris@16
|
173 /// \c Expr. This may be a value or a reference
|
Chris@16
|
174 typedef typename Expr::BOOST_PP_CAT(proto_child, N) value_type;
|
Chris@16
|
175
|
Chris@16
|
176 /// The "reference" type of the child, suitable for return by
|
Chris@16
|
177 /// reference, computed as follows:
|
Chris@16
|
178 /// \li <tt>T const &</tt> becomes <tt>T const &</tt>
|
Chris@16
|
179 /// \li <tt>T &</tt> becomes <tt>T &</tt>
|
Chris@16
|
180 /// \li <tt>T</tt> becomes <tt>T &</tt>
|
Chris@16
|
181 typedef typename detail::expr_traits<typename Expr::BOOST_PP_CAT(proto_child, N)>::reference type;
|
Chris@16
|
182
|
Chris@16
|
183 /// INTERNAL ONLY
|
Chris@16
|
184 ///
|
Chris@16
|
185 BOOST_FORCEINLINE
|
Chris@16
|
186 static type call(Expr &e)
|
Chris@16
|
187 {
|
Chris@16
|
188 return e.proto_base().BOOST_PP_CAT(child, N);
|
Chris@16
|
189 }
|
Chris@16
|
190 };
|
Chris@16
|
191
|
Chris@16
|
192 template<typename Expr>
|
Chris@16
|
193 struct child_c<Expr const &, N>
|
Chris@16
|
194 {
|
Chris@16
|
195 /// Verify that we are not operating on a terminal
|
Chris@16
|
196 BOOST_STATIC_ASSERT(0 != Expr::proto_arity_c);
|
Chris@16
|
197
|
Chris@16
|
198 /// The raw type of the Nth child as it is stored within
|
Chris@16
|
199 /// \c Expr. This may be a value or a reference
|
Chris@16
|
200 typedef typename Expr::BOOST_PP_CAT(proto_child, N) value_type;
|
Chris@16
|
201
|
Chris@16
|
202 /// The "const reference" type of the child, suitable for return by
|
Chris@16
|
203 /// const reference, computed as follows:
|
Chris@16
|
204 /// \li <tt>T const &</tt> becomes <tt>T const &</tt>
|
Chris@16
|
205 /// \li <tt>T &</tt> becomes <tt>T &</tt>
|
Chris@16
|
206 /// \li <tt>T</tt> becomes <tt>T const &</tt>
|
Chris@16
|
207 typedef typename detail::expr_traits<typename Expr::BOOST_PP_CAT(proto_child, N)>::const_reference type;
|
Chris@16
|
208
|
Chris@16
|
209 /// INTERNAL ONLY
|
Chris@16
|
210 ///
|
Chris@16
|
211 BOOST_FORCEINLINE
|
Chris@16
|
212 static type call(Expr const &e)
|
Chris@16
|
213 {
|
Chris@16
|
214 return e.proto_base().BOOST_PP_CAT(child, N);
|
Chris@16
|
215 }
|
Chris@16
|
216 };
|
Chris@16
|
217 }
|
Chris@16
|
218
|
Chris@16
|
219 #undef N
|
Chris@16
|
220
|
Chris@16
|
221 #endif
|