|
Boost Users : |
From: John Christopher (jcxxr_at_[hidden])
Date: 2006-03-18 11:25:59
> 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
C:/ventures/test/classes/main.cpp: In member function `void
Functor::operator()(const int&)':
C:/ventures/test/classes/main.cpp:47: error: `BOOST_PP_REPEAT_1_boost' has
not been declared
C:/ventures/test/classes/main.cpp:47: error: `size' undeclared (first use
this function)
C:/ventures/test/classes/main.cpp:47: error: (Each undeclared identifier is
reported only once for each function it appears in.)
C:/ventures/test/classes/main.cpp:47: error: expected primary-expression
before '>' token
C:/ventures/test/classes/main.cpp:47: error: `::value' has not been declared
C:/ventures/test/classes/main.cpp:47: error: `CASES' undeclared (first use
this function)
C:/ventures/test/classes/main.cpp:47: error: expected primary-expression
before ')' token
mingw32-make[1]: *** [release\main.o] Error 1
Any idea on how to make it work?
Many thanks
JCR
"Delfin Rojas" <drojas_at_[hidden]> wrote in message
news:005001c64a19$6ed5c8e0$3000a8c0_at_winxpme...
>> John Christopher wrote:
>>
>> Hello,
>> Still reading... Chapter 11 is still a few pages away...
>> Any way, I rewrote the program and I have something much simpler.
>> The vector of types has not changed:
>> typedef boost::mpl::vector<T0, T1, T2, T3> TTypes; but
>> the Functor has a new switch statement that is much easier to
>> maintain.
>> The nnumber of cases in the switch must be the number of
>> elements in the vector of types... Adding new cases is no big
>> deal anyway.
>> switch(i)
>> {
>> case 0:
>> vec.push_back(new boost::mpl::at<TTypes,
>> boost::mpl::int_<0> >::type);
>> break;
>> case 1:
>> vec.push_back(new boost::mpl::at<TTypes,
>> boost::mpl::int_<1> >::type);
>> break;
>> ....
>>
>
> Given its prepetitive nature you could use boost preprocessor library to
> generate this switch...
>
> -delfin
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