www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16745] New: Add template helper for creating static arrays


          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 puremagic.com
          Reporter: issues.dlang 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

Nov 23 2016