Chris@16
|
1 #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
|
Chris@16
|
2
|
Chris@16
|
3 #include <boost/proto/context/detail/preprocessed/callable_eval.hpp>
|
Chris@16
|
4
|
Chris@16
|
5 #elif !defined(BOOST_PP_IS_ITERATING)
|
Chris@16
|
6
|
Chris@16
|
7 #define BOOST_PROTO_CHILD_N_TYPE(Z, N, Expr) \
|
Chris@16
|
8 typedef typename proto::result_of::child_c<Expr const &, N>::type BOOST_PP_CAT(child, N); \
|
Chris@16
|
9 /**/
|
Chris@16
|
10
|
Chris@16
|
11 #define BOOST_PROTO_CHILD_N(Z, N, expr) \
|
Chris@16
|
12 proto::child_c<N>(expr) \
|
Chris@16
|
13 /**/
|
Chris@16
|
14
|
Chris@16
|
15 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
16 #pragma wave option(preserve: 2, line: 0, output: "preprocessed/callable_eval.hpp")
|
Chris@16
|
17 #endif
|
Chris@16
|
18
|
Chris@16
|
19 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
20 /// \file callable_eval.hpp
|
Chris@16
|
21 /// Contains specializations of the callable_eval\<\> class template.
|
Chris@16
|
22 //
|
Chris@16
|
23 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
24 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
25 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
26
|
Chris@16
|
27 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
28 #pragma wave option(preserve: 1)
|
Chris@16
|
29 #endif
|
Chris@16
|
30
|
Chris@16
|
31 #define BOOST_PP_ITERATION_PARAMS_1 \
|
Chris@16
|
32 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/context/detail/callable_eval.hpp>))
|
Chris@16
|
33 #include BOOST_PP_ITERATE()
|
Chris@16
|
34
|
Chris@16
|
35 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
36 #pragma wave option(output: null)
|
Chris@16
|
37 #endif
|
Chris@16
|
38
|
Chris@16
|
39 #undef BOOST_PROTO_CHILD_N_TYPE
|
Chris@16
|
40 #undef BOOST_PROTO_CHILD_N
|
Chris@16
|
41
|
Chris@16
|
42 #else
|
Chris@16
|
43
|
Chris@16
|
44 #define N BOOST_PP_ITERATION()
|
Chris@16
|
45
|
Chris@16
|
46 namespace detail
|
Chris@16
|
47 {
|
Chris@16
|
48 template<typename Expr, typename Context>
|
Chris@16
|
49 struct is_expr_handled<Expr, Context, N>
|
Chris@16
|
50 {
|
Chris@16
|
51 static callable_context_wrapper<Context> &sctx_;
|
Chris@16
|
52 static Expr &sexpr_;
|
Chris@16
|
53 static typename Expr::proto_tag &stag_;
|
Chris@16
|
54
|
Chris@16
|
55 static const bool value =
|
Chris@16
|
56 sizeof(yes_type) ==
|
Chris@16
|
57 sizeof(
|
Chris@16
|
58 detail::check_is_expr_handled(
|
Chris@16
|
59 (sctx_(
|
Chris@16
|
60 stag_
|
Chris@16
|
61 BOOST_PP_ENUM_TRAILING(N, BOOST_PROTO_CHILD_N, sexpr_)
|
Chris@16
|
62 ), 0)
|
Chris@16
|
63 )
|
Chris@16
|
64 );
|
Chris@16
|
65
|
Chris@16
|
66 typedef mpl::bool_<value> type;
|
Chris@16
|
67 };
|
Chris@16
|
68 }
|
Chris@16
|
69
|
Chris@16
|
70 namespace context
|
Chris@16
|
71 {
|
Chris@16
|
72 /// \brief A BinaryFunction that accepts a Proto expression and a
|
Chris@16
|
73 /// callable context and calls the context with the expression tag
|
Chris@16
|
74 /// and children as arguments, effectively fanning the expression
|
Chris@16
|
75 /// out.
|
Chris@16
|
76 ///
|
Chris@16
|
77 /// <tt>callable_eval\<\></tt> requires that \c Context is a
|
Chris@16
|
78 /// PolymorphicFunctionObject that can be invoked with \c Expr's
|
Chris@16
|
79 /// tag and children as expressions, as follows:
|
Chris@16
|
80 ///
|
Chris@16
|
81 /// \code
|
Chris@16
|
82 /// context(Expr::proto_tag(), child_c\<0\>(expr), child_c\<1\>(expr), ...)
|
Chris@16
|
83 /// \endcode
|
Chris@16
|
84 template<typename Expr, typename Context>
|
Chris@16
|
85 struct callable_eval<Expr, Context, N>
|
Chris@16
|
86 {
|
Chris@16
|
87 BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD_N_TYPE, Expr)
|
Chris@16
|
88
|
Chris@16
|
89 typedef
|
Chris@16
|
90 typename BOOST_PROTO_RESULT_OF<
|
Chris@16
|
91 Context(
|
Chris@16
|
92 typename Expr::proto_tag
|
Chris@16
|
93 BOOST_PP_ENUM_TRAILING_PARAMS(N, child)
|
Chris@16
|
94 )
|
Chris@16
|
95 >::type
|
Chris@16
|
96 result_type;
|
Chris@16
|
97
|
Chris@16
|
98 /// \param expr The current expression
|
Chris@16
|
99 /// \param context The callable evaluation context
|
Chris@16
|
100 /// \return <tt>context(Expr::proto_tag(), child_c\<0\>(expr), child_c\<1\>(expr), ...)</tt>
|
Chris@16
|
101 result_type operator ()(Expr &expr, Context &context) const
|
Chris@16
|
102 {
|
Chris@16
|
103 return context(
|
Chris@16
|
104 typename Expr::proto_tag()
|
Chris@16
|
105 BOOST_PP_ENUM_TRAILING(N, BOOST_PROTO_CHILD_N, expr)
|
Chris@16
|
106 );
|
Chris@16
|
107 }
|
Chris@16
|
108 };
|
Chris@16
|
109 }
|
Chris@16
|
110
|
Chris@16
|
111 #undef N
|
Chris@16
|
112
|
Chris@16
|
113 #endif
|