Unique as a transitive type?

Sean Kelly sean at invisibleduck.org
Mon Jun 1 20:11:10 PDT 2009


Jason House wrote:
> Andrei has stated previously that unique was left out of the type system because it added little value to the const system. Now that shared and multithreading are here, unique has more value.
> 
> I have two basic questions:
> 
> 1. What would make unique difficult to add?

Move semantics.  Just passing a unique value type to a function, a copy 
is performed.

> 2. What benefits do you forsee?

Message passing could be done without needless copying and with a 
reasonable degree of safety.  I've done this before in C++ by storing 
the reference in a modified shared_ptr (so it can live in containers), 
then asserting is_unique() and transferring the reference to an auto_ptr 
when passing into the message.  Kind of messy, but it works well enough.



More information about the Digitalmars-d mailing list