T[new] misgivings

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Oct 15 20:32:11 PDT 2009


Rainer Deyke wrote:
> Andrei Alexandrescu wrote:
>> int[new] a;
>> ....
>> a = [1, 2, 3];
>>
>> What should that do?
> 
> This question can be rephrased as, "should 'int[new]' be a reference
> type or a value type (or something else)?"
> 
> If 'int[new]' is a reference type, then it must rebind, because that's
> what assignment does for reference types.  If 'int[new]' is a value
> type, then it must modify the array in place, because that's all it can
> do.  If 'int[new]' is neither a reference type nor a value type, then
> we're back to (some of) the problems with slices.
> 
> To answer the rephrased question: 'int[new]' should be a value type.

Well Walter and I agreed they should be pass-by-reference. That doesn't 
mean they must be references, and the fact that the simplest syntax has 
the worst efficiency reminds me of iostreams.

>> W: Nobody complained about it with slices.
> 
> FWIW, I found arrays in D1 so completely broken that I didn't it worth
> the effort to complain about every little detail.  Everything about them
> was wrong.  I consider them a textbook example of what not to do.

My perception is that you're in a minority. Anyway, if there's something 
that T[new] can help with, let us know.


Andrei



More information about the Digitalmars-d mailing list