Boost logo

Boost Users :

Subject: Re: [Boost-users] Using an mpl sepquence as a template parameter
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-11-14 16:35:40


[Sorry if this was sent twice, but it appears to me that I didn't actually
hit "Send" the first time...]

On Mon, Nov 14, 2011 at 12:26 PM, paul Fultz <pfultz2_at_[hidden]> wrote:

> Hi,
> I have class that takes an mpl sequence as its parameter like this:
> X<mpl::vector<A, B, C> >
> And I would like to be able to have the class be used without explicitly
> declaring the mpl sequence like this:
> X<A, B, C>
> I know this could be accomplished using variadic template parameters, but
> I am using an older compiler. I was wondering if there was a macro in boost
> to do this, such as:
> template<BOOST_MPL_VARIADIC_PARAM_PACK(T)>
> class X
> {
> typedef mpl::vector<BOOST_MPL_VARIADIC_PARAM_UNPACK(T)> type;
> };
> If a macro is not available, does anyone know how I could write a macro
> like this? Or what is the default type used for mpl sequences when a type
> is unspecified?
>

I think there are a number of ways to do this. One might be to take
advantage of boost::mpl::na, though it looks like technically an
implementation detail so its stability could be questionable (defined in
<boost/mpl/aux_/na_fwd.hpp>, I believe). For example:

template< class T0 = boost::mpl::na, class T1 = boost::mpl::na, class T2 =
boost::mpl::na, [and so on...] >
struct X
{
    typedef boost::mpl::vector< T0, T1, T2, [and so on...] > type;
};

You can use the Boost.Preprocessor library, e.g., BOOST_PP_ENUM_PARAMS and
BOOST_PP_ENUM_BINARY_PARAMS, to make this a lot less repetitious.

- Jeff



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net