| 1 | #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES) |
| 2 | |
| 3 | #include <boost/proto/detail/preprocessed/traits.hpp> |
| 4 | |
| 5 | #elif !defined(BOOST_PP_IS_ITERATING) |
| 6 | |
| 7 | #define BOOST_PROTO_CHILD(Z, N, DATA) \ |
| 8 | /** INTERNAL ONLY */ \ |
| 9 | typedef BOOST_PP_CAT(DATA, N) BOOST_PP_CAT(proto_child, N); \ |
| 10 | /**/ |
| 11 | |
| 12 | #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) |
| 13 | #pragma wave option(preserve: 2, line: 0, output: "preprocessed/traits.hpp") |
| 14 | #endif |
| 15 | |
| 16 | /////////////////////////////////////////////////////////////////////////////// |
| 17 | /// \file traits.hpp |
| 18 | /// Definitions of proto::function, proto::nary_expr and proto::result_of::child_c |
| 19 | // |
| 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) |
| 23 | |
| 24 | #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) |
| 25 | #pragma wave option(preserve: 1) |
| 26 | #endif |
| 27 | |
| 28 | #define BOOST_PP_ITERATION_PARAMS_1 \ |
| 29 | (3, (0, BOOST_PROTO_MAX_ARITY, <boost/proto/detail/traits.hpp>)) |
| 30 | #include BOOST_PP_ITERATE() |
| 31 | |
| 32 | #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) |
| 33 | #pragma wave option(output: null) |
| 34 | #endif |
| 35 | |
| 36 | #undef BOOST_PROTO_CHILD |
| 37 | |
| 38 | #else // BOOST_PP_IS_ITERATING |
| 39 | |
| 40 | #define N BOOST_PP_ITERATION() |
| 41 | |
| 42 | #if N > 0 |
| 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> |
| 46 | /// transform. |
| 47 | template<BOOST_PP_ENUM_PARAMS(N, typename A)> |
| 48 | struct function |
| 49 | #if N != BOOST_PROTO_MAX_ARITY |
| 50 | < |
| 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) |
| 53 | > |
| 54 | #endif |
| 55 | : proto::transform< |
| 56 | function< |
| 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) |
| 59 | > |
| 60 | , int |
| 61 | > |
| 62 | { |
| 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; |
| 65 | |
| 66 | template<typename Expr, typename State, typename Data> |
| 67 | struct impl |
| 68 | : detail::pass_through_impl<function, deduce_domain, Expr, State, Data> |
| 69 | {}; |
| 70 | |
| 71 | /// INTERNAL ONLY |
| 72 | typedef proto::tag::function proto_tag; |
| 73 | BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD, A) |
| 74 | BOOST_PP_REPEAT_FROM_TO( |
| 75 | N |
| 76 | , BOOST_PROTO_MAX_ARITY |
| 77 | , BOOST_PROTO_CHILD |
| 78 | , detail::if_vararg<BOOST_PP_CAT(A, BOOST_PP_DEC(N))> BOOST_PP_INTERCEPT |
| 79 | ) |
| 80 | }; |
| 81 | |
| 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> |
| 86 | /// transform. |
| 87 | /// |
| 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)> |
| 91 | struct nary_expr |
| 92 | #if N != BOOST_PROTO_MAX_ARITY |
| 93 | < |
| 94 | Tag |
| 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) |
| 97 | > |
| 98 | #endif |
| 99 | : proto::transform< |
| 100 | nary_expr< |
| 101 | Tag |
| 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) |
| 104 | > |
| 105 | , int |
| 106 | > |
| 107 | { |
| 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; |
| 110 | |
| 111 | template<typename Expr, typename State, typename Data> |
| 112 | struct impl |
| 113 | : detail::pass_through_impl<nary_expr, deduce_domain, Expr, State, Data> |
| 114 | {}; |
| 115 | |
| 116 | /// INTERNAL ONLY |
| 117 | typedef Tag proto_tag; |
| 118 | BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD, A) |
| 119 | BOOST_PP_REPEAT_FROM_TO( |
| 120 | N |
| 121 | , BOOST_PROTO_MAX_ARITY |
| 122 | , BOOST_PROTO_CHILD |
| 123 | , detail::if_vararg<BOOST_PP_CAT(A, BOOST_PP_DEC(N))> BOOST_PP_INTERCEPT |
| 124 | ) |
| 125 | }; |
| 126 | |
| 127 | namespace detail |
| 128 | { |
| 129 | template< |
| 130 | template<BOOST_PP_ENUM_PARAMS(N, typename BOOST_PP_INTERCEPT)> class T |
| 131 | , BOOST_PP_ENUM_PARAMS(N, typename A) |
| 132 | > |
| 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> |
| 135 | {}; |
| 136 | } |
| 137 | |
| 138 | #endif |
| 139 | |
| 140 | namespace result_of |
| 141 | { |
| 142 | /// \brief A metafunction that returns the type of the Nth child |
| 143 | /// of a Proto expression. |
| 144 | /// |
| 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> |
| 150 | { |
| 151 | /// Verify that we are not operating on a terminal |
| 152 | BOOST_STATIC_ASSERT(0 != Expr::proto_arity_c); |
| 153 | |
| 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; |
| 157 | |
| 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; |
| 164 | }; |
| 165 | |
| 166 | template<typename Expr> |
| 167 | struct child_c<Expr &, N> |
| 168 | { |
| 169 | /// Verify that we are not operating on a terminal |
| 170 | BOOST_STATIC_ASSERT(0 != Expr::proto_arity_c); |
| 171 | |
| 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; |
| 175 | |
| 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; |
| 182 | |
| 183 | /// INTERNAL ONLY |
| 184 | /// |
| 185 | BOOST_FORCEINLINE |
| 186 | static type call(Expr &e) |
| 187 | { |
| 188 | return e.proto_base().BOOST_PP_CAT(child, N); |
| 189 | } |
| 190 | }; |
| 191 | |
| 192 | template<typename Expr> |
| 193 | struct child_c<Expr const &, N> |
| 194 | { |
| 195 | /// Verify that we are not operating on a terminal |
| 196 | BOOST_STATIC_ASSERT(0 != Expr::proto_arity_c); |
| 197 | |
| 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; |
| 201 | |
| 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; |
| 208 | |
| 209 | /// INTERNAL ONLY |
| 210 | /// |
| 211 | BOOST_FORCEINLINE |
| 212 | static type call(Expr const &e) |
| 213 | { |
| 214 | return e.proto_base().BOOST_PP_CAT(child, N); |
| 215 | } |
| 216 | }; |
| 217 | } |
| 218 | |
| 219 | #undef N |
| 220 | |
| 221 | #endif |
| 222 | |