Do sorted ranges have any special properties?

Tomek Sowiński just at ask.me
Wed Jul 28 12:42:57 PDT 2010


Andrei Alexandrescu wrote:

> Tomek Sowiński wrote:
>> From a different angle, I was thinking that assumptions should give more;
>> look at this:
>> 
>> auto range = [2, 3, 4];
>> auto sorted = assumeSorted(r);
>> range[0] = 666; // BANG! assumeSorted replaced range with Range.init
>> sorted[0] = 666; // BANG! assertion in Sorted's setter went off
>> range = sorted.dropAssumption;
>> sorted[0] = 666;  // BANG! now sorted's range reference is nulled.
>> range[0] = 666;  // OK... phew!
>> 
>> Assumption producers like sort() would take the range by ref to comply
>> with this idiom. Of course if you save() the range before it's eaten by
>> assumeSorted, you can twiddle away through the saved range. Still, it's
>> better than nothing. Oh, and the unique-like behavior can be expanded
>> onto assumeUnique and, I dare say, assumeWhatever.
>> 
>> Like it?
>>  
>> 
>> Tomek
> 
> Like it, just one issue - destructive copy is unlikely to solve any
> problems. The big problems arise with long-distance aliasing, much less
> from messing with the source of the assignment directly.

I know. Yet, it does no harm and is better than what is now.


Tomek


More information about the Digitalmars-d mailing list