call.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
  2. #include <boost/proto/transform/detail/preprocessed/call.hpp>
  3. #elif !defined(BOOST_PP_IS_ITERATING)
  4. #define BOOST_PROTO_NTH_RESULT_TYPE(Z, M, DATA) \
  5. typedef \
  6. typename when<_, BOOST_PP_CAT(A, M)>::template impl<Expr, State, Data> \
  7. BOOST_PP_CAT(a, M); \
  8. typedef typename BOOST_PP_CAT(a, M)::result_type BOOST_PP_CAT(b, M); \
  9. /**/
  10. #define BOOST_PROTO_NTH_RESULT(Z, M, DATA) \
  11. detail::as_lvalue(BOOST_PP_CAT(a, M)()(e, s, d)) \
  12. /**/
  13. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  14. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/call.hpp")
  15. #endif
  16. ///////////////////////////////////////////////////////////////////////////////
  17. /// \file call.hpp
  18. /// Contains definition of the call<> transform.
  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. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  24. #pragma wave option(preserve: 1)
  25. #endif
  26. #define BOOST_PP_ITERATION_PARAMS_1 \
  27. (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/transform/detail/call.hpp>))
  28. #include BOOST_PP_ITERATE()
  29. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  30. #pragma wave option(output: null)
  31. #endif
  32. #undef BOOST_PROTO_NTH_RESULT
  33. #undef BOOST_PROTO_NTH_RESULT_TYPE
  34. #else
  35. #define N BOOST_PP_ITERATION()
  36. #if N > 3
  37. /// \brief Call the PolymorphicFunctionObject \c Fun with the
  38. /// current expression, state and data, transformed according
  39. /// to \c A0 through \c AN.
  40. template<typename Fun BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  41. struct call<Fun(BOOST_PP_ENUM_PARAMS(N, A))> : transform<call<Fun(BOOST_PP_ENUM_PARAMS(N, A))> >
  42. {
  43. template<typename Expr, typename State, typename Data>
  44. struct impl : transform_impl<Expr, State, Data>
  45. {
  46. BOOST_PP_REPEAT(N, BOOST_PROTO_NTH_RESULT_TYPE, ~)
  47. typedef detail::poly_function_traits<Fun, Fun(BOOST_PP_ENUM_PARAMS(N, b))> function_traits;
  48. typedef typename function_traits::result_type result_type;
  49. /// Let \c ax be <tt>when\<_, Ax\>()(e, s, d)</tt>
  50. /// for each \c x in <tt>[0,N]</tt>.
  51. /// Return <tt>Fun()(a0, a1,... aN)</tt>.
  52. ///
  53. /// \param e The current expression
  54. /// \param s The current state
  55. /// \param d An arbitrary data
  56. BOOST_FORCEINLINE
  57. result_type operator ()(
  58. typename impl::expr_param e
  59. , typename impl::state_param s
  60. , typename impl::data_param d
  61. ) const
  62. {
  63. typedef typename function_traits::function_type function_type;
  64. return function_type()(BOOST_PP_ENUM(N, BOOST_PROTO_NTH_RESULT, ~));
  65. }
  66. };
  67. };
  68. #endif
  69. #if N > 0
  70. /// \brief Call the PolymorphicFunctionObject \c Fun with the
  71. /// current expression, state and data, transformed according
  72. /// to \c A0 through \c AN.
  73. template<typename Fun BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  74. struct call<Fun(BOOST_PP_ENUM_PARAMS(N, A)...)> : transform<call<Fun(BOOST_PP_ENUM_PARAMS(N, A)...)> >
  75. {
  76. template<typename Expr, typename State, typename Data>
  77. struct impl
  78. : call<
  79. typename detail::expand_pattern<
  80. proto::arity_of<Expr>::value // BUGBUG this isn't right. Could be pack(_child), should use arity of child!
  81. , BOOST_PP_CAT(A, BOOST_PP_DEC(N))
  82. , detail::BOOST_PP_CAT(expand_pattern_rest_, BOOST_PP_DEC(N))<
  83. Fun
  84. BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_DEC(N), A)
  85. >
  86. >::type
  87. >::template impl<Expr, State, Data>
  88. {};
  89. };
  90. #endif
  91. #undef N
  92. #endif