Array literals

Sergey Gromov snake.scaly at gmail.com
Thu Oct 16 04:26:12 PDT 2008


Wed, 15 Oct 2008 21:12:31 -0400,
Steven Schveighoffer wrote:
> 
> "bearophile" <bearophileHUGS at lycos.com> wrote in message 
> news:gd63sv$2j0t$1 at digitalmars.com...
> > Steven Schveighoffer:
> >> I think this can be solved even simpler.  Make string literal type be
> >> invariant(char)[] instead of static array.  It does not need to be on the
> >> heap.  That would solve lots of IFTI problems too.
> >
> > With your idea this syntax:
> > auto a = ["Hello", "what"];
> > Gives a fixed-sized array of invariant(char)[]. I think that's asymmetric. 
> > My suggestion works with all arrays, so the array 'a' too becomes/is 
> > dynamic, keeping the simmetry.
> 
> Sure, make the type dynamic for all array literals.  My issue is with your 
> proposal to make the data allocated on the heap.
> 
> There is no need for an array literal to be typed as a static array.  Ever.

I can see one need, matrix literals:

auto blah =
[
  [ 1,  0,  0 ],
  [ 0,  0, -1 ],
  [ 0, -1,  0 ]
];

so that blah is a sequence of 9 numbers accessed accordingly, not 3 
arrays of arbitrary length each.

Well, it's probably a special case and deserves a special, safer syntax.



More information about the Digitalmars-d mailing list