[Issue 8008] Syntax for fixed size array literals like [1,2,3]s

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Dec 27 09:02:06 PST 2014


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

--- Comment #8 from Nick Treleaven <ntrel-pub at mybtinternet.com> ---
(In reply to bearophile_hugs from comment #6)
> (In reply to Nick Treleaven from comment #5)
> > Is there an advantage of literal syntax vs. a template function
> > staticArray(1, 2)?
> 
> There are various small advantages. A template function like that seems to
> generate template bloat.

Yes, but this is already pervasive in Phobos.

> It's also longer to write:
> 
> [[1,2]s, [1,2]s, [1,2]s, [1,2]s]
> 
> versus:
> 
> [staticArray(1,2), staticArray(1,2), staticArray(1,2), staticArray(1,2)]

alias s = staticArray;

> And probably []s is also faster to compile by the compiler.

Probably not noticeably.

> Also, staticArray returns a fixed-size array, that according to the D ABI is
> a pointer, and the compiler has to inline the call to staticArray to regain
> efficiency. By default the D compiler inlines only if you use -inline. The
> []s lacks this problem and is efficient at all compilation levels.

This is another general problem. Inlining small template functions by default
might be nice, if it doesn't slow the compiler too much, and could help avoid
template bloat. But passing -inline isn't too much to ask IMO.

--


More information about the Digitalmars-d-bugs mailing list