static array with inferred size

Steven Schveighoffer schveiguy at
Wed Sep 20 14:04:05 UTC 2017

On 9/20/17 1:36 AM, Andrei Alexandrescu wrote:
> On 9/19/17 8:47 PM, Steven Schveighoffer wrote:
>> This needs to happen.
>> e.g.:
>> char[$] arr = "hello"; // syntax up for debate, but I like this.
>> I can't think of a correct way to do this that doesn't heap-allocate 
>> and is DRY.
>> D is so powerful, it's a huge shame it can't figure this one out.
>> issue:
>> Fix that was merged:
>> And then reverted:
>> Maybe there was an issue with the implementation? Can it be redone?
> The argument was it can be done trivially with a library solution.

As I said, I can't figure it out. Perhaps the triviality can be explained?

As Jonathan said, the VRP causes problems, because the compiler has more 
context than a library function. There is also the concern about 
needlessly generating templates and functions for every type and static 
array length combination, just for an initializer.

e.g., make this work without having to specify "3":

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



More information about the Digitalmars-d mailing list