RFC on range design for D2
Robert Jacques
sandford at jhu.edu
Mon Sep 8 19:33:03 PDT 2008
On Mon, 08 Sep 2008 20:37:41 -0400, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Denis Koroskin wrote:
>> 3) Walter mentioned that built-in array could be re-implemented using a
>> pair of pointers instead of ptr+length. Will it ever get a green light?
>> It fits range concept much better.
>
> Walter told me to first implement my design, and if it works, he'll do
> the change. Yes, it does fit ranges much better because the often-used
> next and, um, pop will only touch one word instead of two.
I'd warn that changing away from ptr+length would create logical
incosistencies between 1D arrays and 2D/3D/ND arrays.
>> 4) We need some way of supporting dollar notation in user containers.
>> The hack of using __dollar is bad (although it works).
>
> It doesn't work for multiple dimensions. There should be an
> opDollar(uint dim) that gives the library information on which argument
> count it occured in. Consider:
>
> auto x = matrix[$-1, $-1];
>
> Here the dollar's occurrences have different meanings. A good start
> would be to expand the above into:
>
> auto x = matrix[matrix.opDollar(0)-1, matrix.opDollar(1)-1];
I'd also add that multiple dimension slicing should be supported. i.e.
auto x = matrix[2..5,0..$,3]
would become
auto x =
matrix.opSlice(Slice!(size_t)(2,5),Slice!(size_t)(0,matrix.opDollar(0)),3)
with
struct Slice (T) { T start; T end; }
Strided slices would also be nice. i.e. matrix[0..$:10] // decimate the
array
More information about the Digitalmars-d-announce
mailing list