Array expression for multi dimensional arrays

Madhav unmarshall at gmail.com
Wed Mar 23 05:21:47 PDT 2011


== Quote from spir (denis.spir at gmail.com)'s article
> On 03/23/2011 12:01 PM, 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
> IIUC, you can do it level by level only:
> unittest {
>      int[3] a3;
>      int[3][2] a32;
>      a3[] = 1;
>      a32[] = a3;
>      assert(a32 == [[1,1,1], [1,1,1]]);
> }
> Note: in those assignments, [] is optional, but I consider this as a bug. Even
> more since
>     int[3] a3 = 1;	// works
>     int[3][2] a32 = a3	// works not
> denis

Yes i guessed that. My question was more to do with extending array expressions
for multi dimensional arrays as well.
Don't you think this should be provided by the language? It will ease out a lot of
mathematical implementations

Regards,
Madhav


More information about the Digitalmars-d mailing list