Array expression for multi dimensional arrays

Daniel Green venix1 at gmail.com
Wed Mar 23 18:03:57 PDT 2011


On 3/23/2011 7:01 AM, Madhav wrote:
> Hi,
>
> I tried to do the following:
> auto arr = new int[2][2];
> arr[] = 1; // using array expressions
> // The above gives - Error: cannot implicitly convert expression (1) of type
> int  to const(int[2u][])
>
> This was the first step to try out if array arithmetic that worked with single
> dimensional arrays worked with multi-dimensional. I guess it does not.
>
> The immediate utility of this would be to cleanly do matrix algebra. Any ideas
> why powerful array expressions were not extended to multi dimensional arrays
> as well?
>
> Regards,
> Madhav

I'm not sure this applies to your topic, but it gave me something to 
play with that may be related.

Static arrays are always laid out contiguously in memory.  This appears 
to allow casting to a single dimensional array.

     auto a = new int[3][2];
     int[] test = cast(int[]) a;
     printf("%d\n", test.length); // Equals 6.






More information about the Digitalmars-d mailing list