The demise of T[new]
Michel Fortin
michel.fortin at michelf.com
Mon Oct 19 18:54:35 PDT 2009
On 2009-10-18 17:05:39 -0400, Walter Bright <newshound1 at digitalmars.com> said:
> The purpose of T[new] was to solve the problems T[] had with passing
> T[] to a function and then the function resizes the T[]. What happens
> with the original?
>
> The solution we came up with was to create a third array type, T[new],
> which was a reference type.
>
> Andrei had the idea that T[new] could be dispensed with by making a
> "builder" library type to handle creating arrays by doing things like
> appending, and then delivering a finished T[] type. This is similar to
> what std.outbuffer and std.array.Appender do, they just need a bit of
> refining.
>
> The .length property of T[] would then become an rvalue only, not an
> lvalue, and ~= would no longer be allowed for T[].
>
> 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++.
>
> What do you think?
I never liked T[new] much from the beginning, so good riddance. :-)
But seriously, disallowing '~=' but not '~'? I can already see the newbies:
Q: Why can't I write '~=' as a shortcut for '~' on a slice? It works
fine for every other operator, everywhere else.
A: Because appending is not very efficient.
Q: So '~' is more efficient than '~='?
A: Hum, no. They're both as inefficient, but...
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list