static array with inferred size

Steven Schveighoffer schveiguy at yahoo.com
Wed Sep 20 16:55:25 UTC 2017


On 9/20/17 11:48 AM, Dgame wrote:
> 
> Works:
> ----
> char[5] b = "hallo".s;
> ----

Sure, but completely misses the point!

> Otherwise you could simply use Unqual:
> ----
> Unqual!T[n] s(T, size_t n)(T[n] arr)
> {
>      return arr;
> }
> 
> auto a = "hallo".s;
> writeln(typeof(a).stringof); // char[5]
> ----

This might work better, although it's not necessarily what the user 
wants. It does solve my use case, so that is good! And it's much easier 
to declare something to be immutable or const than it is to force it to 
be mutable.

Still it can't handle the case of:

ubyte[3] x = [1, 2, 3];

-Steve


More information about the Digitalmars-d mailing list