My Reference Safety System (DIP???)
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Sun Mar 1 16:06:50 PST 2015
On Sunday, 1 March 2015 at 23:56:02 UTC, Zach the Mystic wrote:
> 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.
I'm sure many inc/dec can still be removed.
More information about the Digitalmars-d
mailing list