[Issue 8008] static array literal syntax request: auto x=[1,2,3]S;
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Dec 16 06:21:48 PST 2014
https://issues.dlang.org/show_bug.cgi?id=8008
--- Comment #6 from bearophile_hugs at eml.cc ---
(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.
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)]
And probably []s is also faster to compile by the compiler.
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.
The []s will probably become safe to use once D has some kind of tracking of
memory ownership.
There are also some disadvantages, like a little more complexity in the D
language.
--
More information about the Digitalmars-d-bugs
mailing list