Proposal for design of 'scope' (Was: Re: Opportunities for D)
via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jul 11 12:57:57 PDT 2014
On Friday, 11 July 2014 at 06:49:26 UTC, deadalnix wrote:
> On Thursday, 10 July 2014 at 20:10:38 UTC, Marc Schütz wrote:
>> Instead of lifetime intersections with `&` (I believe Timon
>> proposed that in the original thread), simply specify multiple
>> "owners": `scope!(a, b)`. This works, because as far as I can
>> see there is no need for lifetime unions, only intersections.
>>
>
> There are unions.
>
> class A {
> scope!s1(A) a;
> }
>
> scope!s2(A) b;
>
> b.a; // <= this has union lifetime of s1 and s2.
How so? `s2` must not extend after `s1`, because otherwise it
would be illegal to store a `scope!s1` value in `scope!s2`. From
the other side, `s1` must not start after `s2`.
This means that the lifetime of `b.a` is `s1`, just as it has
been annotated, no matter what the lifetime of `b` is. In fact,
because `s1` can be longer than `s2`, a copy of `a.b` may safely
be kept around after `b` is deleted (but of course not longer
than `s1`).
More information about the Digitalmars-d
mailing list