full copies on assignment
John Nixon via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 24 13:58:11 PDT 2016
On Tuesday, 24 May 2016 at 15:17:37 UTC, Adam D. Ruppe wrote:
> 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.
Thank you for this suggestion, perhaps a slightly neater
workaround.
More information about the Digitalmars-d-learn
mailing list