unpack_expr_.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
  2. #include <boost/proto/detail/preprocessed/unpack_expr_.hpp>
  3. #elif !defined(BOOST_PP_IS_ITERATING)
  4. /// INTERNAL ONLY
  5. ///
  6. #define BOOST_PROTO_FUSION_NEXT_ITERATOR_TYPE(Z, N, DATA) \
  7. typedef typename fusion::result_of::next< \
  8. BOOST_PP_CAT(fusion_iterator, N)>::type \
  9. BOOST_PP_CAT(fusion_iterator, BOOST_PP_INC(N)); \
  10. /**/
  11. /// INTERNAL ONLY
  12. ///
  13. #define BOOST_PROTO_FUSION_ITERATORS_TYPE(N) \
  14. typedef \
  15. typename fusion::result_of::begin<Sequence const>::type \
  16. fusion_iterator0; \
  17. BOOST_PP_REPEAT(BOOST_PP_DEC(N), BOOST_PROTO_FUSION_NEXT_ITERATOR_TYPE, fusion_iterator) \
  18. /**/
  19. /// INTERNAL ONLY
  20. ///
  21. #define BOOST_PROTO_FUSION_AT_TYPE(Z, N, DATA) \
  22. typename add_const< \
  23. typename fusion::result_of::value_of< \
  24. BOOST_PP_CAT(fusion_iterator, N) \
  25. >::type \
  26. >::type \
  27. /**/
  28. /// INTERNAL ONLY
  29. ///
  30. #define BOOST_PROTO_FUSION_NEXT_ITERATOR(Z, N, DATA) \
  31. BOOST_PP_CAT(fusion_iterator, BOOST_PP_INC(N)) BOOST_PP_CAT(it, BOOST_PP_INC(N)) = \
  32. fusion::next(BOOST_PP_CAT(it, N)); \
  33. /**/
  34. /// INTERNAL ONLY
  35. ///
  36. #define BOOST_PROTO_FUSION_ITERATORS(N) \
  37. fusion_iterator0 it0 = fusion::begin(sequence); \
  38. BOOST_PP_REPEAT(BOOST_PP_DEC(N), BOOST_PROTO_FUSION_NEXT_ITERATOR, fusion_iterator) \
  39. /**/
  40. /// INTERNAL ONLY
  41. ///
  42. #define BOOST_PROTO_FUSION_AT(Z, N, DATA) \
  43. *BOOST_PP_CAT(it, N) \
  44. /**/
  45. /// INTERNAL ONLY
  46. ///
  47. #define BOOST_PROTO_FUSION_AS_CHILD_AT_TYPE(Z, N, DATA) \
  48. typename detail::protoify< \
  49. BOOST_PROTO_FUSION_AT_TYPE(Z, N, DATA) \
  50. , Domain \
  51. >::result_type \
  52. /**/
  53. /// INTERNAL ONLY
  54. ///
  55. #define BOOST_PROTO_FUSION_AS_CHILD_AT(Z, N, DATA) \
  56. detail::protoify< \
  57. BOOST_PROTO_FUSION_AT_TYPE(Z, N, DATA) \
  58. , Domain \
  59. >()(BOOST_PROTO_FUSION_AT(Z, N, DATA)) \
  60. /**/
  61. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  62. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/unpack_expr_.hpp")
  63. #endif
  64. ///////////////////////////////////////////////////////////////////////////////
  65. /// \file make_expr_.hpp
  66. /// Contains definition of make_expr_\<\> class template.
  67. //
  68. // Copyright 2008 Eric Niebler. Distributed under the Boost
  69. // Software License, Version 1.0. (See accompanying file
  70. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  71. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  72. #pragma wave option(preserve: 1)
  73. #endif
  74. template<typename Tag, typename Domain, typename Sequence, std::size_t Size>
  75. struct unpack_expr_
  76. {};
  77. template<typename Domain, typename Sequence>
  78. struct unpack_expr_<tag::terminal, Domain, Sequence, 1u>
  79. {
  80. typedef
  81. typename add_const<
  82. typename fusion::result_of::value_of<
  83. typename fusion::result_of::begin<Sequence>::type
  84. >::type
  85. >::type
  86. terminal_type;
  87. typedef
  88. typename proto::detail::protoify<
  89. terminal_type
  90. , Domain
  91. >::result_type
  92. type;
  93. BOOST_FORCEINLINE
  94. static type const call(Sequence const &sequence)
  95. {
  96. return proto::detail::protoify<terminal_type, Domain>()(fusion::at_c<0>(sequence));
  97. }
  98. };
  99. template<typename Sequence>
  100. struct unpack_expr_<tag::terminal, deduce_domain, Sequence, 1u>
  101. : unpack_expr_<tag::terminal, default_domain, Sequence, 1u>
  102. {};
  103. #define BOOST_PP_ITERATION_PARAMS_1 \
  104. (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/detail/unpack_expr_.hpp>))
  105. #include BOOST_PP_ITERATE()
  106. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  107. #pragma wave option(output: null)
  108. #endif
  109. #undef BOOST_PROTO_FUSION_AT
  110. #undef BOOST_PROTO_FUSION_AT_TYPE
  111. #undef BOOST_PROTO_FUSION_AS_CHILD_AT
  112. #undef BOOST_PROTO_FUSION_AS_CHILD_AT_TYPE
  113. #undef BOOST_PROTO_FUSION_NEXT_ITERATOR
  114. #undef BOOST_PROTO_FUSION_NEXT_ITERATOR_TYPE
  115. #undef BOOST_PROTO_FUSION_ITERATORS
  116. #undef BOOST_PROTO_FUSION_ITERATORS_TYPE
  117. #else // BOOST_PP_IS_ITERATING
  118. #define N BOOST_PP_ITERATION()
  119. #define M BOOST_PP_SUB(BOOST_PROTO_MAX_ARITY, N)
  120. template<typename Tag, typename Domain, typename Sequence>
  121. struct unpack_expr_<Tag, Domain, Sequence, N>
  122. {
  123. BOOST_PROTO_FUSION_ITERATORS_TYPE(N)
  124. typedef
  125. BOOST_PP_CAT(list, N)<
  126. BOOST_PP_ENUM(N, BOOST_PROTO_FUSION_AS_CHILD_AT_TYPE, ~)
  127. >
  128. proto_args;
  129. typedef typename base_expr<Domain, Tag, proto_args>::type expr_type;
  130. typedef typename Domain::proto_generator proto_generator;
  131. typedef typename proto_generator::template result<proto_generator(expr_type)>::type type;
  132. BOOST_FORCEINLINE
  133. static type const call(Sequence const &sequence)
  134. {
  135. BOOST_PROTO_FUSION_ITERATORS(N)
  136. expr_type const that = {
  137. BOOST_PP_ENUM(N, BOOST_PROTO_FUSION_AS_CHILD_AT, ~)
  138. };
  139. return proto_generator()(that);
  140. }
  141. };
  142. template<typename Tag, typename Sequence>
  143. struct unpack_expr_<Tag, deduce_domain, Sequence, N>
  144. {
  145. BOOST_PROTO_FUSION_ITERATORS_TYPE(N)
  146. typedef
  147. unpack_expr_<
  148. Tag
  149. , typename BOOST_PP_CAT(deduce_domain, N)<
  150. BOOST_PP_ENUM(N, BOOST_PROTO_FUSION_AT_TYPE, ~)
  151. >::type
  152. , Sequence
  153. , N
  154. >
  155. other;
  156. typedef typename other::type type;
  157. BOOST_FORCEINLINE
  158. static type const call(Sequence const &sequence)
  159. {
  160. return other::call(sequence);
  161. }
  162. };
  163. #undef N
  164. #undef M
  165. #endif