My Reference Safety System (DIP???)

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Sun Mar 1 15:56:01 PST 2015


On Sunday, 1 March 2015 at 14:40:54 UTC, Marc Sch├╝tz wrote:
> I don't think a callee-based solution can work:
>
>     class T {
>         void doSomething() scope;
>     }
>     struct S {
>         RC!T t;
>     }
>     void main() {
>         auto s = S(RC!T()); // `s.t`'s refcount is 1
>         T t = s.t;          // borrowing from the RC wrapper
>         foo(s);
>         t.doSomething();    // oops, `t` is gone
>     }
>     void foo(ref S s) {
>         s.t = RC!T();       // drops the old `s.t`
>     }

I thought of this, and I disagree. The very fact of assigning to 
`T t` adds the reference count you need to keep `s.t` from 
disintegrating. As soon as you borrow, you increment the count.


More information about the Digitalmars-d mailing list