
Hi there, let's assume I have a structure which takes 5 ints as template parameters. template< int NumChannel , int FirstChannelBits = 0 , int SecondChannelBits = 0 , int ThirdChannelBits = 0 , int FourthChannelBits = 0 , int FifthChannelBits = 0 > struct pixel_type_generator { /* omitted*/ } The first parameter is different as it defines how many of the other parameters are actually used. How can I use boost::preprocessor to get this kind of code repetition: // one channel test pixel_pixel_test< pixel_type_generator< 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 2 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 3 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 4 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 5 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 6 >::type >(); // up to 64 // two channels test pixel_pixel_test< pixel_type_generator< 2, 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 1, 2 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 1, 3 >::type >(); // ... pixel_pixel_test< pixel_type_generator< 2, 1, 32 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 2, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 2, 2 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 2, 3 >::type >(); // ... // ... pixel_pixel_test< pixel_type_generator< 2, 32, 32 >::type >(); // last two parameters up to 32 - which means there are 32 x 32 calls // three channels test pixel_pixel_test< pixel_type_generator< 3, 1, 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 3, 1, 1, 2 >::type >(); // ... // last three parameters up to 21 - which means there are 21 x 21 x 21 calls // four channels test pixel_pixel_test< pixel_type_generator< 4, 1, 1, 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 4, 1, 1, 1, 2 >::type >(); // ... // last four parameters up to 16 - which means there are 16 x 16 x 16 x 16 calls // five channels test pixel_pixel_test< pixel_type_generator< 5, 1, 1, 1, 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 5, 1, 1, 1, 1, 2 >::type >(); // ... // last four parameters up to 12 - which means there are 12 x 12 x 12 x 12 x 12 calls As you might realize, I try to test every combination until the sum of all channels hits 64. Thanks, Christian

2009/12/6 Christian Henning
Hi there,
let's assume I have a structure which takes 5 ints as template parameters.
template< int NumChannel , int FirstChannelBits = 0 , int SecondChannelBits = 0 , int ThirdChannelBits = 0 , int FourthChannelBits = 0 , int FifthChannelBits = 0 > struct pixel_type_generator { /* omitted*/ }
The first parameter is different as it defines how many of the other parameters are actually used.
How can I use boost::preprocessor to get this kind of code repetition:
<cut> FWIW, this can be achieved with Boost.MPL instead of preprocessor. Roman Perepelitsa.

Hi Roman, thanks for your answer. How can do that with MPL? Any pointers?
Thanks,
Christian
On Mon, Dec 7, 2009 at 4:30 AM, Roman Perepelitsa
2009/12/6 Christian Henning
Hi there,
let's assume I have a structure which takes 5 ints as template parameters.
template< int NumChannel , int FirstChannelBits = 0 , int SecondChannelBits = 0 , int ThirdChannelBits = 0 , int FourthChannelBits = 0 , int FifthChannelBits = 0 > struct pixel_type_generator { /* omitted*/ }
The first parameter is different as it defines how many of the other parameters are actually used.
How can I use boost::preprocessor to get this kind of code repetition:
<cut> FWIW, this can be achieved with Boost.MPL instead of preprocessor. Roman Perepelitsa. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG Christian Henning wrote:
let's assume I have a structure which takes 5 ints as template parameters.
template< int NumChannel , int FirstChannelBits = 0 , int SecondChannelBits = 0 , int ThirdChannelBits = 0 , int FourthChannelBits = 0 , int FifthChannelBits = 0 > struct pixel_type_generator { /* omitted*/ }
The first parameter is different as it defines how many of the other parameters are actually used.
How can I use boost::preprocessor to get this kind of code repetition:
// one channel test pixel_pixel_test< pixel_type_generator< 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 2 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 3 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 4 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 5 >::type >(); pixel_pixel_test< pixel_type_generator< 1, 6 >::type >(); // up to 64
// two channels test pixel_pixel_test< pixel_type_generator< 2, 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 1, 2 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 1, 3 >::type >(); // ... pixel_pixel_test< pixel_type_generator< 2, 1, 32 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 2, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 2, 2 >::type >(); pixel_pixel_test< pixel_type_generator< 2, 2, 3 >::type >(); // ... // ... pixel_pixel_test< pixel_type_generator< 2, 32, 32 >::type >(); // last two parameters up to 32 - which means there are 32 x 32 calls
// three channels test pixel_pixel_test< pixel_type_generator< 3, 1, 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 3, 1, 1, 2 >::type >(); // ... // last three parameters up to 21 - which means there are 21 x 21 x 21 calls
// four channels test pixel_pixel_test< pixel_type_generator< 4, 1, 1, 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 4, 1, 1, 1, 2 >::type >(); // ... // last four parameters up to 16 - which means there are 16 x 16 x 16 x 16 calls
// five channels test pixel_pixel_test< pixel_type_generator< 5, 1, 1, 1, 1, 1 >::type >(); pixel_pixel_test< pixel_type_generator< 5, 1, 1, 1, 1, 2 >::type >(); // ... // last four parameters up to 12 - which means there are 12 x 12 x 12 x 12 x 12 calls
This is 248,832 calls. I wouldn't be surprised if this worked out to several million template instantiations. The largest tests that I have run have been less than 50,000 template instantiations. I think you're going to destroy the compiler if you try this. In Christ, Steven Watanabe

