make.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
  2. #include <boost/proto/transform/detail/preprocessed/make.hpp>
  3. #elif !defined(BOOST_PP_IS_ITERATING)
  4. #define BOOST_PROTO_MAKE_IF(Z, M, DATA) \
  5. make_if_<BOOST_PP_CAT(A, M), Expr, State, Data> \
  6. /**/
  7. #define BOOST_PROTO_MAKE_IF_TYPE(Z, M, DATA) \
  8. typename BOOST_PROTO_MAKE_IF(Z, M, DATA) ::type \
  9. /**/
  10. #define BOOST_PROTO_MAKE_IF_APPLIED(Z, M, DATA) \
  11. BOOST_PROTO_MAKE_IF(Z, M, DATA) ::applied || \
  12. /**/
  13. #define BOOST_PROTO_CONSTRUCT_ARG(Z, M, DATA) \
  14. detail::as_lvalue( \
  15. typename when<_, BOOST_PP_CAT(A, M)>::template impl<Expr, State, Data>()(e, s, d) \
  16. ) \
  17. /**/
  18. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  19. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/make.hpp")
  20. #endif
  21. ///////////////////////////////////////////////////////////////////////////////
  22. /// \file make.hpp
  23. /// Contains definition of the make<> transform.
  24. //
  25. // Copyright 2008 Eric Niebler. Distributed under the Boost
  26. // Software License, Version 1.0. (See accompanying file
  27. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  28. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  29. #pragma wave option(preserve: 1)
  30. #endif
  31. #define BOOST_PP_ITERATION_PARAMS_1 \
  32. (3, (0, BOOST_PROTO_MAX_ARITY, <boost/proto/transform/detail/make.hpp>))
  33. #include BOOST_PP_ITERATE()
  34. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  35. #pragma wave option(output: null)
  36. #endif
  37. #undef BOOST_PROTO_CONSTRUCT_ARG
  38. #undef BOOST_PROTO_MAKE_IF_APPLIED
  39. #undef BOOST_PROTO_MAKE_IF_TYPE
  40. #undef BOOST_PROTO_MAKE_IF
  41. #else
  42. #define N BOOST_PP_ITERATION()
  43. namespace detail
  44. {
  45. #if N > 0
  46. template<
  47. template<BOOST_PP_ENUM_PARAMS(N, typename BOOST_PP_INTERCEPT)> class R
  48. BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)
  49. , typename Expr, typename State, typename Data
  50. >
  51. struct make_<
  52. R<BOOST_PP_ENUM_PARAMS(N, A)>
  53. , Expr, State, Data
  54. BOOST_PROTO_TEMPLATE_ARITY_PARAM(N)
  55. >
  56. : nested_type_if<
  57. R<BOOST_PP_ENUM(N, BOOST_PROTO_MAKE_IF_TYPE, ~)>
  58. , (BOOST_PP_REPEAT(N, BOOST_PROTO_MAKE_IF_APPLIED, ~) false)
  59. >
  60. {};
  61. template<
  62. template<BOOST_PP_ENUM_PARAMS(N, typename BOOST_PP_INTERCEPT)> class R
  63. BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)
  64. , typename Expr, typename State, typename Data
  65. >
  66. struct make_<
  67. noinvoke<R<BOOST_PP_ENUM_PARAMS(N, A)> >
  68. , Expr, State, Data
  69. BOOST_PROTO_TEMPLATE_ARITY_PARAM(1)
  70. >
  71. {
  72. typedef R<BOOST_PP_ENUM(N, BOOST_PROTO_MAKE_IF_TYPE, ~)> type;
  73. static bool const applied = true;
  74. };
  75. #endif
  76. template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  77. struct is_applyable<R(BOOST_PP_ENUM_PARAMS(N, A))>
  78. : mpl::true_
  79. {};
  80. template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  81. struct is_applyable<R(*)(BOOST_PP_ENUM_PARAMS(N, A))>
  82. : mpl::true_
  83. {};
  84. template<typename T, typename A>
  85. struct construct_<proto::expr<T, A, N>, true>
  86. {
  87. typedef proto::expr<T, A, N> result_type;
  88. template<BOOST_PP_ENUM_PARAMS(BOOST_PP_MAX(N, 1), typename A)>
  89. BOOST_FORCEINLINE
  90. result_type operator ()(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_MAX(N, 1), A, &a)) const
  91. {
  92. return result_type::make(BOOST_PP_ENUM_PARAMS(BOOST_PP_MAX(N, 1), a));
  93. }
  94. };
  95. template<typename T, typename A>
  96. struct construct_<proto::basic_expr<T, A, N>, true>
  97. {
  98. typedef proto::basic_expr<T, A, N> result_type;
  99. template<BOOST_PP_ENUM_PARAMS(BOOST_PP_MAX(N, 1), typename A)>
  100. BOOST_FORCEINLINE
  101. result_type operator ()(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_MAX(N, 1), A, &a)) const
  102. {
  103. return result_type::make(BOOST_PP_ENUM_PARAMS(BOOST_PP_MAX(N, 1), a));
  104. }
  105. };
  106. template<typename Type BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  107. BOOST_FORCEINLINE
  108. Type construct(BOOST_PP_ENUM_BINARY_PARAMS(N, A, &a))
  109. {
  110. return construct_<Type>()(BOOST_PP_ENUM_PARAMS(N, a));
  111. }
  112. } // namespace detail
  113. /// \brief A PrimitiveTransform which computes a type by evaluating any
  114. /// nested transforms and then constructs an object of that type with the
  115. /// current expression, state and data, transformed according
  116. /// to \c A0 through \c AN.
  117. template<typename Object BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  118. struct make<Object(BOOST_PP_ENUM_PARAMS(N, A))>
  119. : transform<make<Object(BOOST_PP_ENUM_PARAMS(N, A))> >
  120. {
  121. template<typename Expr, typename State, typename Data>
  122. struct impl : transform_impl<Expr, State, Data>
  123. {
  124. /// \brief <tt>boost::result_of\<make\<Object\>(Expr, State, Data)\>::type</tt>
  125. typedef typename detail::make_if_<Object, Expr, State, Data>::type result_type;
  126. /// Let \c ax be <tt>when\<_, Ax\>()(e, s, d)</tt>
  127. /// for each \c x in <tt>[0,N]</tt>.
  128. /// Return <tt>result_type(a0, a1,... aN)</tt>.
  129. ///
  130. /// \param e The current expression
  131. /// \param s The current state
  132. /// \param d An arbitrary data
  133. BOOST_FORCEINLINE
  134. result_type operator ()(
  135. typename impl::expr_param e
  136. , typename impl::state_param s
  137. , typename impl::data_param d
  138. ) const
  139. {
  140. proto::detail::ignore_unused(e);
  141. proto::detail::ignore_unused(s);
  142. proto::detail::ignore_unused(d);
  143. return detail::construct<result_type>(BOOST_PP_ENUM(N, BOOST_PROTO_CONSTRUCT_ARG, DATA));
  144. }
  145. };
  146. };
  147. #if N > 0
  148. /// \brief A PrimitiveTransform which computes a type by evaluating any
  149. /// nested transforms and then constructs an object of that type with the
  150. /// current expression, state and data, transformed according
  151. /// to \c A0 through \c AN.
  152. template<typename Object BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)>
  153. struct make<Object(BOOST_PP_ENUM_PARAMS(N, A)...)>
  154. : transform<make<Object(BOOST_PP_ENUM_PARAMS(N, A)...)> >
  155. {
  156. template<typename Expr, typename State, typename Data>
  157. struct impl
  158. : make<
  159. typename detail::expand_pattern<
  160. proto::arity_of<Expr>::value
  161. , BOOST_PP_CAT(A, BOOST_PP_DEC(N))
  162. , detail::BOOST_PP_CAT(expand_pattern_rest_, BOOST_PP_DEC(N))<
  163. Object
  164. BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_DEC(N), A)
  165. >
  166. >::type
  167. >::template impl<Expr, State, Data>
  168. {};
  169. };
  170. #endif
  171. #undef N
  172. #endif