reverse_fold_impl.hpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // Copyright Aleksey Gurtovoy 2000-2004
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // *Preprocessed* version of the main "reverse_fold_impl.hpp" header
  8. // -- DO NOT modify by hand!
  9. namespace boost { namespace mpl { namespace aux {
  10. /// forward declaration
  11. template<
  12. long N
  13. , typename First
  14. , typename Last
  15. , typename State
  16. , typename BackwardOp
  17. , typename ForwardOp
  18. >
  19. struct reverse_fold_impl;
  20. template< long N >
  21. struct reverse_fold_chunk;
  22. template<> struct reverse_fold_chunk<0>
  23. {
  24. template<
  25. typename First
  26. , typename Last
  27. , typename State
  28. , typename BackwardOp
  29. , typename ForwardOp
  30. >
  31. struct result_
  32. {
  33. typedef First iter0;
  34. typedef State fwd_state0;
  35. typedef fwd_state0 bkwd_state0;
  36. typedef bkwd_state0 state;
  37. typedef iter0 iterator;
  38. };
  39. };
  40. template<> struct reverse_fold_chunk<1>
  41. {
  42. template<
  43. typename First
  44. , typename Last
  45. , typename State
  46. , typename BackwardOp
  47. , typename ForwardOp
  48. >
  49. struct result_
  50. {
  51. typedef First iter0;
  52. typedef State fwd_state0;
  53. typedef typename apply2< ForwardOp, fwd_state0, typename deref<iter0>::type >::type fwd_state1;
  54. typedef typename mpl::next<iter0>::type iter1;
  55. typedef fwd_state1 bkwd_state1;
  56. typedef typename apply2< BackwardOp, bkwd_state1, typename deref<iter0>::type >::type bkwd_state0;
  57. typedef bkwd_state0 state;
  58. typedef iter1 iterator;
  59. };
  60. };
  61. template<> struct reverse_fold_chunk<2>
  62. {
  63. template<
  64. typename First
  65. , typename Last
  66. , typename State
  67. , typename BackwardOp
  68. , typename ForwardOp
  69. >
  70. struct result_
  71. {
  72. typedef First iter0;
  73. typedef State fwd_state0;
  74. typedef typename apply2< ForwardOp, fwd_state0, typename deref<iter0>::type >::type fwd_state1;
  75. typedef typename mpl::next<iter0>::type iter1;
  76. typedef typename apply2< ForwardOp, fwd_state1, typename deref<iter1>::type >::type fwd_state2;
  77. typedef typename mpl::next<iter1>::type iter2;
  78. typedef fwd_state2 bkwd_state2;
  79. typedef typename apply2< BackwardOp, bkwd_state2, typename deref<iter1>::type >::type bkwd_state1;
  80. typedef typename apply2< BackwardOp, bkwd_state1, typename deref<iter0>::type >::type bkwd_state0;
  81. typedef bkwd_state0 state;
  82. typedef iter2 iterator;
  83. };
  84. };
  85. template<> struct reverse_fold_chunk<3>
  86. {
  87. template<
  88. typename First
  89. , typename Last
  90. , typename State
  91. , typename BackwardOp
  92. , typename ForwardOp
  93. >
  94. struct result_
  95. {
  96. typedef First iter0;
  97. typedef State fwd_state0;
  98. typedef typename apply2< ForwardOp, fwd_state0, typename deref<iter0>::type >::type fwd_state1;
  99. typedef typename mpl::next<iter0>::type iter1;
  100. typedef typename apply2< ForwardOp, fwd_state1, typename deref<iter1>::type >::type fwd_state2;
  101. typedef typename mpl::next<iter1>::type iter2;
  102. typedef typename apply2< ForwardOp, fwd_state2, typename deref<iter2>::type >::type fwd_state3;
  103. typedef typename mpl::next<iter2>::type iter3;
  104. typedef fwd_state3 bkwd_state3;
  105. typedef typename apply2< BackwardOp, bkwd_state3, typename deref<iter2>::type >::type bkwd_state2;
  106. typedef typename apply2< BackwardOp, bkwd_state2, typename deref<iter1>::type >::type bkwd_state1;
  107. typedef typename apply2< BackwardOp, bkwd_state1, typename deref<iter0>::type >::type bkwd_state0;
  108. typedef bkwd_state0 state;
  109. typedef iter3 iterator;
  110. };
  111. };
  112. template<> struct reverse_fold_chunk<4>
  113. {
  114. template<
  115. typename First
  116. , typename Last
  117. , typename State
  118. , typename BackwardOp
  119. , typename ForwardOp
  120. >
  121. struct result_
  122. {
  123. typedef First iter0;
  124. typedef State fwd_state0;
  125. typedef typename apply2< ForwardOp, fwd_state0, typename deref<iter0>::type >::type fwd_state1;
  126. typedef typename mpl::next<iter0>::type iter1;
  127. typedef typename apply2< ForwardOp, fwd_state1, typename deref<iter1>::type >::type fwd_state2;
  128. typedef typename mpl::next<iter1>::type iter2;
  129. typedef typename apply2< ForwardOp, fwd_state2, typename deref<iter2>::type >::type fwd_state3;
  130. typedef typename mpl::next<iter2>::type iter3;
  131. typedef typename apply2< ForwardOp, fwd_state3, typename deref<iter3>::type >::type fwd_state4;
  132. typedef typename mpl::next<iter3>::type iter4;
  133. typedef fwd_state4 bkwd_state4;
  134. typedef typename apply2< BackwardOp, bkwd_state4, typename deref<iter3>::type >::type bkwd_state3;
  135. typedef typename apply2< BackwardOp, bkwd_state3, typename deref<iter2>::type >::type bkwd_state2;
  136. typedef typename apply2< BackwardOp, bkwd_state2, typename deref<iter1>::type >::type bkwd_state1;
  137. typedef typename apply2< BackwardOp, bkwd_state1, typename deref<iter0>::type >::type bkwd_state0;
  138. typedef bkwd_state0 state;
  139. typedef iter4 iterator;
  140. };
  141. };
  142. template< long N >
  143. struct reverse_fold_chunk
  144. {
  145. template<
  146. typename First
  147. , typename Last
  148. , typename State
  149. , typename BackwardOp
  150. , typename ForwardOp
  151. >
  152. struct result_
  153. {
  154. typedef First iter0;
  155. typedef State fwd_state0;
  156. typedef typename apply2< ForwardOp, fwd_state0, typename deref<iter0>::type >::type fwd_state1;
  157. typedef typename mpl::next<iter0>::type iter1;
  158. typedef typename apply2< ForwardOp, fwd_state1, typename deref<iter1>::type >::type fwd_state2;
  159. typedef typename mpl::next<iter1>::type iter2;
  160. typedef typename apply2< ForwardOp, fwd_state2, typename deref<iter2>::type >::type fwd_state3;
  161. typedef typename mpl::next<iter2>::type iter3;
  162. typedef typename apply2< ForwardOp, fwd_state3, typename deref<iter3>::type >::type fwd_state4;
  163. typedef typename mpl::next<iter3>::type iter4;
  164. typedef reverse_fold_impl<
  165. ( (N - 4) < 0 ? 0 : N - 4 )
  166. , iter4
  167. , Last
  168. , fwd_state4
  169. , BackwardOp
  170. , ForwardOp
  171. > nested_chunk;
  172. typedef typename nested_chunk::state bkwd_state4;
  173. typedef typename apply2< BackwardOp, bkwd_state4, typename deref<iter3>::type >::type bkwd_state3;
  174. typedef typename apply2< BackwardOp, bkwd_state3, typename deref<iter2>::type >::type bkwd_state2;
  175. typedef typename apply2< BackwardOp, bkwd_state2, typename deref<iter1>::type >::type bkwd_state1;
  176. typedef typename apply2< BackwardOp, bkwd_state1, typename deref<iter0>::type >::type bkwd_state0;
  177. typedef bkwd_state0 state;
  178. typedef typename nested_chunk::iterator iterator;
  179. };
  180. };
  181. template<
  182. typename First
  183. , typename Last
  184. , typename State
  185. , typename BackwardOp
  186. , typename ForwardOp
  187. >
  188. struct reverse_fold_step;
  189. template<
  190. typename Last
  191. , typename State
  192. >
  193. struct reverse_fold_null_step
  194. {
  195. typedef Last iterator;
  196. typedef State state;
  197. };
  198. template<>
  199. struct reverse_fold_chunk< -1 >
  200. {
  201. template<
  202. typename First
  203. , typename Last
  204. , typename State
  205. , typename BackwardOp
  206. , typename ForwardOp
  207. >
  208. struct result_
  209. {
  210. typedef typename if_<
  211. typename is_same< First,Last >::type
  212. , reverse_fold_null_step< Last,State >
  213. , reverse_fold_step< First,Last,State,BackwardOp,ForwardOp >
  214. >::type res_;
  215. typedef typename res_::state state;
  216. typedef typename res_::iterator iterator;
  217. };
  218. };
  219. template<
  220. typename First
  221. , typename Last
  222. , typename State
  223. , typename BackwardOp
  224. , typename ForwardOp
  225. >
  226. struct reverse_fold_step
  227. {
  228. typedef reverse_fold_chunk< -1 >::template result_<
  229. typename mpl::next<First>::type
  230. , Last
  231. , typename apply2<ForwardOp,State, typename deref<First>::type>::type
  232. , BackwardOp
  233. , ForwardOp
  234. > nested_step;
  235. typedef typename apply2<
  236. BackwardOp
  237. , typename nested_step::state
  238. , typename deref<First>::type
  239. >::type state;
  240. typedef typename nested_step::iterator iterator;
  241. };
  242. template<
  243. long N
  244. , typename First
  245. , typename Last
  246. , typename State
  247. , typename BackwardOp
  248. , typename ForwardOp
  249. >
  250. struct reverse_fold_impl
  251. : reverse_fold_chunk<N>
  252. ::template result_< First,Last,State,BackwardOp,ForwardOp >
  253. {
  254. };
  255. }}}