The D Programming Language page 161.
Adam D. Ruppe
destructionator at gmail.com
Wed Nov 13 06:51:11 PST 2013
On Wednesday, 13 November 2013 at 08:16:34 UTC, Tor Einar
Tønnessen wrote:
> void writeln(string a0, int a1, string a2, int[new] a3) {
Around the time the book was written, there was a debate as to if
we should make dynamic arrays and slices two different types.
T[new] was the proposed syntax for a dynamic array, leaving T[]
to be a slice.
The reasoning would be to separate a window into the memory block
- the slice - from the memory block itself, the array. This is
the case with static arrays: int[10] != int[], but not with
dynamic arrays. The advantage of the separation would be to help
keep track of the array's ownership - appending to a T[new] could
resize the block, whereas appending to a T[] would be a whole new
allocation, among other things.
However, minds were changed and T[new] never actually came to be.
Instead, slice append was changed to address the ownership
stomping problem, it asks the gc for capacity at the end. The old
problem is solved, and it didn't break any code by introducing a
new type... everyone wins, except for the few things written
about T[new] that weren't updated.
This article goes into the append to slice problem and solution
in more detail:
http://dlang.org/d-array-article.html
Bottom line, any time you see T[new] in the book, just replace it
with T[] and it should all work. So int[] a3 ought to compile and
do the same thing described.
BTW, I don't see this item in the list, but on Andrei's website,
there's a list of little changes since the printing:
http://erdani.com/index.php?cID=109
More information about the Digitalmars-d-learn
mailing list