Immutability and arrays

Steven Schveighoffer schveiguy at gmail.com
Tue Dec 14 16:14:28 UTC 2021


On 12/14/21 10:53 AM, Stanislav Blinov wrote:

> Now, since we have copy ctors, slice assignment should, ostensibly, 
> attempt to copy-assign elements (i.e. absent opAssign, try the copy ctor 
> first).

I agree slice-assign should work here with a copy ctor. What I think is 
happening is that it's still very much built on memcpy + postblit (so 
much of the array runtime is still magic functions).

postblit doesn't work because it first makes a copy of the data AS-IS, 
which means it's still immutable, and only after the postblit would it 
be mutable.

-Steve


More information about the Digitalmars-d-learn mailing list