<div dir="ltr">On 11 May 2013 21:12, Diggory <span dir="ltr"><<a href="mailto:diggsey@googlemail.com" target="_blank">diggsey@googlemail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Just listened to this talk and it made me think about the various type qualifiers. Has there ever been any thought of introducing a new type qualifier/attribute, "unique"? I know it already exists as a standard library class but I think there are several advantages to having it as a language feature:<br>

<br>
- "unique" objects can be moved into default, const, unique or immutable variables, but can never be copied.<br>
<br>
- "new"/constructors always returns a "unique" object, which can then be moved into any type, completely eliminating the need for different types of constructors.<br>
<br>
- Functions which create new objects can also return a "unique" object solving the problem mentioned in this talk of whether or not to return immutable values.<br>
<br>
- "assumeUnique" would actually return a "unique" type, but would be unnecessary in most cases.<br>
<br>
- Strings can be efficiently built in "unique" character arrays and then safely returned as immutable without a cast.<br>
<br>
- The compiler can actually provide strong guarantees about uniqueness compared to the rather weak guarantees possible in std.typecons.Unique.<br>
<br>
- It can be extremely useful for optimisation if the compiler can know that there are no other references to an object. There are countless times when this knowledge would make otherwise unsafe optimisations safe.<br></blockquote>
<div><br></div><div style>This is a very interesting idea.</div><div style>It would also be a massive advantage when passing ownership between threads, which is a long-standing problem that's not solves at all.</div><div style>
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.</div><div style>Using shared is cumbersome, and feels very inelegant, casts everywhere, and once the casts appear, any safety is immediately lost.</div>
<div style><br></div><div style>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?</div></div></div></div>