when.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
  2. #include <boost/proto/transform/detail/preprocessed/when.hpp>
  3. #elif !defined(BOOST_PP_IS_ITERATING)
  4. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  5. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/when.hpp")
  6. #endif
  7. ///////////////////////////////////////////////////////////////////////////////
  8. /// \file when.hpp
  9. /// Definition of when transform.
  10. //
  11. // Copyright 2008 Eric Niebler. Distributed under the Boost
  12. // Software License, Version 1.0. (See accompanying file
  13. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  14. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  15. #pragma wave option(preserve: 1)
  16. #endif
  17. #define BOOST_PP_ITERATION_PARAMS_1 \
  18. (3, (0, BOOST_PROTO_MAX_ARITY, <boost/proto/transform/detail/when.hpp>))
  19. #include BOOST_PP_ITERATE()
  20. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  21. #pragma wave option(output: null)
  22. #endif
  23. #else
  24. #define N BOOST_PP_ITERATION()
  25. /// \brief A grammar element and a PrimitiveTransform that associates
  26. /// a transform with the grammar.
  27. ///
  28. /// Use <tt>when\<\></tt> to override a grammar's default transform
  29. /// with a custom transform. It is for used when composing larger
  30. /// transforms by associating smaller transforms with individual
  31. /// rules in your grammar, as in the following transform which
  32. /// counts the number of terminals in an expression.
  33. ///
  34. /// \code
  35. /// // Count the terminals in an expression tree.
  36. /// // Must be invoked with initial state == mpl::int_<0>().
  37. /// struct CountLeaves
  38. /// : or_<
  39. /// when<terminal<_>, mpl::next<_state>()>
  40. /// , otherwise<fold<_, _state, CountLeaves> >
  41. /// >
  42. /// {};
  43. /// \endcode
  44. ///
  45. /// The <tt>when\<G, R(A0,A1,...)\></tt> form accepts either a
  46. /// CallableTransform or an ObjectTransform as its second parameter.
  47. /// <tt>when\<\></tt> uses <tt>is_callable\<R\>::value</tt> to
  48. /// distinguish between the two, and uses <tt>call\<\></tt> to
  49. /// evaluate CallableTransforms and <tt>make\<\></tt> to evaluate
  50. /// ObjectTransforms.
  51. template<typename Grammar, typename R BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  52. struct when<Grammar, R(BOOST_PP_ENUM_PARAMS(N, A))>
  53. : detail::when_impl<Grammar, R, R(BOOST_PP_ENUM_PARAMS(N, A))>
  54. {};
  55. #if N > 0
  56. /// \brief A grammar element and a PrimitiveTransform that associates
  57. /// a transform with the grammar.
  58. ///
  59. /// Use <tt>when\<\></tt> to override a grammar's default transform
  60. /// with a custom transform. It is for used when composing larger
  61. /// transforms by associating smaller transforms with individual
  62. /// rules in your grammar, as in the following transform which
  63. /// counts the number of terminals in an expression.
  64. ///
  65. /// \code
  66. /// // Count the terminals in an expression tree.
  67. /// // Must be invoked with initial state == mpl::int_<0>().
  68. /// struct CountLeaves
  69. /// : or_<
  70. /// when<terminal<_>, mpl::next<_state>()>
  71. /// , otherwise<fold<_, _state, CountLeaves> >
  72. /// >
  73. /// {};
  74. /// \endcode
  75. ///
  76. /// The <tt>when\<G, R(A0,A1,...)\></tt> form accepts either a
  77. /// CallableTransform or an ObjectTransform as its second parameter.
  78. /// <tt>when\<\></tt> uses <tt>is_callable\<R\>::value</tt> to
  79. /// distinguish between the two, and uses <tt>call\<\></tt> to
  80. /// evaluate CallableTransforms and <tt>make\<\></tt> to evaluate
  81. /// ObjectTransforms.
  82. template<typename Grammar, typename R BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  83. struct when<Grammar, R(BOOST_PP_ENUM_PARAMS(N, A)...)>
  84. : detail::when_impl<Grammar, R, R(BOOST_PP_ENUM_PARAMS(N, A)...)>
  85. {};
  86. #endif
  87. #undef N
  88. #endif