Boost logo

Boost Users :

Subject: Re: [Boost-users] [preprocessor]
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-12-07 16:13:11


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


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