Boost logo

Boost Users :

Subject: [Boost-users] [preprocessor]
From: Christian Henning (chhenning_at_[hidden])
Date: 2009-12-06 12:56:06


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


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