seq.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. // (C) Copyright Edward Diener 2011-2015
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #if !defined(BOOST_VMD_DETAIL_SEQ_HPP)
  6. #define BOOST_VMD_DETAIL_SEQ_HPP
  7. #include <boost/preprocessor/comparison/equal.hpp>
  8. #include <boost/preprocessor/control/iif.hpp>
  9. #include <boost/preprocessor/control/while.hpp>
  10. #include <boost/preprocessor/facilities/empty.hpp>
  11. #include <boost/preprocessor/seq/push_back.hpp>
  12. #include <boost/preprocessor/tuple/elem.hpp>
  13. #include <boost/preprocessor/tuple/push_back.hpp>
  14. #include <boost/preprocessor/tuple/size.hpp>
  15. #include <boost/preprocessor/variadic/elem.hpp>
  16. #include <boost/vmd/is_empty.hpp>
  17. #include <boost/vmd/detail/empty_result.hpp>
  18. #include <boost/vmd/detail/mods.hpp>
  19. #include <boost/vmd/detail/not_empty.hpp>
  20. #include <boost/vmd/detail/parens.hpp>
  21. #define BOOST_VMD_DETAIL_SEQ_STATE_INIT(seq) \
  22. BOOST_PP_TUPLE_PUSH_BACK \
  23. ( \
  24. BOOST_PP_TUPLE_PUSH_BACK \
  25. ( \
  26. BOOST_VMD_DETAIL_PARENS(seq,BOOST_VMD_RETURN_AFTER), \
  27. BOOST_PP_EMPTY() \
  28. ), \
  29. BOOST_PP_EMPTY() \
  30. ) \
  31. /**/
  32. #define BOOST_VMD_DETAIL_SEQ_STATE_INIT_D(d,seq) \
  33. BOOST_PP_TUPLE_PUSH_BACK \
  34. ( \
  35. BOOST_PP_TUPLE_PUSH_BACK \
  36. ( \
  37. BOOST_VMD_DETAIL_PARENS_D(d,seq,BOOST_VMD_RETURN_AFTER), \
  38. BOOST_PP_EMPTY() \
  39. ), \
  40. BOOST_PP_EMPTY() \
  41. ) \
  42. /**/
  43. #define BOOST_VMD_DETAIL_SEQ_STATE_PRED(d,state) \
  44. BOOST_VMD_DETAIL_NOT_EMPTY \
  45. ( \
  46. BOOST_PP_TUPLE_ELEM(0,state) \
  47. ) \
  48. /**/
  49. #define BOOST_VMD_DETAIL_SEQ_STATE_OP_SET_FAILURE(d,state) \
  50. ( \
  51. BOOST_PP_EMPTY(), \
  52. BOOST_PP_EMPTY(), \
  53. BOOST_PP_TUPLE_ELEM(2,state), \
  54. BOOST_PP_TUPLE_ELEM(3,state) \
  55. ) \
  56. /**/
  57. #define BOOST_VMD_DETAIL_SEQ_STATE_OP_MAKE_SEQ(d,state) \
  58. BOOST_PP_TUPLE_ELEM(0,state) \
  59. /**/
  60. #define BOOST_VMD_DETAIL_SEQ_STATE_OP_UPGRADE_SEQ(d,state) \
  61. BOOST_PP_SEQ_PUSH_BACK \
  62. ( \
  63. BOOST_PP_TUPLE_ELEM(2,state), \
  64. BOOST_PP_TUPLE_ELEM \
  65. ( \
  66. 0, \
  67. BOOST_PP_TUPLE_ELEM(0,state) \
  68. ) \
  69. ) \
  70. /**/
  71. #define BOOST_VMD_DETAIL_SEQ_STATE_OP_SET_SUCCESS(d,state) \
  72. ( \
  73. BOOST_PP_EMPTY(), \
  74. BOOST_PP_EMPTY(), \
  75. BOOST_PP_IIF \
  76. ( \
  77. BOOST_VMD_IS_EMPTY \
  78. ( \
  79. BOOST_PP_TUPLE_ELEM(2,state) \
  80. ), \
  81. BOOST_VMD_DETAIL_SEQ_STATE_OP_MAKE_SEQ, \
  82. BOOST_VMD_DETAIL_SEQ_STATE_OP_UPGRADE_SEQ \
  83. ) \
  84. (d,state), \
  85. BOOST_PP_EMPTY() \
  86. ) \
  87. /**/
  88. #define BOOST_VMD_DETAIL_SEQ_STATE_OP_SET_CONTINUE(d,state) \
  89. BOOST_PP_TUPLE_PUSH_BACK \
  90. ( \
  91. BOOST_PP_TUPLE_PUSH_BACK \
  92. ( \
  93. BOOST_VMD_DETAIL_PARENS_D(d,BOOST_PP_TUPLE_ELEM(1,state),BOOST_VMD_RETURN_AFTER), \
  94. BOOST_PP_IIF \
  95. ( \
  96. BOOST_VMD_IS_EMPTY \
  97. ( \
  98. BOOST_PP_TUPLE_ELEM(2,state) \
  99. ), \
  100. BOOST_VMD_DETAIL_SEQ_STATE_OP_MAKE_SEQ, \
  101. BOOST_VMD_DETAIL_SEQ_STATE_OP_UPGRADE_SEQ \
  102. ) \
  103. (d,state) \
  104. ), \
  105. BOOST_PP_TUPLE_ELEM(1,state) \
  106. ) \
  107. /**/
  108. #define BOOST_VMD_DETAIL_SEQ_STATE_OP_CHECK_REST(d,state) \
  109. BOOST_PP_IIF \
  110. ( \
  111. BOOST_VMD_IS_EMPTY \
  112. ( \
  113. BOOST_PP_TUPLE_ELEM(1,state) \
  114. ), \
  115. BOOST_VMD_DETAIL_SEQ_STATE_OP_SET_SUCCESS, \
  116. BOOST_VMD_DETAIL_SEQ_STATE_OP_SET_CONTINUE \
  117. ) \
  118. (d,state) \
  119. /**/
  120. #define BOOST_VMD_DETAIL_SEQ_STATE_OP(d,state) \
  121. BOOST_PP_IIF \
  122. ( \
  123. BOOST_PP_EQUAL_D \
  124. ( \
  125. d, \
  126. 1, \
  127. BOOST_PP_TUPLE_SIZE \
  128. ( \
  129. BOOST_PP_TUPLE_ELEM(0,state) \
  130. ) \
  131. ), \
  132. BOOST_VMD_DETAIL_SEQ_STATE_OP_CHECK_REST, \
  133. BOOST_VMD_DETAIL_SEQ_STATE_OP_SET_FAILURE \
  134. ) \
  135. (d,state) \
  136. /**/
  137. #define BOOST_VMD_DETAIL_SEQ_STATE_RESULT(state) \
  138. ( \
  139. BOOST_PP_TUPLE_ELEM(2,state), \
  140. BOOST_PP_TUPLE_ELEM(3,state) \
  141. ) \
  142. /**/
  143. #define BOOST_VMD_DETAIL_SEQ_PROCESS(seq) \
  144. BOOST_VMD_DETAIL_SEQ_STATE_RESULT \
  145. ( \
  146. BOOST_PP_WHILE \
  147. ( \
  148. BOOST_VMD_DETAIL_SEQ_STATE_PRED, \
  149. BOOST_VMD_DETAIL_SEQ_STATE_OP, \
  150. BOOST_VMD_DETAIL_SEQ_STATE_INIT(seq) \
  151. ) \
  152. ) \
  153. /**/
  154. #define BOOST_VMD_DETAIL_SEQ_SPLIT(seq) \
  155. BOOST_PP_IIF \
  156. ( \
  157. BOOST_VMD_IS_EMPTY(seq), \
  158. BOOST_VMD_DETAIL_EMPTY_RESULT, \
  159. BOOST_VMD_DETAIL_SEQ_PROCESS \
  160. ) \
  161. (seq) \
  162. /**/
  163. #define BOOST_VMD_DETAIL_SEQ_BEGIN(seq) \
  164. BOOST_PP_TUPLE_ELEM(0,BOOST_VMD_DETAIL_SEQ_SPLIT(seq)) \
  165. /**/
  166. #define BOOST_VMD_DETAIL_SEQ_PROCESS_D(d,seq) \
  167. BOOST_VMD_DETAIL_SEQ_STATE_RESULT \
  168. ( \
  169. BOOST_PP_WHILE_ ## d \
  170. ( \
  171. BOOST_VMD_DETAIL_SEQ_STATE_PRED, \
  172. BOOST_VMD_DETAIL_SEQ_STATE_OP, \
  173. BOOST_VMD_DETAIL_SEQ_STATE_INIT_D(d,seq) \
  174. ) \
  175. ) \
  176. /**/
  177. #define BOOST_VMD_DETAIL_SEQ_SPLIT_D(d,seq) \
  178. BOOST_PP_IIF \
  179. ( \
  180. BOOST_VMD_IS_EMPTY(seq), \
  181. BOOST_VMD_DETAIL_EMPTY_RESULT, \
  182. BOOST_VMD_DETAIL_SEQ_PROCESS_D \
  183. ) \
  184. (d,seq) \
  185. /**/
  186. #define BOOST_VMD_DETAIL_SEQ_BEGIN_D(d,seq) \
  187. BOOST_PP_TUPLE_ELEM(0,BOOST_VMD_DETAIL_SEQ_SPLIT_D(d,seq)) \
  188. /**/
  189. #define BOOST_VMD_DETAIL_SEQ_D(d,...) \
  190. BOOST_PP_IIF \
  191. ( \
  192. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER \
  193. ( \
  194. BOOST_VMD_DETAIL_NEW_MODS_D(d,BOOST_VMD_ALLOW_AFTER,__VA_ARGS__) \
  195. ), \
  196. BOOST_VMD_DETAIL_SEQ_SPLIT_D, \
  197. BOOST_VMD_DETAIL_SEQ_BEGIN_D \
  198. ) \
  199. (d,BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__)) \
  200. /**/
  201. #define BOOST_VMD_DETAIL_SEQ(...) \
  202. BOOST_PP_IIF \
  203. ( \
  204. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER \
  205. ( \
  206. BOOST_VMD_DETAIL_NEW_MODS(BOOST_VMD_ALLOW_AFTER,__VA_ARGS__) \
  207. ), \
  208. BOOST_VMD_DETAIL_SEQ_SPLIT, \
  209. BOOST_VMD_DETAIL_SEQ_BEGIN \
  210. ) \
  211. (BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__)) \
  212. /**/
  213. #endif /* BOOST_VMD_DETAIL_SEQ_HPP */