On 1/6/21 1:14 PM, Luhrel wrote:
On Wednesday, 6 January 2021 at 17:59:57 UTC, Jacob Carlborg wrote:
On 2021-01-06 10:21, Mike Parker wrote:
This is the discussion thread for the first round of Community Review of DIP 1039, "Static Arrays with Inferred Length":

https://github.com/dlang/DIPs/blob/c06ce7f144b3dabf363d1896ddcd31a2a6b7c969/DIPs/DIP1039.md

There's `staticArray` to solve this issue [1].

[1] https://dlang.org/phobos/std_array.html#.staticArray

It works only for the `int` type and above (and other types as structs).

example with short:
---
extern(C) void main()
{
     import std.array;
     auto a = [0, 1].staticArray!short;  // error
}
---

To fix that, I need to cast every element:
---
extern(C) void main()
{
     import std.array;
     auto a = [cast(short) 1, cast(short) 2].staticArray!short; // ok
}
---

With a tweak, it's possible:

T[n] staticArray(T, size_t n)(T[n] val...) { return val; }

auto arr = staticArray!short(1, 2);

Though the syntax isn't as nice...

-Steve

Reply via email to