Ticket #2297: template_arity.patch
File template_arity.patch, 2.0 KB (added by , 14 years ago) |
---|
-
template_arity.hpp
64 64 namespace boost { namespace mpl { namespace aux { 65 65 66 66 template< BOOST_MPL_AUX_NTTP_DECL(int, N) > struct arity_tag 67 : arity_tag<N-1> 67 68 { 68 typedef char (&type)[N + 1];69 typedef char (&type)[N + 2]; 69 70 }; 70 71 71 # define AUX778076_MAX_ARITY_OP(unused, state, i_) \ 72 ( BOOST_PP_CAT(C,i_) > 0 ? BOOST_PP_CAT(C,i_) : state ) \ 73 /**/ 74 75 template< 76 BOOST_MPL_PP_PARAMS(AUX778076_ARITY, BOOST_MPL_AUX_NTTP_DECL(int, C)) 77 > 78 struct max_arity 72 template <> 73 struct arity_tag<0> 79 74 { 80 BOOST_STATIC_CONSTANT(int, value = 81 BOOST_PP_SEQ_FOLD_LEFT( 82 AUX778076_MAX_ARITY_OP 83 , -1 84 , BOOST_MPL_PP_RANGE(1, AUX778076_ARITY) 85 ) 86 ); 75 typedef char type; 87 76 }; 88 77 89 # undef AUX778076_MAX_ARITY_OP90 91 78 arity_tag<0>::type arity_helper(...); 92 79 93 80 # define BOOST_PP_ITERATION_LIMITS (1, AUX778076_ARITY) 94 81 # define BOOST_PP_FILENAME_1 <boost/mpl/aux_/template_arity.hpp> 95 82 # include BOOST_PP_ITERATE() 96 83 97 template< typename F, BOOST_MPL_AUX_NTTP_DECL(int, N) >98 struct template_arity_impl99 {100 BOOST_STATIC_CONSTANT(int, value =101 sizeof(arity_helper(type_wrapper<F>(),arity_tag<N>())) - 1102 );103 };104 105 # define AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION(unused, i_, F) \106 BOOST_PP_COMMA_IF(i_) template_arity_impl<F,BOOST_PP_INC(i_)>::value \107 /**/108 109 84 template< typename F > 110 85 struct template_arity 86 : mpl::int_< 87 (sizeof(arity_helper(type_wrapper<F>(), arity_tag<AUX778076_ARITY>())) - 2) 88 > 111 89 { 112 BOOST_STATIC_CONSTANT(int, value = (113 max_arity< BOOST_MPL_PP_REPEAT(114 AUX778076_ARITY115 , AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION116 , F117 ) >::value118 ));119 120 typedef mpl::int_<value> type;121 90 }; 122 91 123 92 # undef AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION