lazy.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
  2. #include <boost/proto/transform/detail/preprocessed/lazy.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/lazy.hpp")
  6. #endif
  7. ///////////////////////////////////////////////////////////////////////////////
  8. /// \file lazy.hpp
  9. /// Contains definition of the lazy<> 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/lazy.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 PrimitiveTransform that uses <tt>make\<\></tt> to build
  26. /// a CallableTransform, and then uses <tt>call\<\></tt> to apply it.
  27. ///
  28. /// <tt>lazy\<\></tt> is useful as a higher-order transform, when the
  29. /// transform to be applied depends on the current state of the
  30. /// transformation. The invocation of the <tt>make\<\></tt> transform
  31. /// evaluates any nested transforms, and the resulting type is treated
  32. /// as a CallableTransform, which is evaluated with <tt>call\<\></tt>.
  33. template<typename Object BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  34. struct lazy<Object(BOOST_PP_ENUM_PARAMS(N, A))>
  35. : transform<lazy<Object(BOOST_PP_ENUM_PARAMS(N, A))> >
  36. {
  37. template<typename Expr, typename State, typename Data>
  38. struct impl
  39. : call<
  40. typename make<Object>::template impl<Expr, State, Data>::result_type
  41. (BOOST_PP_ENUM_PARAMS(N, A))
  42. >::template impl<Expr, State, Data>
  43. {};
  44. };
  45. #if N > 0
  46. template<typename Object BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  47. struct lazy<Object(BOOST_PP_ENUM_PARAMS(N, A)...)>
  48. : transform<lazy<Object(BOOST_PP_ENUM_PARAMS(N, A)...)> >
  49. {
  50. template<typename Expr, typename State, typename Data>
  51. struct impl
  52. : lazy<
  53. typename detail::expand_pattern<
  54. proto::arity_of<Expr>::value
  55. , BOOST_PP_CAT(A, BOOST_PP_DEC(N))
  56. , detail::BOOST_PP_CAT(expand_pattern_rest_, BOOST_PP_DEC(N))<
  57. Object
  58. BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_DEC(N), A)
  59. >
  60. >::type
  61. >::template impl<Expr, State, Data>
  62. {};
  63. };
  64. #endif
  65. #undef N
  66. #endif