On Mon, Dec 7, 2009 at 10:13 PM, Steven Watanabe
AMDG
This is 248,832 calls. I wouldn't be surprised if this worked out to several million template instantiations. The largest tests that I have run have been less than 50,000 template instantiations. I think you're going to destroy the compiler if you try this.
Steven, but as far as I understand it will destroy the compiler eitherway. Does it really matter if he is going to use preprocessor to generate the code or MPL? Templates are instantiated in both cases... Best Regards, Ovanes

AMDG Ovanes Markarian wrote:
On Mon, Dec 7, 2009 at 10:13 PM, Steven Watanabe
wrote: This is 248,832 calls. I wouldn't be surprised if this worked out to several million template instantiations. The largest tests that I have run have been less than 50,000 template instantiations. I think you're going to destroy the compiler if you try this.
but as far as I understand it will destroy the compiler eitherway. Does it really matter if he is going to use preprocessor to generate the code or MPL? Templates are instantiated in both cases...
How is the Preprocessor vs. MPL relevant to what I said? The only way to make it work is to split the tests into many translation units. In Christ, Steven Watanabe

OK OK. I was thinking the same. ;-)
For now I would be more than thankful if someone could tell how I can
actually accomplish the code using boost::preprocessor or even
boost::mpl. This test wont be permanent. I'm trying to nail down
issues with gil. Though, I can run in stages.
Thanks,
Christian
On Mon, Dec 7, 2009 at 5:00 PM, Steven Watanabe
AMDG
Ovanes Markarian wrote:
On Mon, Dec 7, 2009 at 10:13 PM, Steven Watanabe
wrote: This is 248,832 calls. I wouldn't be surprised if this worked out to several million template instantiations. The largest tests that I have run have been less than 50,000 template instantiations. I think you're going to destroy the compiler if you try this.
but as far as I understand it will destroy the compiler eitherway. Does it really matter if he is going to use preprocessor to generate the code or MPL? Templates are instantiated in both cases...
How is the Preprocessor vs. MPL relevant to what I said? The only way to make it work is to split the tests into many translation units.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG Christian Henning wrote:
OK OK. I was thinking the same. ;-)
For now I would be more than thankful if someone could tell how I can actually accomplish the code using boost::preprocessor or even boost::mpl. This test wont be permanent. I'm trying to nail down issues with gil. Though, I can run in stages.
You might look at BOOST_PP_SEQ_FOR_EACH_PRODUCT. In Christ, Steven Watanabe

Hi there, thanks Steven for your good advise. I have been making some
progress but I'm stuck on one part. Here is some code that exhibits my
problem.
#include

AMDG Christian Henning wrote:
Hi there, thanks Steven for your good advise. I have been making some progress but I'm stuck on one part. Here is some code that exhibits my problem.
#include
template< int i, int j > void test() {}
int main() { #define S1 (1)(2)(3) #define S2 (1)(2)(3) #define FOR_EACH( r, data, elem ) BOOST_PP_CAT( elem \ , BOOST_PP_COMMA() )
#define FOR_EACH_PRODUCT(r, product) test< BOOST_PP_SEQ_FOR_EACH( FOR_EACH \ , BOOST_PP_EMPTY() \ , product \ ) >();
BOOST_PP_SEQ_FOR_EACH_PRODUCT( FOR_EACH_PRODUCT \ , (S1)(S2) \ )
return 0; }
Here is what the preprocessor produces:
test< 1, 1, >(); test< 1, 2, >(); test< 1, 3, >(); test< 2, 1, >(); [snip]
My problem is that I cannot figure out how to get rid of the last comma? Any ideas?
BOOST_PP_SEQ_ENUM? In Christ, Steven Watanabe

Wow, thanks Steven. This is exactly what I'm looking for. Although, I
find the name BOOST_PP_SEQ_ENUM a bit odd.
Everything works now. And yes, there are way too many template
instantiations. ;-)
Christian
On Sun, Dec 13, 2009 at 6:05 PM, Steven Watanabe
AMDG
Christian Henning wrote:
Hi there, thanks Steven for your good advise. I have been making some progress but I'm stuck on one part. Here is some code that exhibits my problem.
#include
template< int i, int j > void test() {}
int main() { #define S1 (1)(2)(3) #define S2 (1)(2)(3) #define FOR_EACH( r, data, elem ) BOOST_PP_CAT( elem \ , BOOST_PP_COMMA() )
#define FOR_EACH_PRODUCT(r, product) test< BOOST_PP_SEQ_FOR_EACH( FOR_EACH \ , BOOST_PP_EMPTY() \ , product \ ) >();
BOOST_PP_SEQ_FOR_EACH_PRODUCT( FOR_EACH_PRODUCT \ , (S1)(S2) \ )
return 0; }
Here is what the preprocessor produces:
test< 1, 1, >(); test< 1, 2, >(); test< 1, 3, >(); test< 2, 1, >(); [snip]
My problem is that I cannot figure out how to get rid of the last comma? Any ideas?
BOOST_PP_SEQ_ENUM?
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

They are not. Sorry. Gmail shows everything as one branch. That's why I
thought your email was an answer to Christian's question how to implement
the approach with MPL, but in fact (looking into the boost users list) you
answered in a separate branch. Sorry again.
On Mon, Dec 7, 2009 at 11:00 PM, Steven Watanabe
AMDG
How is the Preprocessor vs. MPL relevant to what I said? The only way to make it work is to split the tests into many translation units.
participants (4)
-
Christian Henning
-
Ovanes Markarian
-
Roman Perepelitsa
-
Steven Watanabe