For the parameter pack size_t ...len, e.g. [len={3,5,2}, I wish to create
double x[3][5][2];
or an equivalent type that I can reference to it (cf Requirement below).
Question
Is there a short way of doing this?
Remarks
I would like to remain able to make heavy use of "dimensional abuse" x[i][j][k] == x[0][0][i*5*2+j*2+k] == (*(x+i))[j][k] etc.
What I tried
My current attempt is:
template<typename Tfloat, int...> struct ARRAY_TYPE;
template<typename Tfloat, int len, int ...lens>
struct ARRAY_TYPE<Tfloat,len,lens...>{
using type = typename ARRAY_TYPE<Tfloat,lens...>::type[len];
};
template<typename Tfloat>
struct ARRAY_TYPE<Tfloat>{
using type = Tfloat;
};
But I am clueless as to figure out whether this yields me actually the exact same constructed type.
I am afraid it does not support "dimensional abuse".
Is there a way to reinterpret an x of above type into a y of my type ARRAY_TYPE<double,len...> ? (That would at least enable me to test for differences in behaviour.)
Or is there maybe even an efficient triple-dot syntax for obtaining the sought type by virtue of a one-liner expression from len... (other than with my tedious ARRAY_TYPE implementation)?
Requirement
For y of my type, I need to be able to reference it from double[3][5][2]. I.e.:
double (&ref)[3][5][2] = y;
Do you mean something like this? Note I will not use "C" style arrays for this (the final std::array of arryas should be contiguous in memory still)