[Issue 16745] New: Add template helper for creating static arrays with the size inferred
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Nov 23 13:56:08 PST 2016
https://issues.dlang.org/show_bug.cgi?id=16745
Issue ID: 16745
Summary: Add template helper for creating static arrays with
the size inferred
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: issues.dlang at jmdavisProg.com
There is currently no way in the language or in Phobos to create a static array
where the size is inferred. If you do something like
int[5] sa = [1, 2, 3, 4, 5];
you have to explicitly give the length, and if the number of arguments ever
changes, you need to explicitly change the length. There are advantages to
that, but it can also be annoying to have to type the length rather than have
it be inferred. And auto won't do it, because it would infer the type to be a
dynamic array rather than a static one.
As I understand it, at one point there was a PR for dmd which would have added
a syntax such as
int[$] = [1, 2, 3, 4, 5];
to implement this functionality, but it was rejected. However, it should be
simple enough to create a template helper which does the same job and add it to
Phobos.
--
More information about the Digitalmars-d-bugs
mailing list