[Issue 6421] Require initialization of static arrays with array literals not to allocate

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun May 4 03:38:14 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=6421

--- Comment #7 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Andrej Mitrovic from comment #5)
> (In reply to bearophile_hugs from comment #3)
> > (In reply to Andrej Mitrovic from comment #2)
> > 
> > > With a parser fix we could implement this in D:
> > >     float[3] arr = float[3](1.0, 2.0, 3.0);
> > 
> > I also like this syntax (composed of two parts usable in different
> > situations):
> > 
> > float[$] arr = [1.0, 2.0, 3.0]s;
> > 
> > Or:
> > 
> > auto arr = [1.0f, 2.0f, 3.0f]s;
> 
> I don't like them, they're too much of a special case. Re-using existing
> syntax is better IMO.

I also think that "static array literal sytax" (eg. DIP34) is not good feature.

But "length inference" on variable declaration is a useful syntax.

float[$] arr = [1, 2, 3];          // typeof(arr) == float[3]
auto[$] arr = [1.0f, 2.0f, 3.0f];  // dito

--


More information about the Digitalmars-d-bugs mailing list