uniqueness

Fawzi Mohamed fawzi at gmx.ch
Fri Dec 10 04:40:49 PST 2010


On 10-dic-10, at 11:53, Don wrote:

> Fawzi Mohamed wrote:
>
>> If one could declare return or out types as unique (note that  
>> unique is *not* part of the type, it is like the storage  
>> attributes), these methods could be implicitly castable to const or  
>> immutable, allowing nicer code.
>> Constructors *might* return unique objects (an object is unique  
>> only if all its references are to unique or immutable objects).
>> In several cases uniqueness could be checked by the compiler. I  
>> think that such a change would improve part of my code, removing  
>> the need for several spurious casts, while at the same time making  
>> the code safer.
>
> Any mutable object returned from a strongly pure function, is  
> guaranteed to be unique.

indeed good catch, I was saying that in some occasions the compiler  
can verify uniqueness, that is indeed an important case.

But I don't understand if you want to imply that uniqueness should not  
be explicit, but just guaranteed to be detected and used in some  
occasions, as in the case you gave.

Because any object builder (as for example an array concatenate  
object) cannot be pure, but can still return an unique object.

about front_const , there I thought harder about having an implicit  
only use of it, but also there I think that it is not such a good idea


More information about the Digitalmars-d mailing list