Immutability and arrays

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


On 12/14/21 11:14 AM, Steven Schveighoffer wrote:
> 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.

Er... scratch that, this isn't construction, it should use opAssign. 
Again, probably because memcpy+postblit is used by the runtime.

If not reported, it should be.

-Steve


More information about the Digitalmars-d-learn mailing list