Built-in array opSliceAssign

Paul Backus snarwin at gmail.com
Thu Oct 25 12:38:44 UTC 2018


On Thursday, 25 October 2018 at 12:25:37 UTC, Eduard Staniloiu 
wrote:
> As I wrote in the comments above, I was expecting `a[] = b[]` 
> to iterate the slices and assign the elements of b into a.
>
> What really happens is a memcpy: as you can see from godblot 
> [0], this gets lowered to a call to `_d_arraycopy`, in druntime.

In D, when you assign one aggregate to another, opAssign is only 
called for the aggregate, not for any of its elements. However, 
postblit constructors are called for both. Example: 
https://run.dlang.io/is/XfDaWw

Your example will work as expected if you change the opAssign to 
a postblit constructor: https://run.dlang.io/is/HBbGO2


More information about the Digitalmars-d-learn mailing list