Discussion Thread: DIP 1039--Static Arrays with Inferred Length--Community Review Round 1

Luhrel lucien.perregaux at gmail.com
Wed Jan 6 18:14:42 UTC 2021


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
}
---


More information about the Digitalmars-d-announce mailing list