I’ve some code that produces a set of tr1::array of different sizes, but same type, like
array<int, 2>
array<int, 4>
array<int, 6>
The number of these arrays, and their sizes, are given in compile time, so I know exactly how many of them there will be and how’s big each one (but they may be different).
Problem: I would like to put them in a collection (using array<> would be great), but type must be equal for all the members and this is not the case.
I thought about using boost::variant, but how can specify a variant with a compile-time determined list of types (I’m thinking about an heavy usage of the preprocessor…)?
What about using boost::any? Other methods? (Wild pointers?)
TIA
~Aki
Correction: preprocessor is not usable in this case.
I would use Boost’s MPL and Fusion libraries. There are two ways of ending up with the type list: generate them, or explicitly define them. The former is bit more flexible, but it’s hard to say which is right for you since we don’t know how you get the values you have.
In any case, generating:
Or explicitly stating:
Either way, you can then use it like this: