DConf 2013 Day 1 Talk 2 (Copy and Move Semantics)

Diggory diggsey at googlemail.com
Sat May 11 04:12:00 PDT 2013


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:

- "unique" objects can be moved into default, const, unique or 
immutable variables, but can never be copied.

- "new"/constructors always returns a "unique" object, which can 
then be moved into any type, completely eliminating the need for 
different types of constructors.

- 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.

- "assumeUnique" would actually return a "unique" type, but would 
be unnecessary in most cases.

- Strings can be efficiently built in "unique" character arrays 
and then safely returned as immutable without a cast.

- The compiler can actually provide strong guarantees about 
uniqueness compared to the rather weak guarantees possible in 
std.typecons.Unique.

- 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.





More information about the Digitalmars-d mailing list