sequence_wrapper.hpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. // NO INCLUDE GUARDS, THE HEADER IS INTENDED FOR MULTIPLE INCLUSION
  2. #if !defined(BOOST_PP_IS_ITERATING)
  3. ///// header body
  4. // Copyright Aleksey Gurtovoy 2000-2008
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/mpl for documentation.
  11. // $Id$
  12. // $Date$
  13. // $Revision$
  14. # include <boost/mpl/aux_/config/ctps.hpp>
  15. # include <boost/mpl/aux_/config/static_constant.hpp>
  16. # include <boost/mpl/aux_/nttp_decl.hpp>
  17. # include <boost/preprocessor/arithmetic/sub.hpp>
  18. # include <boost/preprocessor/tuple/elem.hpp>
  19. # include <boost/preprocessor/enum_params_with_a_default.hpp>
  20. # include <boost/preprocessor/enum_params.hpp>
  21. # include <boost/preprocessor/enum.hpp>
  22. # include <boost/preprocessor/repeat.hpp>
  23. # include <boost/preprocessor/comma_if.hpp>
  24. # include <boost/preprocessor/iterate.hpp>
  25. #if defined(BOOST_MPL_PREPROCESSING_MODE)
  26. # undef LONG_MAX
  27. #endif
  28. namespace boost { namespace mpl {
  29. #if !defined(AUX778076_SEQUENCE_BASE_NAME)
  30. # define AUX778076_SEQUENCE_BASE_NAME AUX778076_SEQUENCE_NAME
  31. #endif
  32. #if !defined(AUX778076_SEQUENCE_INTEGRAL_WRAPPER)
  33. # define AUX778076_SEQUENCE_PARAM_NAME T
  34. # define AUX778076_SEQUENCE_TEMPLATE_PARAM typename T
  35. # define AUX778076_SEQUENCE_DEFAULT na
  36. # define AUX778076_SEQUENCE_NAME_N(n) \
  37. BOOST_PP_CAT(AUX778076_SEQUENCE_BASE_NAME,n) \
  38. /**/
  39. # define AUX778076_SEQUENCE_PARAMS() \
  40. BOOST_PP_ENUM_PARAMS( \
  41. AUX778076_SEQUENCE_LIMIT \
  42. , AUX778076_SEQUENCE_TEMPLATE_PARAM \
  43. ) \
  44. /**/
  45. # define AUX778076_SEQUENCE_ARGS() \
  46. BOOST_PP_ENUM_PARAMS( \
  47. AUX778076_SEQUENCE_LIMIT \
  48. , T \
  49. ) \
  50. /**/
  51. # define AUX778076_SEQUENCE_DEFAULT_PARAMS() \
  52. BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( \
  53. AUX778076_SEQUENCE_LIMIT \
  54. , AUX778076_SEQUENCE_TEMPLATE_PARAM \
  55. , AUX778076_SEQUENCE_DEFAULT \
  56. ) \
  57. /**/
  58. # define AUX778076_SEQUENCE_N_PARAMS(n) \
  59. BOOST_PP_ENUM_PARAMS(n, AUX778076_SEQUENCE_TEMPLATE_PARAM) \
  60. /**/
  61. # define AUX778076_SEQUENCE_N_ARGS(n) \
  62. BOOST_PP_ENUM_PARAMS(n, T) \
  63. /**/
  64. # define AUX778076_SEQUENCE_N_PARTIAL_SPEC_ARGS(n) \
  65. BOOST_PP_ENUM_PARAMS(n, T) \
  66. BOOST_PP_COMMA_IF(n) \
  67. BOOST_PP_ENUM( \
  68. BOOST_PP_SUB_D(1,AUX778076_SEQUENCE_LIMIT,n) \
  69. , BOOST_PP_TUPLE_ELEM_3_2 \
  70. , AUX778076_SEQUENCE_DEFAULT \
  71. ) \
  72. /**/
  73. #else // AUX778076_SEQUENCE_INTEGRAL_WRAPPER
  74. # define AUX778076_SEQUENCE_PARAM_NAME C
  75. # define AUX778076_SEQUENCE_TEMPLATE_PARAM BOOST_MPL_AUX_NTTP_DECL(long, C)
  76. # define AUX778076_SEQUENCE_DEFAULT LONG_MAX
  77. # define AUX778076_SEQUENCE_PARAMS() \
  78. typename T, BOOST_PP_ENUM_PARAMS( \
  79. AUX778076_SEQUENCE_LIMIT \
  80. , AUX778076_SEQUENCE_TEMPLATE_PARAM \
  81. ) \
  82. /**/
  83. # define AUX778076_SEQUENCE_ARGS() \
  84. T, BOOST_PP_ENUM_PARAMS( \
  85. AUX778076_SEQUENCE_LIMIT \
  86. , C \
  87. ) \
  88. /**/
  89. # define AUX778076_SEQUENCE_DEFAULT_PARAMS() \
  90. typename T, \
  91. BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( \
  92. AUX778076_SEQUENCE_LIMIT \
  93. , AUX778076_SEQUENCE_TEMPLATE_PARAM \
  94. , AUX778076_SEQUENCE_DEFAULT \
  95. ) \
  96. /**/
  97. # define AUX778076_SEQUENCE_N_PARAMS(n) \
  98. typename T BOOST_PP_COMMA_IF(n) \
  99. BOOST_PP_ENUM_PARAMS(n, AUX778076_SEQUENCE_TEMPLATE_PARAM) \
  100. /**/
  101. # if !defined(AUX778076_SEQUENCE_CONVERT_CN_TO)
  102. # define AUX778076_SEQUENCE_CONVERT_CN_TO(z,n,TARGET) BOOST_PP_CAT(C,n)
  103. # endif
  104. # define AUX778076_SEQUENCE_N_ARGS(n) \
  105. T BOOST_PP_COMMA_IF(n) \
  106. BOOST_PP_ENUM(n,AUX778076_SEQUENCE_CONVERT_CN_TO,T) \
  107. /**/
  108. # define AUX778076_SEQUENCE_N_PARTIAL_SPEC_ARGS(n) \
  109. T, BOOST_PP_ENUM_PARAMS(n, C) \
  110. BOOST_PP_COMMA_IF(n) \
  111. BOOST_PP_ENUM( \
  112. BOOST_PP_SUB_D(1,AUX778076_SEQUENCE_LIMIT,n) \
  113. , BOOST_PP_TUPLE_ELEM_3_2 \
  114. , AUX778076_SEQUENCE_DEFAULT \
  115. ) \
  116. /**/
  117. #endif // AUX778076_SEQUENCE_INTEGRAL_WRAPPER
  118. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  119. // forward declaration
  120. template<
  121. AUX778076_SEQUENCE_DEFAULT_PARAMS()
  122. >
  123. struct AUX778076_SEQUENCE_NAME;
  124. #else
  125. namespace aux {
  126. template< BOOST_MPL_AUX_NTTP_DECL(int, N) >
  127. struct BOOST_PP_CAT(AUX778076_SEQUENCE_NAME,_chooser);
  128. }
  129. #endif
  130. #define BOOST_PP_ITERATION_PARAMS_1 \
  131. (3,(0, AUX778076_SEQUENCE_LIMIT, <boost/mpl/aux_/sequence_wrapper.hpp>))
  132. #include BOOST_PP_ITERATE()
  133. // real C++ version is already taken care of
  134. #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  135. namespace aux {
  136. // ???_count_args
  137. #define AUX778076_COUNT_ARGS_PREFIX AUX778076_SEQUENCE_NAME
  138. #define AUX778076_COUNT_ARGS_DEFAULT AUX778076_SEQUENCE_DEFAULT
  139. #define AUX778076_COUNT_ARGS_PARAM_NAME AUX778076_SEQUENCE_PARAM_NAME
  140. #define AUX778076_COUNT_ARGS_TEMPLATE_PARAM AUX778076_SEQUENCE_TEMPLATE_PARAM
  141. #define AUX778076_COUNT_ARGS_ARITY AUX778076_SEQUENCE_LIMIT
  142. #define AUX778076_COUNT_ARGS_USE_STANDARD_PP_PRIMITIVES
  143. #include <boost/mpl/aux_/count_args.hpp>
  144. template<
  145. AUX778076_SEQUENCE_PARAMS()
  146. >
  147. struct BOOST_PP_CAT(AUX778076_SEQUENCE_NAME,_impl)
  148. {
  149. typedef aux::BOOST_PP_CAT(AUX778076_SEQUENCE_NAME,_count_args)<
  150. BOOST_PP_ENUM_PARAMS(AUX778076_SEQUENCE_LIMIT, AUX778076_SEQUENCE_PARAM_NAME)
  151. > arg_num_;
  152. typedef typename aux::BOOST_PP_CAT(AUX778076_SEQUENCE_NAME,_chooser)< arg_num_::value >
  153. ::template result_< AUX778076_SEQUENCE_ARGS() >::type type;
  154. };
  155. } // namespace aux
  156. template<
  157. AUX778076_SEQUENCE_DEFAULT_PARAMS()
  158. >
  159. struct AUX778076_SEQUENCE_NAME
  160. : aux::BOOST_PP_CAT(AUX778076_SEQUENCE_NAME,_impl)<
  161. AUX778076_SEQUENCE_ARGS()
  162. >::type
  163. {
  164. typedef typename aux::BOOST_PP_CAT(AUX778076_SEQUENCE_NAME,_impl)<
  165. AUX778076_SEQUENCE_ARGS()
  166. >::type type;
  167. };
  168. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  169. # undef AUX778076_SEQUENCE_N_PARTIAL_SPEC_ARGS
  170. # undef AUX778076_SEQUENCE_N_ARGS
  171. # undef AUX778076_SEQUENCE_CONVERT_CN_TO
  172. # undef AUX778076_SEQUENCE_N_PARAMS
  173. # undef AUX778076_SEQUENCE_DEFAULT_PARAMS
  174. # undef AUX778076_SEQUENCE_ARGS
  175. # undef AUX778076_SEQUENCE_PARAMS
  176. # undef AUX778076_SEQUENCE_NAME_N
  177. # undef AUX778076_SEQUENCE_DEFAULT
  178. # undef AUX778076_SEQUENCE_TEMPLATE_PARAM
  179. # undef AUX778076_SEQUENCE_PARAM_NAME
  180. # undef AUX778076_SEQUENCE_LIMIT
  181. # undef AUX778076_SEQUENCE_BASE_NAME
  182. # undef AUX778076_SEQUENCE_NAME
  183. # undef AUX778076_SEQUENCE_INTEGRAL_WRAPPER
  184. }}
  185. ///// iteration
  186. #else
  187. #define i_ BOOST_PP_FRAME_ITERATION(1)
  188. # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  189. #if i_ == AUX778076_SEQUENCE_LIMIT
  190. /// primary template (not a specialization!)
  191. template<
  192. AUX778076_SEQUENCE_N_PARAMS(i_)
  193. >
  194. struct AUX778076_SEQUENCE_NAME
  195. : AUX778076_SEQUENCE_NAME_N(i_)< AUX778076_SEQUENCE_N_ARGS(i_) >
  196. {
  197. typedef typename AUX778076_SEQUENCE_NAME_N(i_)< AUX778076_SEQUENCE_N_ARGS(i_) >::type type;
  198. };
  199. #else
  200. template<
  201. AUX778076_SEQUENCE_N_PARAMS(i_)
  202. >
  203. struct AUX778076_SEQUENCE_NAME< AUX778076_SEQUENCE_N_PARTIAL_SPEC_ARGS(i_) >
  204. : AUX778076_SEQUENCE_NAME_N(i_)< AUX778076_SEQUENCE_N_ARGS(i_) >
  205. {
  206. #if i_ > 0 || defined(AUX778076_SEQUENCE_INTEGRAL_WRAPPER)
  207. typedef typename AUX778076_SEQUENCE_NAME_N(i_)< AUX778076_SEQUENCE_N_ARGS(i_) >::type type;
  208. #else
  209. typedef AUX778076_SEQUENCE_NAME_N(i_)< AUX778076_SEQUENCE_N_ARGS(i_) >::type type;
  210. #endif
  211. };
  212. #endif // i_ == AUX778076_SEQUENCE_LIMIT
  213. # else
  214. namespace aux {
  215. template<>
  216. struct BOOST_PP_CAT(AUX778076_SEQUENCE_NAME,_chooser)<i_>
  217. {
  218. template<
  219. AUX778076_SEQUENCE_PARAMS()
  220. >
  221. struct result_
  222. {
  223. #if i_ > 0 || defined(AUX778076_SEQUENCE_INTEGRAL_WRAPPER)
  224. typedef typename AUX778076_SEQUENCE_NAME_N(i_)<
  225. AUX778076_SEQUENCE_N_ARGS(i_)
  226. >::type type;
  227. #else
  228. typedef AUX778076_SEQUENCE_NAME_N(i_)<
  229. AUX778076_SEQUENCE_N_ARGS(i_)
  230. >::type type;
  231. #endif
  232. };
  233. };
  234. } // namespace aux
  235. # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  236. #undef i_
  237. #endif // BOOST_PP_IS_ITERATING