template_arity.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #if !defined(BOOST_PP_IS_ITERATING)
  2. ///// header body
  3. #ifndef BOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED
  4. #define BOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED
  5. // Copyright Aleksey Gurtovoy 2001-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. #include <boost/mpl/aux_/config/ttp.hpp>
  16. #include <boost/mpl/aux_/config/lambda.hpp>
  17. #if !defined(BOOST_MPL_PREPROCESSING_MODE)
  18. # include <boost/mpl/aux_/template_arity_fwd.hpp>
  19. # include <boost/mpl/int.hpp>
  20. # if !defined(BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT)
  21. # if defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
  22. # include <boost/mpl/aux_/type_wrapper.hpp>
  23. # endif
  24. # else
  25. # include <boost/mpl/aux_/has_rebind.hpp>
  26. # endif
  27. #endif
  28. #include <boost/mpl/aux_/config/static_constant.hpp>
  29. #include <boost/mpl/aux_/config/use_preprocessed.hpp>
  30. #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \
  31. && !defined(BOOST_MPL_PREPROCESSING_MODE)
  32. # define BOOST_MPL_PREPROCESSED_HEADER template_arity.hpp
  33. # include <boost/mpl/aux_/include_preprocessed.hpp>
  34. #else
  35. # if !defined(BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT)
  36. # if defined(BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING)
  37. # include <boost/mpl/limits/arity.hpp>
  38. # include <boost/mpl/aux_/preprocessor/range.hpp>
  39. # include <boost/mpl/aux_/preprocessor/repeat.hpp>
  40. # include <boost/mpl/aux_/preprocessor/params.hpp>
  41. # include <boost/mpl/aux_/nttp_decl.hpp>
  42. # include <boost/preprocessor/seq/fold_left.hpp>
  43. # include <boost/preprocessor/comma_if.hpp>
  44. # include <boost/preprocessor/iterate.hpp>
  45. # include <boost/preprocessor/inc.hpp>
  46. # include <boost/preprocessor/cat.hpp>
  47. # define AUX778076_ARITY BOOST_PP_INC(BOOST_MPL_LIMIT_METAFUNCTION_ARITY)
  48. namespace boost { namespace mpl { namespace aux {
  49. template< BOOST_MPL_AUX_NTTP_DECL(int, N) > struct arity_tag
  50. {
  51. typedef char (&type)[N + 1];
  52. };
  53. # define AUX778076_MAX_ARITY_OP(unused, state, i_) \
  54. ( BOOST_PP_CAT(C,i_) > 0 ? BOOST_PP_CAT(C,i_) : state ) \
  55. /**/
  56. template<
  57. BOOST_MPL_PP_PARAMS(AUX778076_ARITY, BOOST_MPL_AUX_NTTP_DECL(int, C))
  58. >
  59. struct max_arity
  60. {
  61. BOOST_STATIC_CONSTANT(int, value =
  62. BOOST_PP_SEQ_FOLD_LEFT(
  63. AUX778076_MAX_ARITY_OP
  64. , -1
  65. , BOOST_MPL_PP_RANGE(1, AUX778076_ARITY)
  66. )
  67. );
  68. };
  69. # undef AUX778076_MAX_ARITY_OP
  70. arity_tag<0>::type arity_helper(...);
  71. # define BOOST_PP_ITERATION_LIMITS (1, AUX778076_ARITY)
  72. # define BOOST_PP_FILENAME_1 <boost/mpl/aux_/template_arity.hpp>
  73. # include BOOST_PP_ITERATE()
  74. template< typename F, BOOST_MPL_AUX_NTTP_DECL(int, N) >
  75. struct template_arity_impl
  76. {
  77. BOOST_STATIC_CONSTANT(int, value =
  78. sizeof(::boost::mpl::aux::arity_helper(type_wrapper<F>(),arity_tag<N>())) - 1
  79. );
  80. };
  81. # define AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION(unused, i_, F) \
  82. BOOST_PP_COMMA_IF(i_) template_arity_impl<F,BOOST_PP_INC(i_)>::value \
  83. /**/
  84. template< typename F >
  85. struct template_arity
  86. {
  87. BOOST_STATIC_CONSTANT(int, value = (
  88. max_arity< BOOST_MPL_PP_REPEAT(
  89. AUX778076_ARITY
  90. , AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION
  91. , F
  92. ) >::value
  93. ));
  94. typedef mpl::int_<value> type;
  95. };
  96. # undef AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION
  97. # undef AUX778076_ARITY
  98. }}}
  99. # endif // BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING
  100. # else // BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT
  101. # include <boost/mpl/aux_/config/eti.hpp>
  102. namespace boost { namespace mpl { namespace aux {
  103. template< bool >
  104. struct template_arity_impl
  105. {
  106. template< typename F > struct result_
  107. : mpl::int_<-1>
  108. {
  109. };
  110. };
  111. template<>
  112. struct template_arity_impl<true>
  113. {
  114. template< typename F > struct result_
  115. : F::arity
  116. {
  117. };
  118. };
  119. template< typename F >
  120. struct template_arity
  121. : template_arity_impl< ::boost::mpl::aux::has_rebind<F>::value >
  122. ::template result_<F>
  123. {
  124. };
  125. #if defined(BOOST_MPL_CFG_MSVC_ETI_BUG)
  126. template<>
  127. struct template_arity<int>
  128. : mpl::int_<-1>
  129. {
  130. };
  131. #endif
  132. }}}
  133. # endif // BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT
  134. #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
  135. #endif // BOOST_MPL_AUX_TEMPLATE_ARITY_HPP_INCLUDED
  136. ///// iteration
  137. #else
  138. #define i_ BOOST_PP_FRAME_ITERATION(1)
  139. template<
  140. template< BOOST_MPL_PP_PARAMS(i_, typename P) > class F
  141. , BOOST_MPL_PP_PARAMS(i_, typename T)
  142. >
  143. typename arity_tag<i_>::type
  144. arity_helper(type_wrapper< F<BOOST_MPL_PP_PARAMS(i_, T)> >, arity_tag<i_>);
  145. #undef i_
  146. #endif // BOOST_PP_IS_ITERATING