Boost logo

Boost :

Subject: Re: [boost] [mpl] mpl::c_str fails for mpl::push_back
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-11-07 03:40:13


----- Original Message -----
From: "vicente.botet" <vicente.botet_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, November 07, 2010 8:38 AM
Subject: Re: [boost] [mpl] mpl::c_str fails for mpl::push_back

> Do you have a workaround I can use to preserve it?

I have tried to add a value_type trait

    template<typename Sequence>
    struct value_type {
        typedef typename Sequence::value_type type;
    };

changed the c_str to use the type trait

    template<typename Sequence>
    struct c_str
    {
        typedef typename mpl::end<Sequence>::type iend;
        typedef typename mpl::begin<Sequence>::type i0;
        #define M0(z, n, data) \
        typedef \
            typename mpl::aux_::next_unless<BOOST_PP_CAT(i, n), iend>::type \
        BOOST_PP_CAT(i, BOOST_PP_INC(n));
        BOOST_PP_REPEAT(BOOST_MPL_LIMIT_STRING_SIZE, M0, ~)
        #undef M0

        typedef c_str type;
        static typename value_type<Sequence>::type const value[BOOST_MPL_LIMIT_STRING_SIZE+1];
    };

and defined the following specializations:

namespace boost { namespace mpl {
template<typename T, T N>
struct value_type<integral_c<T,N> > {
    typedef T type;
};
template<typename T0,typename T1,typename T2,typename T3,typename T4,
    typename T5,typename T6,typename T7,typename T8,typename T9,
    typename T10,typename T11>
struct value_type<vector12<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> > {
   typedef typename value_type<T0>::type type;
};
}
}

Then we are able to use c_str on any sequence providing the specialization. Of course compile checking that the sequence size is not greater than BOOST_MPL_LIMIT_STRING_SIZE should be convenient.

If I'm not wrong this change should not break working user code.

Is there a possibility to add this trait to Boost.MPL and the corresponding specialization and move the c_str function to a standalone file ?

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk