Strange copying of a constant array of structures

user1234 user1234 at 12.de
Fri Jun 14 08:18:27 UTC 2024


On Friday, 14 June 2024 at 08:03:47 UTC, Vindex wrote:
> Last night I encountered some strange behavior of the dup [...]
> I feel that I do not understand something, please explain what 
> is the problem of constant structures with reference fields?

`const` is transitive, not only `S` instances are but also their 
members.

> And why is the copy constructor only called once in the last 
> example? Optimization?

Yes kind of optim. The compiler is allowed to use 
"move-semantics". Looks like it's what happens here (at first 
glance).


More information about the Digitalmars-d mailing list