1 #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
3 #ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
4 #include <boost/proto/detail/preprocessed/expr_variadic.hpp>
6 #include <boost/proto/detail/preprocessed/expr.hpp>
9 #elif !defined(BOOST_PP_IS_ITERATING)
13 #define BOOST_PROTO_CHILD(Z, N, DATA) \
14 typedef BOOST_PP_CAT(Arg, N) BOOST_PP_CAT(proto_child, N); \
15 BOOST_PP_CAT(proto_child, N) BOOST_PP_CAT(child, N); \
20 #define BOOST_PROTO_VOID(Z, N, DATA) \
21 typedef void BOOST_PP_CAT(proto_child, N); \
24 // Generate variadic versions of expr
25 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
26 #pragma wave option(preserve: 2, line: 0, output: "preprocessed/expr_variadic.hpp")
29 ///////////////////////////////////////////////////////////////////////////////
30 /// \file expr_variadic.hpp
31 /// Contains definition of expr\<\> class template.
33 // Copyright 2008 Eric Niebler. Distributed under the Boost
34 // Software License, Version 1.0. (See accompanying file
35 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
37 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
38 #pragma wave option(preserve: 1)
41 // The expr<> specializations are actually defined here.
42 #define BOOST_PROTO_DEFINE_TERMINAL
43 #define BOOST_PP_ITERATION_PARAMS_1 \
44 (3, (0, 0, <boost/proto/detail/expr.hpp>))
45 #include BOOST_PP_ITERATE()
47 #undef BOOST_PROTO_DEFINE_TERMINAL
48 #define BOOST_PP_ITERATION_PARAMS_1 \
49 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/detail/expr.hpp>))
50 #include BOOST_PP_ITERATE()
52 // Generate non-variadic versions of expr
53 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
54 #define BOOST_NO_CXX11_VARIADIC_TEMPLATES
55 #pragma wave option(preserve: 2, line: 0, output: "preprocessed/expr.hpp")
57 ///////////////////////////////////////////////////////////////////////////////
59 /// Contains definition of expr\<\> class template.
61 // Copyright 2008 Eric Niebler. Distributed under the Boost
62 // Software License, Version 1.0. (See accompanying file
63 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
65 #pragma wave option(preserve: 1)
67 // The expr<> specializations are actually defined here.
68 #define BOOST_PROTO_DEFINE_TERMINAL
69 #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, <boost/proto/detail/expr.hpp>))
70 #include BOOST_PP_ITERATE()
72 #undef BOOST_PROTO_DEFINE_TERMINAL
73 #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/detail/expr.hpp>))
74 #include BOOST_PP_ITERATE()
76 #pragma wave option(output: null)
77 #undef BOOST_NO_CXX11_VARIADIC_TEMPLATES
80 #undef BOOST_PROTO_CHILD
81 #undef BOOST_PROTO_VOID
85 #define ARG_COUNT BOOST_PP_MAX(1, BOOST_PP_ITERATION())
87 /// \brief Representation of a node in an expression tree.
89 /// \c proto::expr\<\> is a node in an expression template tree. It
90 /// is a container for its child sub-trees. It also serves as
91 /// the terminal nodes of the tree.
93 /// \c Tag is type that represents the operation encoded by
94 /// this expression. It is typically one of the structs
95 /// in the \c boost::proto::tag namespace, but it doesn't
98 /// \c Args is a type list representing the type of the children
99 /// of this expression. It is an instantiation of one
100 /// of \c proto::list1\<\>, \c proto::list2\<\>, etc. The
101 /// child types must all themselves be either \c expr\<\>
102 /// or <tt>proto::expr\<\>&</tt>. If \c Args is an
103 /// instantiation of \c proto::term\<\> then this
104 /// \c expr\<\> type represents a terminal expression;
105 /// the parameter to the \c proto::term\<\> template
106 /// represents the terminal's value type.
108 /// \c Arity is an integral constant representing the number of child
109 /// nodes this node contains. If \c Arity is 0, then this
110 /// node is a terminal.
112 /// \c proto::expr\<\> is a valid Fusion random-access sequence, where
113 /// the elements of the sequence are the child expressions.
114 #ifdef BOOST_PROTO_DEFINE_TERMINAL
115 template<typename Tag, typename Arg0>
116 struct expr<Tag, term<Arg0>, 0>
118 template<typename Tag BOOST_PP_ENUM_TRAILING_PARAMS(ARG_COUNT, typename Arg)>
119 struct expr<Tag, BOOST_PP_CAT(list, BOOST_PP_ITERATION())<BOOST_PP_ENUM_PARAMS(ARG_COUNT, Arg)>, BOOST_PP_ITERATION() >
122 typedef Tag proto_tag;
123 static const long proto_arity_c = BOOST_PP_ITERATION();
124 typedef mpl::long_<BOOST_PP_ITERATION() > proto_arity;
125 typedef expr proto_base_expr;
126 #ifdef BOOST_PROTO_DEFINE_TERMINAL
127 typedef term<Arg0> proto_args;
129 typedef BOOST_PP_CAT(list, BOOST_PP_ITERATION())<BOOST_PP_ENUM_PARAMS(ARG_COUNT, Arg)> proto_args;
131 typedef basic_expr<Tag, proto_args, BOOST_PP_ITERATION() > proto_grammar;
132 typedef default_domain proto_domain;
133 typedef default_generator proto_generator;
134 typedef proto::tag::proto_expr<Tag, proto_domain> fusion_tag;
135 typedef expr proto_derived_expr;
136 typedef void proto_is_expr_; /**< INTERNAL ONLY */
138 BOOST_PP_REPEAT(ARG_COUNT, BOOST_PROTO_CHILD, ~)
139 BOOST_PP_REPEAT_FROM_TO(ARG_COUNT, BOOST_PROTO_MAX_ARITY, BOOST_PROTO_VOID, ~)
144 expr const &proto_base() const
157 #ifdef BOOST_PROTO_DEFINE_TERMINAL
158 /// \return A new \c expr\<\> object initialized with the specified
161 template<typename A0>
163 static expr const make(A0 &a0)
165 return detail::make_terminal(a0, static_cast<expr *>(0), static_cast<proto_args *>(0));
170 template<typename A0>
172 static expr const make(A0 const &a0)
174 return detail::make_terminal(a0, static_cast<expr *>(0), static_cast<proto_args *>(0));
177 /// \return A new \c expr\<\> object initialized with the specified
180 template<BOOST_PP_ENUM_PARAMS(ARG_COUNT, typename A)>
182 static expr const make(BOOST_PP_ENUM_BINARY_PARAMS(ARG_COUNT, A, const &a))
184 expr that = {BOOST_PP_ENUM_PARAMS(ARG_COUNT, a)};
189 #if 1 == BOOST_PP_ITERATION()
190 /// If \c Tag is \c boost::proto::tag::address_of and \c proto_child0 is
191 /// <tt>T&</tt>, then \c address_of_hack_type_ is <tt>T*</tt>.
192 /// Otherwise, it is some undefined type.
193 typedef typename detail::address_of_hack<Tag, proto_child0>::type address_of_hack_type_;
195 /// \return The address of <tt>this->child0</tt> if \c Tag is
196 /// \c boost::proto::tag::address_of. Otherwise, this function will
199 /// \attention Proto overloads <tt>operator&</tt>, which means that
200 /// proto-ified objects cannot have their addresses taken, unless we use
201 /// the following hack to make \c &x implicitly convertible to \c X*.
203 operator address_of_hack_type_() const
205 return boost::addressof(this->child0);
210 typedef detail::not_a_valid_type address_of_hack_type_;
215 /// \param a The rhs.
216 /// \return A new \c expr\<\> node representing an assignment of \c that to \c *this.
220 , list2<expr &, expr const &>
223 operator =(expr const &a)
227 , list2<expr &, expr const &>
235 /// \param a The rhs.
236 /// \return A new \c expr\<\> node representing an assignment of \c a to \c *this.
241 , list2<expr const &, typename result_of::as_child<A>::type>
244 operator =(A &a) const
248 , list2<expr const &, typename result_of::as_child<A>::type>
250 > that = {*this, proto::as_child(a)};
260 , list2<expr const &, typename result_of::as_child<A const>::type>
263 operator =(A const &a) const
267 , list2<expr const &, typename result_of::as_child<A const>::type>
269 > that = {*this, proto::as_child(a)};
273 #ifdef BOOST_PROTO_DEFINE_TERMINAL
280 , list2<expr &, typename result_of::as_child<A>::type>
287 , list2<expr &, typename result_of::as_child<A>::type>
289 > that = {*this, proto::as_child(a)};
299 , list2<expr &, typename result_of::as_child<A const>::type>
302 operator =(A const &a)
306 , list2<expr &, typename result_of::as_child<A const>::type>
308 > that = {*this, proto::as_child(a)};
315 /// \param a The rhs.
316 /// \return A new \c expr\<\> node representing \c *this subscripted with \c a.
320 proto::tag::subscript
321 , list2<expr const &, typename result_of::as_child<A>::type>
324 operator [](A &a) const
327 proto::tag::subscript
328 , list2<expr const &, typename result_of::as_child<A>::type>
330 > that = {*this, proto::as_child(a)};
339 proto::tag::subscript
340 , list2<expr const &, typename result_of::as_child<A const>::type>
343 operator [](A const &a) const
346 proto::tag::subscript
347 , list2<expr const &, typename result_of::as_child<A const>::type>
349 > that = {*this, proto::as_child(a)};
353 #ifdef BOOST_PROTO_DEFINE_TERMINAL
359 proto::tag::subscript
360 , list2<expr &, typename result_of::as_child<A>::type>
366 proto::tag::subscript
367 , list2<expr &, typename result_of::as_child<A>::type>
369 > that = {*this, proto::as_child(a)};
378 proto::tag::subscript
379 , list2<expr &, typename result_of::as_child<A const>::type>
382 operator [](A const &a)
385 proto::tag::subscript
386 , list2<expr &, typename result_of::as_child<A const>::type>
388 > that = {*this, proto::as_child(a)};
393 /// Encodes the return type of \c expr\<\>::operator(), for use with \c boost::result_of\<\>
395 template<typename Sig>
398 typedef typename result_of::funop<Sig, expr, default_domain>::type const type;
401 #ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
404 template<typename ...A>
406 typename result_of::funop<
407 expr const(A const &...)
411 operator ()(A const &... a) const
413 return result_of::funop<
414 expr const(A const &...)
417 >::call(*this, a...);
420 #ifdef BOOST_PROTO_DEFINE_TERMINAL
423 template<typename ...A>
425 typename result_of::funop<
430 operator ()(A const &... a)
432 return result_of::funop<
436 >::call(*this, a...);
440 #else // BOOST_NO_CXX11_VARIADIC_TEMPLATES
444 /// \return A new \c expr\<\> node representing the function invocation of \c (*this)().
446 proto::expr<proto::tag::function, list1<expr const &>, 1> const
449 proto::expr<proto::tag::function, list1<expr const &>, 1> that = {*this};
453 #ifdef BOOST_PROTO_DEFINE_TERMINAL
457 proto::expr<proto::tag::function, list1<expr &>, 1> const
460 proto::expr<proto::tag::function, list1<expr &>, 1> that = {*this};
465 #define BOOST_PP_ITERATION_PARAMS_2 \
466 (3, (1, BOOST_PP_DEC(BOOST_PROTO_MAX_FUNCTION_CALL_ARITY), <boost/proto/detail/expr_funop.hpp>))
467 #include BOOST_PP_ITERATE()