template type deduction of static 2d arrays

uri via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 24 16:59:55 PDT 2014


On Friday, 24 October 2014 at 23:46:28 UTC, uri wrote:

>
> On a related note, does the D spec guarantee the following will 
> be rectangular in memory?
>
> auto a = [ [1,2],[3,4] ];
>
>
> Cheers,
> uri

I just checked the docs and auto a = [ [1,2],[3,4] ] will be an 
an array of pointers. So this cannot work (unless the compiler 
truly is magical :)

auto a = [ [1,2],[3,4] ];
cast(int[2][2])(a);

but this should work:

enum a = [ [1,2],[3,4] ];
cast(int[2][2])(a);


(all untested)

Thanks,
uri


More information about the Digitalmars-d-learn mailing list