apply.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #if !defined(BOOST_PP_IS_ITERATING)
  2. ///// header body
  3. #ifndef BOOST_MPL_APPLY_HPP_INCLUDED
  4. #define BOOST_MPL_APPLY_HPP_INCLUDED
  5. // Copyright Aleksey Gurtovoy 2000-2004
  6. //
  7. // Distributed under the Boost Software License, Version 1.0.
  8. // (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // See http://www.boost.org/libs/mpl for documentation.
  12. // $Id$
  13. // $Date$
  14. // $Revision$
  15. #if !defined(BOOST_MPL_PREPROCESSING_MODE)
  16. # include <boost/mpl/apply_fwd.hpp>
  17. # include <boost/mpl/apply_wrap.hpp>
  18. # include <boost/mpl/placeholders.hpp>
  19. # include <boost/mpl/lambda.hpp>
  20. # include <boost/mpl/aux_/na.hpp>
  21. # include <boost/mpl/aux_/lambda_support.hpp>
  22. #endif
  23. #include <boost/mpl/aux_/config/use_preprocessed.hpp>
  24. #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
  25. && !defined(BOOST_MPL_PREPROCESSING_MODE)
  26. # define BOOST_MPL_PREPROCESSED_HEADER apply.hpp
  27. # include <boost/mpl/aux_/include_preprocessed.hpp>
  28. #else
  29. # include <boost/mpl/limits/arity.hpp>
  30. # include <boost/mpl/aux_/preprocessor/params.hpp>
  31. # include <boost/mpl/aux_/preprocessor/default_params.hpp>
  32. # include <boost/mpl/aux_/preprocessor/partial_spec_params.hpp>
  33. # include <boost/mpl/aux_/preprocessor/enum.hpp>
  34. # include <boost/mpl/aux_/config/lambda.hpp>
  35. # include <boost/mpl/aux_/config/dtp.hpp>
  36. # include <boost/mpl/aux_/nttp_decl.hpp>
  37. # include <boost/mpl/aux_/config/eti.hpp>
  38. # include <boost/mpl/aux_/config/msvc.hpp>
  39. # include <boost/mpl/aux_/config/workaround.hpp>
  40. # include <boost/preprocessor/comma_if.hpp>
  41. # include <boost/preprocessor/inc.hpp>
  42. # include <boost/preprocessor/iterate.hpp>
  43. # include <boost/preprocessor/cat.hpp>
  44. namespace boost { namespace mpl {
  45. // local macros, #undef-ined at the end of the header
  46. # define AUX778076_APPLY_PARAMS(param) \
  47. BOOST_MPL_PP_PARAMS( \
  48. BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
  49. , param \
  50. ) \
  51. /**/
  52. # define AUX778076_APPLY_DEF_PARAMS(param, value) \
  53. BOOST_MPL_PP_DEFAULT_PARAMS( \
  54. BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
  55. , param \
  56. , value \
  57. ) \
  58. /**/
  59. # define AUX778076_APPLY_N_PARAMS(n, param) \
  60. BOOST_MPL_PP_PARAMS(n, param) \
  61. /**/
  62. # define AUX778076_APPLY_N_COMMA_PARAMS(n, param) \
  63. BOOST_PP_COMMA_IF(n) \
  64. BOOST_MPL_PP_PARAMS(n, param) \
  65. /**/
  66. # define AUX778076_APPLY_N_PARTIAL_SPEC_PARAMS(n, param, def) \
  67. BOOST_PP_COMMA_IF(n) \
  68. BOOST_MPL_PP_PARTIAL_SPEC_PARAMS(n, param, def) \
  69. /**/
  70. # define AUX778076_APPLY_N_SPEC_PARAMS(n, param) \
  71. BOOST_MPL_PP_ENUM(BOOST_PP_INC(n), param) \
  72. /**/
  73. #define BOOST_PP_ITERATION_PARAMS_1 \
  74. (3,(0, BOOST_MPL_LIMIT_METAFUNCTION_ARITY, <boost/mpl/apply.hpp>))
  75. #include BOOST_PP_ITERATE()
  76. # if !defined(BOOST_MPL_CFG_NO_APPLY_TEMPLATE)
  77. // real C++ version is already taken care of
  78. # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  79. namespace aux {
  80. // apply_count_args
  81. #define AUX778076_COUNT_ARGS_PREFIX apply
  82. #define AUX778076_COUNT_ARGS_DEFAULT na
  83. #define AUX778076_COUNT_ARGS_ARITY BOOST_MPL_LIMIT_METAFUNCTION_ARITY
  84. #include <boost/mpl/aux_/count_args.hpp>
  85. }
  86. template<
  87. typename F, AUX778076_APPLY_DEF_PARAMS(typename T, na)
  88. >
  89. struct apply
  90. : aux::apply_chooser<
  91. aux::apply_count_args< AUX778076_APPLY_PARAMS(T) >::value
  92. >::template result_< F, AUX778076_APPLY_PARAMS(T) >::type
  93. {
  94. };
  95. # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  96. # endif // BOOST_MPL_CFG_NO_APPLY_TEMPLATE
  97. # undef AUX778076_APPLY_N_SPEC_PARAMS
  98. # undef AUX778076_APPLY_N_PARTIAL_SPEC_PARAMS
  99. # undef AUX778076_APPLY_N_COMMA_PARAMS
  100. # undef AUX778076_APPLY_N_PARAMS
  101. # undef AUX778076_APPLY_DEF_PARAMS
  102. # undef AUX778076_APPLY_PARAMS
  103. }}
  104. #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
  105. #endif // BOOST_MPL_APPLY_HPP_INCLUDED
  106. ///// iteration, depth == 1
  107. // For gcc 4.4 compatability, we must include the
  108. // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
  109. #else // BOOST_PP_IS_ITERATING
  110. #if BOOST_PP_ITERATION_DEPTH() == 1
  111. # define i_ BOOST_PP_FRAME_ITERATION(1)
  112. template<
  113. typename F AUX778076_APPLY_N_COMMA_PARAMS(i_, typename T)
  114. >
  115. struct BOOST_PP_CAT(apply,i_)
  116. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  117. : BOOST_PP_CAT(apply_wrap,i_)<
  118. typename lambda<F>::type
  119. AUX778076_APPLY_N_COMMA_PARAMS(i_, T)
  120. >
  121. {
  122. #else
  123. {
  124. typedef typename BOOST_PP_CAT(apply_wrap,i_)<
  125. typename lambda<F>::type
  126. AUX778076_APPLY_N_COMMA_PARAMS(i_, T)
  127. >::type type;
  128. #endif
  129. BOOST_MPL_AUX_LAMBDA_SUPPORT(
  130. BOOST_PP_INC(i_)
  131. , BOOST_PP_CAT(apply,i_)
  132. , (F AUX778076_APPLY_N_COMMA_PARAMS(i_,T))
  133. )
  134. };
  135. #if defined(BOOST_MPL_CFG_MSVC_ETI_BUG)
  136. /// workaround for ETI bug
  137. template<>
  138. struct BOOST_PP_CAT(apply,i_)<AUX778076_APPLY_N_SPEC_PARAMS(i_, int)>
  139. {
  140. typedef int type;
  141. };
  142. #endif
  143. # if !defined(BOOST_MPL_CFG_NO_APPLY_TEMPLATE)
  144. # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  145. #if i_ == BOOST_MPL_LIMIT_METAFUNCTION_ARITY
  146. /// primary template (not a specialization!)
  147. template<
  148. typename F AUX778076_APPLY_N_COMMA_PARAMS(i_, typename T)
  149. >
  150. struct apply
  151. : BOOST_PP_CAT(apply,i_)< F AUX778076_APPLY_N_COMMA_PARAMS(i_, T) >
  152. {
  153. };
  154. #else
  155. template<
  156. typename F AUX778076_APPLY_N_COMMA_PARAMS(i_, typename T)
  157. >
  158. struct apply< F AUX778076_APPLY_N_PARTIAL_SPEC_PARAMS(i_, T, na) >
  159. : BOOST_PP_CAT(apply,i_)< F AUX778076_APPLY_N_COMMA_PARAMS(i_, T) >
  160. {
  161. };
  162. #endif
  163. # else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  164. #if !defined(BOOST_MPL_CFG_NO_APPLY_TEMPLATE)
  165. namespace aux {
  166. template<>
  167. struct apply_chooser<i_>
  168. {
  169. template<
  170. typename F, AUX778076_APPLY_PARAMS(typename T)
  171. >
  172. struct result_
  173. {
  174. typedef BOOST_PP_CAT(apply,i_)<
  175. F AUX778076_APPLY_N_COMMA_PARAMS(i_, T)
  176. > type;
  177. };
  178. };
  179. } // namespace aux
  180. #endif
  181. # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  182. # endif // BOOST_MPL_CFG_NO_APPLY_TEMPLATE
  183. # undef i_
  184. #endif // BOOST_PP_ITERATION_DEPTH()
  185. #endif // BOOST_PP_IS_ITERATING