DIP 1018--The Copy Constructor--Community Review Round 1
12345swordy
alexanderheistermann at gmail.com
Wed Dec 19 14:34:37 UTC 2018
On Wednesday, 19 December 2018 at 11:53:12 UTC, Kagamin wrote:
> I think const postblit can be done by creating shadow copy of
> instance fields (but still physically located in the field).
>
> struct A
> {
> int b;
> this(this) immutable
> {
> immutable int shadow_b; //reads go here
> //b++
> immutable int t=shadow_b;
> shadow_b.__dtor();
> b.__ctor(t+1);
> }
> }
>
> Type system would treat them as distinct instances, but would
> destroy shadow copy right before assignment, after which shadow
> copy's lifetime ends and it goes out of scope completely, which
> will also invalidate any retained pointers if any.
You should not be resorting to calling the hidden symbol .__dtor,
.__ctor in your production code as that is just asking for
trouble. Which it is not guarantee to grant the behavior that you
desire.
Alex
More information about the Digitalmars-d
mailing list