The demise of T[new]

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Oct 19 12:36:57 PDT 2009


Chris Nicholson-Sauls wrote:
>> People expecting a slice and using "auto" or templates are in for a 
>> rude awakening.
>>
>>
>> Andrei
> 
> I would argue that, if they truly *needed* a slice and are relying on 
> "auto" then they implicitly accept responsibility for putting the [] in 
> place to guarantee that.  In other words:
> auto foo = someFunc()[];
> 
> Or T[]'s and T[new]'s could have an alternative to .dup that does the 
> same thing (return self for T[], and return self[] for T[new]).  Either 
> way, it would be something to point out in the book as a best practice: 
> when expecting a slice, guarantee a slice with []'s.

I understand that, but I also believe it's a symptom of a problem 
instead of a solution. One of our goals is to make the best practices 
book as high-level as possible, and integrate many best practices in the 
language.

The above code, therefore, I put in the bin "stuff that the language's 
user must keep in mind". At best that should go away.


Andrei



More information about the Digitalmars-d mailing list