T[new] misgivings
Walter Bright
newshound1 at digitalmars.com
Fri Oct 16 02:53:20 PDT 2009
Don wrote:
> Max Samukha wrote:
>> // arrays are true reference types
>> int[new] a = [1, 2, 3];
>> b = a;
>> a.length = 22;
>> assert (a.length == b.length);
>
> This makes perfect sense to me. The rule would be:
> If 'x' is T[new], then:
> x = y; _always_ copies y into a {length, capacity-specified block},
> unless it already is one. x is given a pointer to the start of that block.
> x[] = y[]; does a memcpy, regardless of whether y is a T[new] or a T[].
Right. Assignment of a reference type does not copy the values of what
is referred to. Only the reference is copied.
I think it would be very strange to have T[] behave like a reference
type (which it does now) and T[new] to behave like a value type.
More information about the Digitalmars-d
mailing list