Array of templated structs
- by Jakub Mertlik
I have structs templated by int derived from a Base struct.
struct Base { int i; double d; };
template< int N > struct Derv : base { static const int mN = N; };
I need to make an array of Derv< N where N can vary for each struct in that array. I know C/C++ does not allow arrays of objects of different types, but is there a way around this? I was thinking of separating the type information somehow (hints like pointers to Base struct or usage of union spring to my mind, but with all of these I don't know how to store the type information of each array element for usage DURING COMPILE TIME). As you can see, the memory pattern of each Derv< N is the same.
I need to access the type of each array element for template specialization later in my code. The general aim of this all is to have a compile-time dispatch mechanism without the need to do a runtime "type switch" somewhere in the code.
Thank you.