Ticket #2297: template_arity.patch

File template_arity.patch, 2.0 KB (added by dave, 6 years ago)

The correct improved patch

  • template_arity.hpp

     
    6464namespace boost { namespace mpl { namespace aux { 
    6565 
    6666template< BOOST_MPL_AUX_NTTP_DECL(int, N) > struct arity_tag 
     67  : arity_tag<N-1> 
    6768{ 
    68     typedef char (&type)[N + 1]; 
     69    typedef char (&type)[N + 2]; 
    6970}; 
    7071 
    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 
     72template <> 
     73struct arity_tag<0> 
    7974{ 
    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; 
    8776}; 
    8877 
    89 #   undef AUX778076_MAX_ARITY_OP 
    90  
    9178arity_tag<0>::type arity_helper(...); 
    9279 
    9380#   define BOOST_PP_ITERATION_LIMITS (1, AUX778076_ARITY) 
    9481#   define BOOST_PP_FILENAME_1 <boost/mpl/aux_/template_arity.hpp> 
    9582#   include BOOST_PP_ITERATE() 
    9683 
    97 template< typename F, BOOST_MPL_AUX_NTTP_DECL(int, N) > 
    98 struct template_arity_impl 
    99 { 
    100     BOOST_STATIC_CONSTANT(int, value =  
    101           sizeof(arity_helper(type_wrapper<F>(),arity_tag<N>())) - 1 
    102         ); 
    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  
    10984template< typename F > 
    11085struct template_arity 
     86  : mpl::int_< 
     87        (sizeof(arity_helper(type_wrapper<F>(), arity_tag<AUX778076_ARITY>())) - 2) 
     88    > 
    11189{ 
    112     BOOST_STATIC_CONSTANT(int, value = ( 
    113           max_arity< BOOST_MPL_PP_REPEAT( 
    114               AUX778076_ARITY 
    115             , AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION 
    116             , F 
    117             ) >::value 
    118         )); 
    119          
    120     typedef mpl::int_<value> type; 
    12190}; 
    12291 
    12392#   undef AUX778076_TEMPLATE_ARITY_IMPL_INVOCATION