On 2013-05-12, 00:31, Manu wrote:

This is a very interesting idea.
It would also be a massive advantage when passing ownership between
threads, which is a long-standing problem that's not solves at all.
There currently exists no good way to say "I now give ownership to you",
which is what you basically always do when putting a job on a queue to be
picked up by some foreign thread.
Using shared is cumbersome, and feels very inelegant, casts everywhere, and
once the casts appear, any safety is immediately lost.

Can you detail the process involved in assignment from one unique to
another unique? Would the original unique be destroyed? Leaving only the
'copy' remaining?

Not speaking for Diggory, but that's generally the idea, yes. In code:

class A { /* ... */ }

void foo(A a) { /* ... */ }

void fun( ) {
    unique A a = new A();
    unique A b = a;
    assert(a is null);
    foo(b);
    assert(b is null);
}

And with my suggestion for 'lent':

void bar(lent A a) { /* Assigning a (or anything reachable from a) to a global in here is verboten. */ }

void gun( ) {
    unique A a = new A();
    bar(a);
    assert(a !is null);
}

--
Simen

Reply via email to