
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of John Christopher Sent: Saturday, March 18, 2006 8:26 AM To: boost-users@lists.boost.org 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
::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