Template

Mael mael.primet at gmail.com
Fri Jun 6 05:49:54 PDT 2008


Hello,

another question,

I wanted to generate an image having an arbitrary dimension (each pixel is a  n-tuple).

The option

class Image(vType, int vDim)
{
...
  vType[vDim][] data ;
}

isn't really good, because the array isn't "unfolded" resulting in some overhead (or is there a way to build a vType[dim][n] array that would be represented as a vType[n*dim] array, and the compiler would optimize arr[p][k] in arr[p*dim+k] ?)

so I wanted to have a template generate a struct that would look like
struct tuple {
vType elem1 ;
vType elem2 ;
...
}
and define the data as
{
...
tuple[] data ;
}

(I guess this would give what I expect).
I couldn't get to do this with template metaprogramming, could anyone give a hint on how to recurse to build such a struct ? 


Thanks 

 


More information about the Digitalmars-d-learn mailing list