full copies on assignment

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 24 08:17:37 PDT 2016


On Tuesday, 24 May 2016 at 14:29:53 UTC, John Nixon wrote:
> This naively doesn’t seem right because the RHS of an 
> assignment should not be altered by it.

It's because the char[] being shallow copied still leads to 
mutable stuff.

What I typically do here is just add a method `dup` to the struct 
that deep copies. Then you do `CS cs = rhs.dup;` when you want to 
construct it, like you'd do with a copy of a naked array.


More information about the Digitalmars-d-learn mailing list