1 #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
3 #include <boost/proto/detail/preprocessed/traits.hpp>
5 #elif !defined(BOOST_PP_IS_ITERATING)
7 #define BOOST_PROTO_CHILD(Z, N, DATA) \
9 typedef BOOST_PP_CAT(DATA, N) BOOST_PP_CAT(proto_child, N); \
12 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
13 #pragma wave option(preserve: 2, line: 0, output: "preprocessed/traits.hpp")
16 ///////////////////////////////////////////////////////////////////////////////
18 /// Definitions of proto::function, proto::nary_expr and proto::result_of::child_c
20 // Copyright 2008 Eric Niebler. Distributed under the Boost
21 // Software License, Version 1.0. (See accompanying file
22 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
24 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
25 #pragma wave option(preserve: 1)
28 #define BOOST_PP_ITERATION_PARAMS_1 \
29 (3, (0, BOOST_PROTO_MAX_ARITY, <boost/proto/detail/traits.hpp>))
30 #include BOOST_PP_ITERATE()
32 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
33 #pragma wave option(output: null)
36 #undef BOOST_PROTO_CHILD
38 #else // BOOST_PP_IS_ITERATING
40 #define N BOOST_PP_ITERATION()
43 /// \brief A metafunction for generating function-call expression types,
44 /// a grammar element for matching function-call expressions, and a
45 /// PrimitiveTransform that dispatches to the <tt>pass_through\<\></tt>
47 template<BOOST_PP_ENUM_PARAMS(N, typename A)>
49 #if N != BOOST_PROTO_MAX_ARITY
51 BOOST_PP_ENUM_PARAMS(N, A)
52 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_SUB(BOOST_PROTO_MAX_ARITY, N), void BOOST_PP_INTERCEPT)
57 BOOST_PP_ENUM_PARAMS(N, A)
58 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_SUB(BOOST_PROTO_MAX_ARITY, N), void BOOST_PP_INTERCEPT)
63 typedef proto::expr<proto::tag::function, BOOST_PP_CAT(list, N)<BOOST_PP_ENUM_PARAMS(N, A)>, N> type;
64 typedef proto::basic_expr<proto::tag::function, BOOST_PP_CAT(list, N)<BOOST_PP_ENUM_PARAMS(N, A)>, N> proto_grammar;
66 template<typename Expr, typename State, typename Data>
68 : detail::pass_through_impl<function, deduce_domain, Expr, State, Data>
72 typedef proto::tag::function proto_tag;
73 BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD, A)
74 BOOST_PP_REPEAT_FROM_TO(
76 , BOOST_PROTO_MAX_ARITY
78 , detail::if_vararg<BOOST_PP_CAT(A, BOOST_PP_DEC(N))> BOOST_PP_INTERCEPT
82 /// \brief A metafunction for generating n-ary expression types with a
83 /// specified tag type,
84 /// a grammar element for matching n-ary expressions, and a
85 /// PrimitiveTransform that dispatches to the <tt>pass_through\<\></tt>
88 /// Use <tt>nary_expr\<_, vararg\<_\> \></tt> as a grammar element to match any
89 /// n-ary expression; that is, any non-terminal.
90 template<typename Tag BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
92 #if N != BOOST_PROTO_MAX_ARITY
95 BOOST_PP_ENUM_TRAILING_PARAMS(N, A)
96 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_SUB(BOOST_PROTO_MAX_ARITY, N), void BOOST_PP_INTERCEPT)
102 BOOST_PP_ENUM_TRAILING_PARAMS(N, A)
103 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_SUB(BOOST_PROTO_MAX_ARITY, N), void BOOST_PP_INTERCEPT)
108 typedef proto::expr<Tag, BOOST_PP_CAT(list, N)<BOOST_PP_ENUM_PARAMS(N, A)>, N> type;
109 typedef proto::basic_expr<Tag, BOOST_PP_CAT(list, N)<BOOST_PP_ENUM_PARAMS(N, A)>, N> proto_grammar;
111 template<typename Expr, typename State, typename Data>
113 : detail::pass_through_impl<nary_expr, deduce_domain, Expr, State, Data>
117 typedef Tag proto_tag;
118 BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD, A)
119 BOOST_PP_REPEAT_FROM_TO(
121 , BOOST_PROTO_MAX_ARITY
123 , detail::if_vararg<BOOST_PP_CAT(A, BOOST_PP_DEC(N))> BOOST_PP_INTERCEPT
130 template<BOOST_PP_ENUM_PARAMS(N, typename BOOST_PP_INTERCEPT)> class T
131 , BOOST_PP_ENUM_PARAMS(N, typename A)
133 struct is_callable_<T<BOOST_PP_ENUM_PARAMS(N, A)> BOOST_PROTO_TEMPLATE_ARITY_PARAM(N)>
134 : is_same<BOOST_PP_CAT(A, BOOST_PP_DEC(N)), callable>
142 /// \brief A metafunction that returns the type of the Nth child
143 /// of a Proto expression.
145 /// A metafunction that returns the type of the Nth child
146 /// of a Proto expression. \c N must be less than
147 /// \c Expr::proto_arity::value.
148 template<typename Expr>
149 struct child_c<Expr, N>
151 /// Verify that we are not operating on a terminal
152 BOOST_STATIC_ASSERT(0 != Expr::proto_arity_c);
154 /// The raw type of the Nth child as it is stored within
155 /// \c Expr. This may be a value or a reference
156 typedef typename Expr::BOOST_PP_CAT(proto_child, N) value_type;
158 /// The "value" type of the child, suitable for return by value,
159 /// computed as follows:
160 /// \li <tt>T const &</tt> becomes <tt>T</tt>
161 /// \li <tt>T &</tt> becomes <tt>T</tt>
162 /// \li <tt>T</tt> becomes <tt>T</tt>
163 typedef typename detail::expr_traits<typename Expr::BOOST_PP_CAT(proto_child, N)>::value_type type;
166 template<typename Expr>
167 struct child_c<Expr &, N>
169 /// Verify that we are not operating on a terminal
170 BOOST_STATIC_ASSERT(0 != Expr::proto_arity_c);
172 /// The raw type of the Nth child as it is stored within
173 /// \c Expr. This may be a value or a reference
174 typedef typename Expr::BOOST_PP_CAT(proto_child, N) value_type;
176 /// The "reference" type of the child, suitable for return by
177 /// reference, computed as follows:
178 /// \li <tt>T const &</tt> becomes <tt>T const &</tt>
179 /// \li <tt>T &</tt> becomes <tt>T &</tt>
180 /// \li <tt>T</tt> becomes <tt>T &</tt>
181 typedef typename detail::expr_traits<typename Expr::BOOST_PP_CAT(proto_child, N)>::reference type;
186 static type call(Expr &e)
188 return e.proto_base().BOOST_PP_CAT(child, N);
192 template<typename Expr>
193 struct child_c<Expr const &, N>
195 /// Verify that we are not operating on a terminal
196 BOOST_STATIC_ASSERT(0 != Expr::proto_arity_c);
198 /// The raw type of the Nth child as it is stored within
199 /// \c Expr. This may be a value or a reference
200 typedef typename Expr::BOOST_PP_CAT(proto_child, N) value_type;
202 /// The "const reference" type of the child, suitable for return by
203 /// const reference, computed as follows:
204 /// \li <tt>T const &</tt> becomes <tt>T const &</tt>
205 /// \li <tt>T &</tt> becomes <tt>T &</tt>
206 /// \li <tt>T</tt> becomes <tt>T const &</tt>
207 typedef typename detail::expr_traits<typename Expr::BOOST_PP_CAT(proto_child, N)>::const_reference type;
212 static type call(Expr const &e)
214 return e.proto_base().BOOST_PP_CAT(child, N);