On Wednesday, September 20, 2017 01:36:43 Andrei Alexandrescu via Digitalmars-d 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: 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? > > > > -Steve > > The argument was it can be done trivially with a library solution. -- > Andrei
I have yet to see a library solution that is able to accept the full range of arguments that you can give when you provide the length. The closest that I was able to come up with didn't work with VRP, and most of the other solutions I've seen only accept compile-time arguments, meaning that you can't having any variables in the elements used to initialize the static array. I opened https://issues.dlang.org/show_bug.cgi?id=16779 a while ago, since with that enhancement implemented, it _is_ possible to do the same thing that T[$] = would do, but without that, I don't know of any way to get the full functionality that we get right now when the size isn't inferred. Now, I think that something like T[$] = is a very improvement syntactically, so I'd be in favor of it anyway, but regardless, as far as I can tell, if we want this full functionality, we need to improve to the language/compiler - be it by adding syntax for infering the size to the language itself or by fixing it so that VRP works properly with IFTI and auto ref. - Jonathan M Davis