list.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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_LIST_HPP)
  6. #define BOOST_VMD_DETAIL_LIST_HPP
  7. #include <boost/preprocessor/control/iif.hpp>
  8. #include <boost/preprocessor/punctuation/is_begin_parens.hpp>
  9. #include <boost/preprocessor/tuple/elem.hpp>
  10. #include <boost/preprocessor/tuple/pop_back.hpp>
  11. #include <boost/preprocessor/variadic/elem.hpp>
  12. #include <boost/vmd/is_empty.hpp>
  13. #include <boost/vmd/detail/empty_result.hpp>
  14. #include <boost/vmd/detail/identifier.hpp>
  15. #include <boost/vmd/detail/is_list.hpp>
  16. #include <boost/vmd/detail/mods.hpp>
  17. #include <boost/vmd/detail/parens.hpp>
  18. #define BOOST_VMD_DETAIL_LIST_CHECK_FOR_LIST(tuple) \
  19. BOOST_PP_IIF \
  20. ( \
  21. BOOST_VMD_DETAIL_IS_LIST \
  22. ( \
  23. BOOST_PP_TUPLE_ELEM \
  24. ( \
  25. 0, \
  26. tuple \
  27. ) \
  28. ), \
  29. tuple, \
  30. (,) \
  31. ) \
  32. /**/
  33. #define BOOST_VMD_DETAIL_LIST_CHECK_FOR_LIST_D(d,tuple) \
  34. BOOST_PP_IIF \
  35. ( \
  36. BOOST_VMD_DETAIL_IS_LIST_D \
  37. ( \
  38. d, \
  39. BOOST_PP_TUPLE_ELEM \
  40. ( \
  41. 0, \
  42. tuple \
  43. ) \
  44. ), \
  45. tuple, \
  46. (,) \
  47. ) \
  48. /**/
  49. #define BOOST_VMD_DETAIL_LIST_CHECK_RETURN(tuple) \
  50. BOOST_PP_IIF \
  51. ( \
  52. BOOST_VMD_IS_EMPTY \
  53. ( \
  54. BOOST_PP_TUPLE_ELEM \
  55. ( \
  56. 0, \
  57. tuple \
  58. ) \
  59. ), \
  60. BOOST_VMD_DETAIL_EMPTY_RESULT, \
  61. BOOST_VMD_DETAIL_LIST_CHECK_FOR_LIST \
  62. ) \
  63. (tuple) \
  64. /**/
  65. #define BOOST_VMD_DETAIL_LIST_CHECK_RETURN_D(d,tuple) \
  66. BOOST_PP_IIF \
  67. ( \
  68. BOOST_VMD_IS_EMPTY \
  69. ( \
  70. BOOST_PP_TUPLE_ELEM \
  71. ( \
  72. 0, \
  73. tuple \
  74. ) \
  75. ), \
  76. BOOST_VMD_DETAIL_EMPTY_RESULT, \
  77. BOOST_VMD_DETAIL_LIST_CHECK_FOR_LIST_D \
  78. ) \
  79. (d,tuple) \
  80. /**/
  81. #define BOOST_VMD_DETAIL_LIST_EMPTY_LIST(list) \
  82. BOOST_VMD_DETAIL_IDENTIFIER(list,BOOST_PP_NIL,BOOST_VMD_RETURN_AFTER,BOOST_VMD_RETURN_INDEX) \
  83. /**/
  84. #define BOOST_VMD_DETAIL_LIST_EMPTY_LIST_D(d,list) \
  85. BOOST_VMD_DETAIL_IDENTIFIER_D(d,list,BOOST_PP_NIL,BOOST_VMD_RETURN_AFTER,BOOST_VMD_RETURN_INDEX) \
  86. /**/
  87. #define BOOST_VMD_DETAIL_LIST_TUPLE(param) \
  88. BOOST_VMD_DETAIL_LIST_CHECK_RETURN \
  89. ( \
  90. BOOST_VMD_DETAIL_PARENS(param,BOOST_VMD_RETURN_AFTER) \
  91. ) \
  92. /**/
  93. #define BOOST_VMD_DETAIL_LIST_TUPLE_D(d,param) \
  94. BOOST_VMD_DETAIL_LIST_CHECK_RETURN_D \
  95. ( \
  96. d, \
  97. BOOST_VMD_DETAIL_PARENS_D(d,param,BOOST_VMD_RETURN_AFTER) \
  98. ) \
  99. /**/
  100. #define BOOST_VMD_DETAIL_LIST_EMPTY_PROCESS(tuple) \
  101. BOOST_PP_IIF \
  102. ( \
  103. BOOST_VMD_IS_EMPTY \
  104. ( \
  105. BOOST_PP_TUPLE_ELEM(0,tuple) \
  106. ), \
  107. (,), \
  108. tuple \
  109. ) \
  110. /**/
  111. #define BOOST_VMD_DETAIL_LIST_EMPTY(list) \
  112. BOOST_VMD_DETAIL_LIST_EMPTY_PROCESS \
  113. ( \
  114. BOOST_VMD_DETAIL_LIST_EMPTY_LIST(list) \
  115. ) \
  116. /**/
  117. #define BOOST_VMD_DETAIL_LIST_EMPTY_D(d,list) \
  118. BOOST_VMD_DETAIL_LIST_EMPTY_PROCESS \
  119. ( \
  120. BOOST_VMD_DETAIL_LIST_EMPTY_LIST_D(d,list) \
  121. ) \
  122. /**/
  123. #define BOOST_VMD_DETAIL_LIST_PROCESS(list) \
  124. BOOST_PP_IIF \
  125. ( \
  126. BOOST_PP_IS_BEGIN_PARENS(list), \
  127. BOOST_VMD_DETAIL_LIST_TUPLE, \
  128. BOOST_VMD_DETAIL_LIST_EMPTY \
  129. ) \
  130. (list) \
  131. /**/
  132. #define BOOST_VMD_DETAIL_LIST_SPLIT(list) \
  133. BOOST_PP_IIF \
  134. ( \
  135. BOOST_VMD_IS_EMPTY(list), \
  136. BOOST_VMD_DETAIL_EMPTY_RESULT, \
  137. BOOST_VMD_DETAIL_LIST_PROCESS \
  138. ) \
  139. (list) \
  140. /**/
  141. #define BOOST_VMD_DETAIL_LIST_BEGIN(list) \
  142. BOOST_PP_TUPLE_ELEM(0,BOOST_VMD_DETAIL_LIST_SPLIT(list)) \
  143. /**/
  144. #define BOOST_VMD_DETAIL_LIST_PROCESS_D(d,list) \
  145. BOOST_PP_IIF \
  146. ( \
  147. BOOST_PP_IS_BEGIN_PARENS(list), \
  148. BOOST_VMD_DETAIL_LIST_TUPLE_D, \
  149. BOOST_VMD_DETAIL_LIST_EMPTY_D \
  150. ) \
  151. (d,list) \
  152. /**/
  153. #define BOOST_VMD_DETAIL_LIST_SPLIT_D(d,list) \
  154. BOOST_PP_IIF \
  155. ( \
  156. BOOST_VMD_IS_EMPTY(list), \
  157. BOOST_VMD_DETAIL_EMPTY_RESULT, \
  158. BOOST_VMD_DETAIL_LIST_PROCESS_D \
  159. ) \
  160. (d,list) \
  161. /**/
  162. #define BOOST_VMD_DETAIL_LIST_BEGIN_D(d,list) \
  163. BOOST_PP_TUPLE_ELEM(0,BOOST_VMD_DETAIL_LIST_SPLIT_D(d,list)) \
  164. /**/
  165. #define BOOST_VMD_DETAIL_LIST_D(d,...) \
  166. BOOST_PP_IIF \
  167. ( \
  168. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER \
  169. ( \
  170. BOOST_VMD_DETAIL_NEW_MODS_D(d,BOOST_VMD_ALLOW_AFTER,__VA_ARGS__) \
  171. ), \
  172. BOOST_VMD_DETAIL_LIST_SPLIT_D, \
  173. BOOST_VMD_DETAIL_LIST_BEGIN_D \
  174. ) \
  175. (d,BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__)) \
  176. /**/
  177. #define BOOST_VMD_DETAIL_LIST(...) \
  178. BOOST_PP_IIF \
  179. ( \
  180. BOOST_VMD_DETAIL_MODS_IS_RESULT_AFTER \
  181. ( \
  182. BOOST_VMD_DETAIL_NEW_MODS(BOOST_VMD_ALLOW_AFTER,__VA_ARGS__) \
  183. ), \
  184. BOOST_VMD_DETAIL_LIST_SPLIT, \
  185. BOOST_VMD_DETAIL_LIST_BEGIN \
  186. ) \
  187. (BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__)) \
  188. /**/
  189. #endif /* BOOST_VMD_DETAIL_LIST_HPP */