static array with inferred size

Meta jared771 at gmail.com
Wed Sep 20 02:46:53 UTC 2017


On Wednesday, 20 September 2017 at 01:29:39 UTC, Jonathan M Davis 
wrote:
> On Tuesday, September 19, 2017 20:47:25 Steven Schveighoffer 
> via Digitalmars-d 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: https://issues.dlang.org/show_bug.cgi?id=481
>>
>> Fix that was merged: https://github.com/dlang/dmd/pull/3615
>>
>> And then reverted: https://github.com/dlang/dmd/pull/4373
>>
>> Maybe there was an issue with the implementation? Can it be 
>> redone?
>
> All in all, I think that it would be cleanest if this were just 
> implemented in the language. I recall there being discussions 
> about adding it with the syntax you showed, and on reflection, 
> I _think_ that I recall Walter objecting to it for some reason, 
> which is why it was reverted, but I don't remember the details 
> at all at this point, so I could easily be remembering 
> incorrectly.

That was the main reason it was reverted. A contributing factor 
is that Beadophile had been trying to push this feature for a 
long time, and once it got in (against W&A's reservations, 
although they eventually gave the okay) he started pushing harder 
for the []s syntax for static array literals, arguing that now 
that we had static array length deduction syntax we needed static 
array literal syntax as well. This was the straw that broke the 
camel's back for Andrei and he decided to revert the length 
deduction PR citing concerns over feature bloat. There was also 
other functionality tied up with the deduction syntax - see this 
post: 
https://forum.dlang.org/post/wagryggxehnbsbyhwkgf@forum.dlang.org

With all due respect to Andrei, I think he overreacted a bit and 
it was a mistake to revert static array length deduction 
(although the array/aa type deduction on steroids was probably 
overly complicated so that was a good call). Maybe now that @nogc 
and betterC are squarely in focus we can revisit array length 
deduction.


More information about the Digitalmars-d mailing list