callable_eval.hpp 4.0 KB

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