The demise of T[new]

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 18 19:55:40 PDT 2009


dsimcha wrote:
> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
>> Jason House wrote:
>>> Andrei Alexandrescu Wrote:
>>>
>>>> grauzone wrote:
>>>>> Walter Bright wrote:
>>>>>> We both feel that this would simplify D, make it more flexible,
>>>>>> and remove some awkward corner cases like the inability to say
>>>>>> a.length++.
>>>>> How would this remove this corner case?
>>>> Can't increment length if it's read-only.
>>>>
>>>> Andrei
>>> removing syntactic sugar doesn't really remove corner cases. T[new]
>>> is being replaced with an array builder. What usage semantics are
>>> given up with an array builder? How will implicit conversions be
>>> handled? (alias this, etc...). How will the Phobos array buiilder
>>> support user specified lengths (for efficiency)?
>> I think ArrayBuilder could a logic similar to Appender for "~=" and
>> otherwise offer regular array primitives. I don't think implicit
>> conversion to T[] is an essential feature, but it can be done.
>> Andrei
> 
> So basically, ArrayBuilder would be like T[new], except:
> 
> 1.  It would be a plain old library type, and the core language would know nothing
> about it.
> 2.  T[].dup, T[] ~ T[], new T[3], etc. would return T[], not ArrayBuilder/T[new].
> 
> Is this basically correct?

Yes, that's the plan. I hope you're not setting me up or something :o).

Andrei



More information about the Digitalmars-d mailing list