annotate DEPENDENCIES/generic/include/boost/proto/transform/default.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 ///////////////////////////////////////////////////////////////////////////////
Chris@16 2 /// \file default.hpp
Chris@16 3 /// Contains definition of the _default transform, which gives operators their
Chris@16 4 /// usual C++ meanings and uses Boost.Typeof to deduce return types.
Chris@16 5 //
Chris@16 6 // Copyright 2008 Eric Niebler. Distributed under the Boost
Chris@16 7 // Software License, Version 1.0. (See accompanying file
Chris@16 8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9
Chris@16 10 #ifndef BOOST_PROTO_TRANSFORM_DEFAULT_HPP_EAN_04_04_2008
Chris@16 11 #define BOOST_PROTO_TRANSFORM_DEFAULT_HPP_EAN_04_04_2008
Chris@16 12
Chris@16 13 #include <boost/preprocessor/iteration/iterate.hpp>
Chris@16 14 #include <boost/preprocessor/repetition/repeat.hpp>
Chris@16 15 #include <boost/preprocessor/arithmetic/add.hpp>
Chris@16 16 #include <boost/preprocessor/arithmetic/sub.hpp>
Chris@16 17 #include <boost/preprocessor/repetition/enum.hpp>
Chris@16 18 #include <boost/preprocessor/repetition/enum_shifted.hpp>
Chris@16 19 #include <boost/preprocessor/repetition/enum_shifted_params.hpp>
Chris@16 20 #include <boost/ref.hpp>
Chris@16 21 #include <boost/get_pointer.hpp>
Chris@16 22 #include <boost/utility/enable_if.hpp>
Chris@16 23 #include <boost/type_traits/is_member_pointer.hpp>
Chris@16 24 #include <boost/type_traits/is_member_object_pointer.hpp>
Chris@16 25 #include <boost/type_traits/is_member_function_pointer.hpp>
Chris@16 26 #include <boost/proto/proto_fwd.hpp>
Chris@16 27 #include <boost/proto/traits.hpp>
Chris@16 28 #include <boost/proto/transform/impl.hpp>
Chris@16 29 #include <boost/proto/transform/arg.hpp>
Chris@16 30 #include <boost/proto/detail/decltype.hpp>
Chris@16 31
Chris@16 32 namespace boost { namespace proto
Chris@16 33 {
Chris@16 34 namespace detail
Chris@16 35 {
Chris@16 36 template<typename Grammar, typename Tag>
Chris@16 37 struct default_case
Chris@16 38 : not_<_>
Chris@16 39 {};
Chris@16 40
Chris@16 41 template<typename Grammar>
Chris@16 42 struct default_case<Grammar, tag::terminal>
Chris@16 43 : when<terminal<_>, _value>
Chris@16 44 {};
Chris@16 45
Chris@16 46 template<typename Grammar>
Chris@16 47 struct default_cases
Chris@16 48 {
Chris@16 49 template<typename Tag>
Chris@16 50 struct case_
Chris@16 51 : default_case<Grammar, Tag>
Chris@16 52 {};
Chris@16 53 };
Chris@16 54
Chris@16 55 #define BOOST_PROTO_UNARY_DEFAULT_EVAL(OP, TAG, MAKE) \
Chris@16 56 template<typename Grammar> \
Chris@16 57 struct BOOST_PP_CAT(default_, TAG) \
Chris@16 58 : transform<BOOST_PP_CAT(default_, TAG)<Grammar> > \
Chris@16 59 { \
Chris@16 60 template<typename Expr, typename State, typename Data> \
Chris@16 61 struct impl \
Chris@16 62 : transform_impl<Expr, State, Data> \
Chris@16 63 { \
Chris@16 64 private: \
Chris@16 65 typedef typename result_of::child_c<Expr, 0>::type e0; \
Chris@16 66 typedef typename Grammar::template impl<e0, State, Data>::result_type r0; \
Chris@16 67 public: \
Chris@16 68 BOOST_PROTO_DECLTYPE_(OP proto::detail::MAKE<r0>(), result_type) \
Chris@16 69 result_type operator ()( \
Chris@16 70 typename impl::expr_param e \
Chris@16 71 , typename impl::state_param s \
Chris@16 72 , typename impl::data_param d \
Chris@16 73 ) const \
Chris@16 74 { \
Chris@16 75 typename Grammar::template impl<e0, State, Data> t0; \
Chris@16 76 return OP t0(proto::child_c<0>(e), s, d); \
Chris@16 77 } \
Chris@16 78 }; \
Chris@16 79 }; \
Chris@16 80 \
Chris@16 81 template<typename Grammar> \
Chris@16 82 struct default_case<Grammar, tag::TAG> \
Chris@16 83 : when<unary_expr<tag::TAG, Grammar>, BOOST_PP_CAT(default_, TAG)<Grammar> > \
Chris@16 84 {}; \
Chris@16 85 /**/
Chris@16 86
Chris@16 87 #define BOOST_PROTO_BINARY_DEFAULT_EVAL(OP, TAG, LMAKE, RMAKE) \
Chris@16 88 template<typename Grammar> \
Chris@16 89 struct BOOST_PP_CAT(default_, TAG) \
Chris@16 90 : transform<BOOST_PP_CAT(default_, TAG)<Grammar> > \
Chris@16 91 { \
Chris@16 92 template<typename Expr, typename State, typename Data> \
Chris@16 93 struct impl \
Chris@16 94 : transform_impl<Expr, State, Data> \
Chris@16 95 { \
Chris@16 96 private: \
Chris@16 97 typedef typename result_of::child_c<Expr, 0>::type e0; \
Chris@16 98 typedef typename result_of::child_c<Expr, 1>::type e1; \
Chris@16 99 typedef typename Grammar::template impl<e0, State, Data>::result_type r0; \
Chris@16 100 typedef typename Grammar::template impl<e1, State, Data>::result_type r1; \
Chris@16 101 public: \
Chris@16 102 BOOST_PROTO_DECLTYPE_( \
Chris@16 103 proto::detail::LMAKE<r0>() OP proto::detail::RMAKE<r1>() \
Chris@16 104 , result_type \
Chris@16 105 ) \
Chris@16 106 result_type operator ()( \
Chris@16 107 typename impl::expr_param e \
Chris@16 108 , typename impl::state_param s \
Chris@16 109 , typename impl::data_param d \
Chris@16 110 ) const \
Chris@16 111 { \
Chris@16 112 typename Grammar::template impl<e0, State, Data> t0; \
Chris@16 113 typename Grammar::template impl<e1, State, Data> t1; \
Chris@16 114 return t0(proto::child_c<0>(e), s, d) \
Chris@16 115 OP t1(proto::child_c<1>(e), s, d); \
Chris@16 116 } \
Chris@16 117 }; \
Chris@16 118 }; \
Chris@16 119 \
Chris@16 120 template<typename Grammar> \
Chris@16 121 struct default_case<Grammar, tag::TAG> \
Chris@16 122 : when<binary_expr<tag::TAG, Grammar, Grammar>, BOOST_PP_CAT(default_, TAG)<Grammar> > \
Chris@16 123 {}; \
Chris@16 124 /**/
Chris@16 125
Chris@16 126 BOOST_PROTO_UNARY_DEFAULT_EVAL(+, unary_plus, make)
Chris@16 127 BOOST_PROTO_UNARY_DEFAULT_EVAL(-, negate, make)
Chris@16 128 BOOST_PROTO_UNARY_DEFAULT_EVAL(*, dereference, make)
Chris@16 129 BOOST_PROTO_UNARY_DEFAULT_EVAL(~, complement, make)
Chris@16 130 BOOST_PROTO_UNARY_DEFAULT_EVAL(&, address_of, make)
Chris@16 131 BOOST_PROTO_UNARY_DEFAULT_EVAL(!, logical_not, make)
Chris@16 132 BOOST_PROTO_UNARY_DEFAULT_EVAL(++, pre_inc, make_mutable)
Chris@16 133 BOOST_PROTO_UNARY_DEFAULT_EVAL(--, pre_dec, make_mutable)
Chris@16 134
Chris@16 135 BOOST_PROTO_BINARY_DEFAULT_EVAL(<<, shift_left, make_mutable, make)
Chris@16 136 BOOST_PROTO_BINARY_DEFAULT_EVAL(>>, shift_right, make_mutable, make_mutable)
Chris@16 137 BOOST_PROTO_BINARY_DEFAULT_EVAL(*, multiplies, make, make)
Chris@16 138 BOOST_PROTO_BINARY_DEFAULT_EVAL(/, divides, make, make)
Chris@16 139 BOOST_PROTO_BINARY_DEFAULT_EVAL(%, modulus, make, make)
Chris@16 140 BOOST_PROTO_BINARY_DEFAULT_EVAL(+, plus, make, make)
Chris@16 141 BOOST_PROTO_BINARY_DEFAULT_EVAL(-, minus, make, make)
Chris@16 142 BOOST_PROTO_BINARY_DEFAULT_EVAL(<, less, make, make)
Chris@16 143 BOOST_PROTO_BINARY_DEFAULT_EVAL(>, greater, make, make)
Chris@16 144 BOOST_PROTO_BINARY_DEFAULT_EVAL(<=, less_equal, make, make)
Chris@16 145 BOOST_PROTO_BINARY_DEFAULT_EVAL(>=, greater_equal, make, make)
Chris@16 146 BOOST_PROTO_BINARY_DEFAULT_EVAL(==, equal_to, make, make)
Chris@16 147 BOOST_PROTO_BINARY_DEFAULT_EVAL(!=, not_equal_to, make, make)
Chris@16 148 BOOST_PROTO_BINARY_DEFAULT_EVAL(||, logical_or, make, make)
Chris@16 149 BOOST_PROTO_BINARY_DEFAULT_EVAL(&&, logical_and, make, make)
Chris@16 150 BOOST_PROTO_BINARY_DEFAULT_EVAL(&, bitwise_and, make, make)
Chris@16 151 BOOST_PROTO_BINARY_DEFAULT_EVAL(|, bitwise_or, make, make)
Chris@16 152 BOOST_PROTO_BINARY_DEFAULT_EVAL(^, bitwise_xor, make, make)
Chris@16 153
Chris@16 154 BOOST_PROTO_BINARY_DEFAULT_EVAL(=, assign, make_mutable, make)
Chris@16 155 BOOST_PROTO_BINARY_DEFAULT_EVAL(<<=, shift_left_assign, make_mutable, make)
Chris@16 156 BOOST_PROTO_BINARY_DEFAULT_EVAL(>>=, shift_right_assign, make_mutable, make)
Chris@16 157 BOOST_PROTO_BINARY_DEFAULT_EVAL(*=, multiplies_assign, make_mutable, make)
Chris@16 158 BOOST_PROTO_BINARY_DEFAULT_EVAL(/=, divides_assign, make_mutable, make)
Chris@16 159 BOOST_PROTO_BINARY_DEFAULT_EVAL(%=, modulus_assign, make_mutable, make)
Chris@16 160 BOOST_PROTO_BINARY_DEFAULT_EVAL(+=, plus_assign, make_mutable, make)
Chris@16 161 BOOST_PROTO_BINARY_DEFAULT_EVAL(-=, minus_assign, make_mutable, make)
Chris@16 162 BOOST_PROTO_BINARY_DEFAULT_EVAL(&=, bitwise_and_assign, make_mutable, make)
Chris@16 163 BOOST_PROTO_BINARY_DEFAULT_EVAL(|=, bitwise_or_assign, make_mutable, make)
Chris@16 164 BOOST_PROTO_BINARY_DEFAULT_EVAL(^=, bitwise_xor_assign, make_mutable, make)
Chris@16 165
Chris@16 166 #undef BOOST_PROTO_UNARY_DEFAULT_EVAL
Chris@16 167 #undef BOOST_PROTO_BINARY_DEFAULT_EVAL
Chris@16 168
Chris@16 169 /// INTERNAL ONLY
Chris@16 170 template<typename Grammar, typename Expr, typename State, typename Data>
Chris@16 171 struct is_member_function_invocation
Chris@16 172 : is_member_function_pointer<
Chris@16 173 typename uncvref<
Chris@16 174 typename Grammar::template impl<
Chris@16 175 typename result_of::child_c<Expr, 1>::type
Chris@16 176 , State
Chris@16 177 , Data
Chris@16 178 >::result_type
Chris@16 179 >::type
Chris@16 180 >
Chris@16 181 {};
Chris@16 182
Chris@16 183 /// INTERNAL ONLY
Chris@16 184 template<typename Grammar, typename Expr, typename State, typename Data, bool IsMemFunCall>
Chris@16 185 struct default_mem_ptr_impl
Chris@16 186 : transform_impl<Expr, State, Data>
Chris@16 187 {
Chris@16 188 private:
Chris@16 189 typedef typename result_of::child_c<Expr, 0>::type e0;
Chris@16 190 typedef typename result_of::child_c<Expr, 1>::type e1;
Chris@16 191 typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
Chris@16 192 typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
Chris@16 193 public:
Chris@16 194 typedef typename detail::mem_ptr_fun<r0, r1>::result_type result_type;
Chris@16 195 result_type operator ()(
Chris@16 196 typename default_mem_ptr_impl::expr_param e
Chris@16 197 , typename default_mem_ptr_impl::state_param s
Chris@16 198 , typename default_mem_ptr_impl::data_param d
Chris@16 199 ) const
Chris@16 200 {
Chris@16 201 typename Grammar::template impl<e0, State, Data> t0;
Chris@16 202 typename Grammar::template impl<e1, State, Data> t1;
Chris@16 203 return detail::mem_ptr_fun<r0, r1>()(
Chris@16 204 t0(proto::child_c<0>(e), s, d)
Chris@16 205 , t1(proto::child_c<1>(e), s, d)
Chris@16 206 );
Chris@16 207 }
Chris@16 208 };
Chris@16 209
Chris@16 210 /// INTERNAL ONLY
Chris@16 211 template<typename Grammar, typename Expr, typename State, typename Data>
Chris@16 212 struct default_mem_ptr_impl<Grammar, Expr, State, Data, true>
Chris@16 213 : transform_impl<Expr, State, Data>
Chris@16 214 {
Chris@16 215 private:
Chris@16 216 typedef typename result_of::child_c<Expr, 0>::type e0;
Chris@16 217 typedef typename result_of::child_c<Expr, 1>::type e1;
Chris@16 218 typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
Chris@16 219 typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
Chris@16 220 public:
Chris@16 221 typedef detail::memfun<r0, r1> result_type;
Chris@16 222 result_type const operator ()(
Chris@16 223 typename default_mem_ptr_impl::expr_param e
Chris@16 224 , typename default_mem_ptr_impl::state_param s
Chris@16 225 , typename default_mem_ptr_impl::data_param d
Chris@16 226 ) const
Chris@16 227 {
Chris@16 228 typename Grammar::template impl<e0, State, Data> t0;
Chris@16 229 typename Grammar::template impl<e1, State, Data> t1;
Chris@16 230 return detail::memfun<r0, r1>(
Chris@16 231 t0(proto::child_c<0>(e), s, d)
Chris@16 232 , t1(proto::child_c<1>(e), s, d)
Chris@16 233 );
Chris@16 234 }
Chris@16 235 };
Chris@16 236
Chris@16 237 template<typename Grammar>
Chris@16 238 struct default_mem_ptr
Chris@16 239 : transform<default_mem_ptr<Grammar> >
Chris@16 240 {
Chris@16 241 template<typename Expr, typename State, typename Data>
Chris@16 242 struct impl
Chris@16 243 : default_mem_ptr_impl<
Chris@16 244 Grammar
Chris@16 245 , Expr
Chris@16 246 , State
Chris@16 247 , Data
Chris@16 248 , is_member_function_invocation<Grammar, Expr, State, Data>::value
Chris@16 249 >
Chris@16 250 {};
Chris@16 251 };
Chris@16 252
Chris@16 253 template<typename Grammar>
Chris@16 254 struct default_case<Grammar, tag::mem_ptr>
Chris@16 255 : when<mem_ptr<Grammar, Grammar>, default_mem_ptr<Grammar> >
Chris@16 256 {};
Chris@16 257
Chris@16 258 template<typename Grammar>
Chris@16 259 struct default_post_inc
Chris@16 260 : transform<default_post_inc<Grammar> >
Chris@16 261 {
Chris@16 262 template<typename Expr, typename State, typename Data>
Chris@16 263 struct impl
Chris@16 264 : transform_impl<Expr, State, Data>
Chris@16 265 {
Chris@16 266 private:
Chris@16 267 typedef typename result_of::child_c<Expr, 0>::type e0;
Chris@16 268 typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
Chris@16 269 public:
Chris@16 270 BOOST_PROTO_DECLTYPE_(proto::detail::make_mutable<r0>() ++, result_type)
Chris@16 271 result_type operator ()(
Chris@16 272 typename impl::expr_param e
Chris@16 273 , typename impl::state_param s
Chris@16 274 , typename impl::data_param d
Chris@16 275 ) const
Chris@16 276 {
Chris@16 277 typename Grammar::template impl<e0, State, Data> t0;
Chris@16 278 return t0(proto::child_c<0>(e), s, d) ++;
Chris@16 279 }
Chris@16 280 };
Chris@16 281 };
Chris@16 282
Chris@16 283 template<typename Grammar>
Chris@16 284 struct default_case<Grammar, tag::post_inc>
Chris@16 285 : when<post_inc<Grammar>, default_post_inc<Grammar> >
Chris@16 286 {};
Chris@16 287
Chris@16 288 template<typename Grammar>
Chris@16 289 struct default_post_dec
Chris@16 290 : transform<default_post_dec<Grammar> >
Chris@16 291 {
Chris@16 292 template<typename Expr, typename State, typename Data>
Chris@16 293 struct impl
Chris@16 294 : transform_impl<Expr, State, Data>
Chris@16 295 {
Chris@16 296 private:
Chris@16 297 typedef typename result_of::child_c<Expr, 0>::type e0;
Chris@16 298 typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
Chris@16 299 public:
Chris@16 300 BOOST_PROTO_DECLTYPE_(proto::detail::make_mutable<r0>() --, result_type)
Chris@16 301 result_type operator ()(
Chris@16 302 typename impl::expr_param e
Chris@16 303 , typename impl::state_param s
Chris@16 304 , typename impl::data_param d
Chris@16 305 ) const
Chris@16 306 {
Chris@16 307 typename Grammar::template impl<e0, State, Data> t0;
Chris@16 308 return t0(proto::child_c<0>(e), s, d) --;
Chris@16 309 }
Chris@16 310 };
Chris@16 311 };
Chris@16 312
Chris@16 313 template<typename Grammar>
Chris@16 314 struct default_case<Grammar, tag::post_dec>
Chris@16 315 : when<post_dec<Grammar>, default_post_dec<Grammar> >
Chris@16 316 {};
Chris@16 317
Chris@16 318 template<typename Grammar>
Chris@16 319 struct default_subscript
Chris@16 320 : transform<default_subscript<Grammar> >
Chris@16 321 {
Chris@16 322 template<typename Expr, typename State, typename Data>
Chris@16 323 struct impl
Chris@16 324 : transform_impl<Expr, State, Data>
Chris@16 325 {
Chris@16 326 private:
Chris@16 327 typedef typename result_of::child_c<Expr, 0>::type e0;
Chris@16 328 typedef typename result_of::child_c<Expr, 1>::type e1;
Chris@16 329 typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
Chris@16 330 typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
Chris@16 331 public:
Chris@16 332 BOOST_PROTO_DECLTYPE_(
Chris@16 333 proto::detail::make_subscriptable<r0>() [ proto::detail::make<r1>() ]
Chris@16 334 , result_type
Chris@16 335 )
Chris@16 336 result_type operator ()(
Chris@16 337 typename impl::expr_param e
Chris@16 338 , typename impl::state_param s
Chris@16 339 , typename impl::data_param d
Chris@16 340 ) const
Chris@16 341 {
Chris@16 342 typename Grammar::template impl<e0, State, Data> t0;
Chris@16 343 typename Grammar::template impl<e1, State, Data> t1;
Chris@16 344 return t0(proto::child_c<0>(e), s, d) [
Chris@16 345 t1(proto::child_c<1>(e), s, d) ];
Chris@16 346 }
Chris@16 347 };
Chris@16 348 };
Chris@16 349
Chris@16 350 template<typename Grammar>
Chris@16 351 struct default_case<Grammar, tag::subscript>
Chris@16 352 : when<subscript<Grammar, Grammar>, default_subscript<Grammar> >
Chris@16 353 {};
Chris@16 354
Chris@16 355 template<typename Grammar>
Chris@16 356 struct default_if_else_
Chris@16 357 {
Chris@16 358 template<typename Expr, typename State, typename Data>
Chris@16 359 struct impl
Chris@16 360 : transform_impl<Expr, State, Data>
Chris@16 361 {
Chris@16 362 private:
Chris@16 363 typedef typename result_of::child_c<Expr, 0>::type e0;
Chris@16 364 typedef typename result_of::child_c<Expr, 1>::type e1;
Chris@16 365 typedef typename result_of::child_c<Expr, 2>::type e2;
Chris@16 366 typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
Chris@16 367 typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
Chris@16 368 typedef typename Grammar::template impl<e2, State, Data>::result_type r2;
Chris@16 369 public:
Chris@16 370 BOOST_PROTO_DECLTYPE_(
Chris@16 371 proto::detail::make<r0>()
Chris@16 372 ? proto::detail::make<r1>()
Chris@16 373 : proto::detail::make<r2>()
Chris@16 374 , result_type
Chris@16 375 )
Chris@16 376 result_type operator ()(
Chris@16 377 typename impl::expr_param e
Chris@16 378 , typename impl::state_param s
Chris@16 379 , typename impl::data_param d
Chris@16 380 ) const
Chris@16 381 {
Chris@16 382 typename Grammar::template impl<e0, State, Data> t0;
Chris@16 383 typename Grammar::template impl<e1, State, Data> t1;
Chris@16 384 typename Grammar::template impl<e2, State, Data> t2;
Chris@16 385 return t0(proto::child_c<0>(e), s, d)
Chris@16 386 ? t1(proto::child_c<1>(e), s, d)
Chris@16 387 : t2(proto::child_c<2>(e), s, d);
Chris@16 388 }
Chris@16 389 };
Chris@16 390 };
Chris@16 391
Chris@16 392 template<typename Grammar>
Chris@16 393 struct default_case<Grammar, tag::if_else_>
Chris@16 394 : when<if_else_<Grammar, Grammar, Grammar>, default_if_else_<Grammar> >
Chris@16 395 {};
Chris@16 396
Chris@16 397 template<typename Grammar>
Chris@16 398 struct default_comma
Chris@16 399 : transform<default_comma<Grammar> >
Chris@16 400 {
Chris@16 401 template<typename Expr, typename State, typename Data>
Chris@16 402 struct impl
Chris@16 403 : transform_impl<Expr, State, Data>
Chris@16 404 {
Chris@16 405 private:
Chris@16 406 typedef typename result_of::child_c<Expr, 0>::type e0;
Chris@16 407 typedef typename result_of::child_c<Expr, 1>::type e1;
Chris@16 408 typedef typename Grammar::template impl<e0, State, Data>::result_type r0;
Chris@16 409 typedef typename Grammar::template impl<e1, State, Data>::result_type r1;
Chris@16 410 public:
Chris@16 411 typedef typename proto::detail::comma_result<r0, r1>::type result_type;
Chris@16 412 result_type operator ()(
Chris@16 413 typename impl::expr_param e
Chris@16 414 , typename impl::state_param s
Chris@16 415 , typename impl::data_param d
Chris@16 416 ) const
Chris@16 417 {
Chris@16 418 typename Grammar::template impl<e0, State, Data> t0;
Chris@16 419 typename Grammar::template impl<e1, State, Data> t1;
Chris@16 420 return t0(proto::child_c<0>(e), s, d)
Chris@16 421 , t1(proto::child_c<1>(e), s, d);
Chris@16 422 }
Chris@16 423 };
Chris@16 424 };
Chris@16 425
Chris@16 426 template<typename Grammar>
Chris@16 427 struct default_case<Grammar, tag::comma>
Chris@16 428 : when<comma<Grammar, Grammar>, default_comma<Grammar> >
Chris@16 429 {};
Chris@16 430
Chris@16 431 template<typename Grammar, typename Expr, typename State, typename Data, long Arity>
Chris@16 432 struct default_function_impl;
Chris@16 433
Chris@16 434 template<typename Grammar>
Chris@16 435 struct default_function
Chris@16 436 : transform<default_function<Grammar> >
Chris@16 437 {
Chris@16 438 template<typename Expr, typename State, typename Data>
Chris@16 439 struct impl
Chris@16 440 : default_function_impl<
Chris@16 441 Grammar
Chris@16 442 , Expr
Chris@16 443 , State
Chris@16 444 , Data
Chris@16 445 , transform_impl<Expr, State, Data>::expr::proto_arity_c
Chris@16 446 >
Chris@16 447 {};
Chris@16 448 };
Chris@16 449
Chris@16 450 template<typename Grammar>
Chris@16 451 struct default_case<Grammar, tag::function>
Chris@16 452 : when<function<Grammar, vararg<Grammar> >, default_function<Grammar> >
Chris@16 453 {};
Chris@16 454
Chris@16 455 #define BOOST_PROTO_DEFAULT_EVAL_TYPE(Z, N, DATA) \
Chris@16 456 typedef \
Chris@16 457 typename result_of::child_c<DATA, N>::type \
Chris@16 458 BOOST_PP_CAT(e, N); \
Chris@16 459 \
Chris@16 460 typedef \
Chris@16 461 typename Grammar::template impl<BOOST_PP_CAT(e, N), State, Data>::result_type \
Chris@16 462 BOOST_PP_CAT(r, N); \
Chris@16 463 /**/
Chris@16 464
Chris@16 465 #define BOOST_PROTO_DEFAULT_EVAL(Z, N, DATA) \
Chris@16 466 typename Grammar::template impl<BOOST_PP_CAT(e, N), State, Data>()( \
Chris@16 467 proto::child_c<N>(DATA), s, d \
Chris@16 468 ) \
Chris@16 469 /**/
Chris@16 470
Chris@16 471 template<typename Grammar, typename Expr, typename State, typename Data>
Chris@16 472 struct default_function_impl<Grammar, Expr, State, Data, 1>
Chris@16 473 : transform_impl<Expr, State, Data>
Chris@16 474 {
Chris@16 475 BOOST_PROTO_DEFAULT_EVAL_TYPE(~, 0, Expr)
Chris@16 476
Chris@16 477 typedef
Chris@16 478 typename proto::detail::result_of_fixup<r0>::type
Chris@16 479 function_type;
Chris@16 480
Chris@16 481 typedef
Chris@16 482 typename BOOST_PROTO_RESULT_OF<function_type()>::type
Chris@16 483 result_type;
Chris@16 484
Chris@16 485 result_type operator ()(
Chris@16 486 typename default_function_impl::expr_param e
Chris@16 487 , typename default_function_impl::state_param s
Chris@16 488 , typename default_function_impl::data_param d
Chris@16 489 ) const
Chris@16 490 {
Chris@16 491 return BOOST_PROTO_DEFAULT_EVAL(~, 0, e)();
Chris@16 492 }
Chris@16 493 };
Chris@16 494
Chris@16 495 template<typename Grammar, typename Expr, typename State, typename Data>
Chris@16 496 struct default_function_impl<Grammar, Expr, State, Data, 2>
Chris@16 497 : transform_impl<Expr, State, Data>
Chris@16 498 {
Chris@16 499 BOOST_PROTO_DEFAULT_EVAL_TYPE(~, 0, Expr)
Chris@16 500 BOOST_PROTO_DEFAULT_EVAL_TYPE(~, 1, Expr)
Chris@16 501
Chris@16 502 typedef
Chris@16 503 typename proto::detail::result_of_fixup<r0>::type
Chris@16 504 function_type;
Chris@16 505
Chris@16 506 typedef
Chris@16 507 typename detail::result_of_<function_type(r1)>::type
Chris@16 508 result_type;
Chris@16 509
Chris@16 510 result_type operator ()(
Chris@16 511 typename default_function_impl::expr_param e
Chris@16 512 , typename default_function_impl::state_param s
Chris@16 513 , typename default_function_impl::data_param d
Chris@16 514 ) const
Chris@16 515 {
Chris@16 516 return this->invoke(
Chris@16 517 e
Chris@16 518 , s
Chris@16 519 , d
Chris@16 520 , is_member_function_pointer<function_type>()
Chris@16 521 , is_member_object_pointer<function_type>()
Chris@16 522 );
Chris@16 523 }
Chris@16 524
Chris@16 525 private:
Chris@16 526 result_type invoke(
Chris@16 527 typename default_function_impl::expr_param e
Chris@16 528 , typename default_function_impl::state_param s
Chris@16 529 , typename default_function_impl::data_param d
Chris@16 530 , mpl::false_
Chris@16 531 , mpl::false_
Chris@16 532 ) const
Chris@16 533 {
Chris@16 534 return BOOST_PROTO_DEFAULT_EVAL(~, 0, e)(BOOST_PROTO_DEFAULT_EVAL(~, 1, e));
Chris@16 535 }
Chris@16 536
Chris@16 537 result_type invoke(
Chris@16 538 typename default_function_impl::expr_param e
Chris@16 539 , typename default_function_impl::state_param s
Chris@16 540 , typename default_function_impl::data_param d
Chris@16 541 , mpl::true_
Chris@16 542 , mpl::false_
Chris@16 543 ) const
Chris@16 544 {
Chris@16 545 BOOST_PROTO_USE_GET_POINTER();
Chris@16 546 typedef typename detail::class_member_traits<function_type>::class_type class_type;
Chris@16 547 return (
Chris@16 548 BOOST_PROTO_GET_POINTER(class_type, (BOOST_PROTO_DEFAULT_EVAL(~, 1, e))) ->*
Chris@16 549 BOOST_PROTO_DEFAULT_EVAL(~, 0, e)
Chris@16 550 )();
Chris@16 551 }
Chris@16 552
Chris@16 553 result_type invoke(
Chris@16 554 typename default_function_impl::expr_param e
Chris@16 555 , typename default_function_impl::state_param s
Chris@16 556 , typename default_function_impl::data_param d
Chris@16 557 , mpl::false_
Chris@16 558 , mpl::true_
Chris@16 559 ) const
Chris@16 560 {
Chris@16 561 BOOST_PROTO_USE_GET_POINTER();
Chris@16 562 typedef typename detail::class_member_traits<function_type>::class_type class_type;
Chris@16 563 return (
Chris@16 564 BOOST_PROTO_GET_POINTER(class_type, (BOOST_PROTO_DEFAULT_EVAL(~, 1, e))) ->*
Chris@16 565 BOOST_PROTO_DEFAULT_EVAL(~, 0, e)
Chris@16 566 );
Chris@16 567 }
Chris@16 568 };
Chris@16 569
Chris@16 570 #include <boost/proto/transform/detail/default_function_impl.hpp>
Chris@16 571
Chris@16 572 #undef BOOST_PROTO_DEFAULT_EVAL_TYPE
Chris@16 573 #undef BOOST_PROTO_DEFAULT_EVAL
Chris@16 574 }
Chris@16 575
Chris@16 576 template<typename Grammar /*= detail::_default*/>
Chris@16 577 struct _default
Chris@16 578 : switch_<detail::default_cases<Grammar> >
Chris@16 579 {};
Chris@16 580
Chris@16 581 template<typename Grammar>
Chris@16 582 struct is_callable<_default<Grammar> >
Chris@16 583 : mpl::true_
Chris@16 584 {};
Chris@16 585
Chris@16 586 namespace detail
Chris@16 587 {
Chris@16 588 // Loopy indirection that allows proto::_default<> to be
Chris@16 589 // used without specifying a Grammar argument.
Chris@16 590 struct _default
Chris@16 591 : proto::_default<>
Chris@16 592 {};
Chris@16 593 }
Chris@16 594
Chris@16 595 }}
Chris@16 596
Chris@16 597 #endif
Chris@16 598