RFC on range design for D2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Sep 9 03:25:06 PDT 2008


Sergey Gromov wrote:
> Denis Koroskin <2korden at gmail.com> wrote:
>> 5) I don't quite like names left and right! :) I think they should  
>> represent limits (pointers to begin and end, in case of array) rather that  
>> values. In this case, built-in arrays could be implemented as follows:
>>
>> struct Array(T)
>> {
>>      T* left;
>>      T* right;
>>      size_t length() { return right-left; }
>>      ref T opIndex(size_t index) { return left[index]; }
>>      // etc
>> }
>>
>> The rationale behind having access to range limits is to allow operations  
>> on them. For example,
>> R.left-=n;
>>
>> could be used instead of
>> foreach(i; 0..n) {
>>      R.pop();
>> }
> 
> Now you stepped onto your own landmine.  :)  "R.left-=n" extends the 
> range beyond its beginning with unpredictable consequences.  That's why 
> such operations shouldn't be easily accessible.

Oh I thought it's R.right -= n.

It has become clear to me that a range never increases. It always 
shrinks. It can increase if fused to another range (I'm thinking of 
relaxing the fusion operations to allow for overlapping/adjacent ranges, 
not only ranges that include one another). But without extra info from 
the container a range can never grow.


Andrei


More information about the Digitalmars-d-announce mailing list