RFC on range design for D2
Sergey Gromov
snake.scaly at gmail.com
Tue Sep 9 02:22:14 PDT 2008
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.
More information about the Digitalmars-d-announce
mailing list