auto arr = [1, 2, 3] should be a static array, not a GC allocated array
Salih Dincer
salihdb at hotmail.com
Sun Jul 17 07:04:01 UTC 2022
On Saturday, 16 July 2022 at 18:59:52 UTC, Paul Backus wrote:
> Because the literal `[1, 2, 3]` is considered an `int` array
> literal, not a `byte` array literal.
>
> It works if you use an explicit cast:
>
> ```d
> auto arr = staticArray(cast(byte[]) [1, 2, 3]);
> static assert(is(typeof(arr) == byte[3])); // ok
> ```
Thank you, but this complicates things! Because it makes using
staticArray unnecessary:
```d
auto def = sa(cast(char[3]) [100, 101, 102]);
assert(is(typeof(def) : char[3]));
import std.stdio;
auto cdef = cast(char[4]) [99, 100, 101, 102];
cdef.writeln; // "cdef"
```
I think DIP1039 should be opened for review in the next version
urgently.
SDB at 79
More information about the Digitalmars-d
mailing list