Boost logo

Boost Users :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2006-03-18 20:12:20


 

> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of
> John Christopher
> Sent: Saturday, March 18, 2006 8:26 AM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] MPL to get rid of cumbersome switch
>
> > Given its prepetitive nature you could use boost
> preprocessor library
> > to generate this switch...
>
> That's a good idea.
> I could define
> #define NUMBER_CASES 4
> and the switch would become something like that:
> switch(i)
> {
> #define CASES(z, n, text)
> \
> case n:
> \
> vec.push_back(new boost::mpl::at<TTypes,
> boost::mpl::int_<n> >::type); \
> break;
> BOOST_PP_REPEAT(NUMBER_CASES, CASES, ~);
> }
> this compiles and works fine, but, since the number of cases
> in the switch must equal the size of the vector of type, I'd
> rather write something like:
> #define NUMBER_CASES boost::mpl::size<TTypes>::value
>
> but this does not compile and I am getting the error

Yeah, that won't work because the preprocessor cannot evaluate
'boost::mpl::size<TTypes>::value'. If you're going to use the preprocessor for
this, you need to store the types in a preprocessor data structure, not an
mpl::vector. (Note, BTW, than an MPL vector can be trivial created from a
preprocessor data structure.)

Regards,
Paul Mensonides


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