Proposal: Make [][x] and [][a..b] illegal (reserve for multidimensional arrays)

Janice Caron caron800 at googlemail.com
Thu Nov 22 11:36:50 PST 2007


I had a mad thought yesterday. It probably won't fly, but...

what if opSlice took tuple arguments, like this

    a[3,4 .. 5,6]

translating to

    a.opSlice(Tuple!(3,4),Tuple!(5,6))

implying the slice [3..5] in one dimension, and [4..6] in a second.
That would kind of automatically give you a syntax for
multidimensional arrays. Of course it would help if length() also took
tuples...

    a.length = Tuple!(3,3); /* create a 3x3 array */

    Tuple!(int,int) dims = a.length; /* get the array dimensions */

I suspect it might be possible to implement this right now in
user-defined classes by suitably overloading opSlice(),
opSliceAssign() and length().

There's probably some reason why it wouldn't work that I haven't thought of. :-)



More information about the Digitalmars-d mailing list