I am going to use our wonderful Preprocessor library to generate a
metafunction that basically looks like this:

    template<
          int C0, int C1, ..., int Cn
        >
    struct max_arity
    {
        static int const value = Cn > 0 ? Cn : ( Cn-1 > 0 ? Cn-1 : 
            ... ( C1 > 0 ? C1 : ( C0 > 0 ? C0 : -1 ) ) )
            ;
    };

So here's what I came up with:

    template<
          BOOST_PP_ENUM_PARAMS(BOOST_MPL_METAFUNCTION_MAX_ARITY, int C)
        >
    struct max_arity
    {
        BOOST_STATIC_CONSTANT(int, 
            value = BOOST_PP_LIST_FOLD_LEFT(
                      AUX_MAX_ARITY_OP
                    , -1
                    , (0, (1, (2, (3, (4, BOOST_PP_NIL)))))
                    )
            );
    };

I love everything about it except for the "(0, (1, (2, (3, (4,
BOOST_PP_NIL)))))" part. I would like the above to become something along
these lines:

            value = BOOST_PP_RANGE_FOLD_LEFT(
                      AUX_MAX_ARITY_OP
                    , -1
                    , BOOST_PP_RANGE(0, 4)
                    )

or, better yet,

            value = BOOST_PP_FOLD_LEFT(
                      AUX_MAX_ARITY_OP
                    , -1
                    , BOOST_PP_RANGE(0, 4)
                    )

where 'BOOST_PP_FOLD_LEFT' is a generic algorithm that can be used on all PP
sequences. 

How hard would it be to have something like this?

I suppose it's possible to generate the code I need using BOOST_PP_WHILE,
but IMO that solution wouldn't be as conceptually nice and intuitive as the
above.

Aleksey
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to