I think it would be better to make the slice syntax (a..b) a type of its own. the foreach could use that type as an aggregate and opSlice (and friends) would be replaced with an opIndex, which takes a slice. This would also allow one to construct slices of user-defined types (e.g. integers of specific ranges) and different type wrappers to allow overloading. To go one step further, it would be nicer to have the double dot, (which is currently magical syntax for slices) become a legitimate overloadable binary operator. I think we could do much more interesting things, then merely multidimensional slices with a slice operator.


On Mon, Nov 19, 2012 at 11:25 PM, Mike Wey <mike-wey@example.com> wrote:
On 11/19/2012 07:04 PM, H. S. Teoh wrote:
I'm experimenting with implementing "true" multidimensional arrays in D.
It's actually very nice, compared with the hassle of memory management
in C/C++, and it even lets you give opIndex multiple parameters so that
you can write things like arr[1,2] instead of the uglier arr[1][2] (or
worse, arr[2][1]).

Two questions, though:

1) Is multidimensional slicing supported? I.e., does opSlice support
notation like arr[1..2, 2..3]?

This is currently not supported. Would be nice to have tough.


2) Is opDollar supported for multidimensional arrays? I.e., when you
write arr[1..$, 2..$], the $ in each dimension can potentially be
different values (say you have a 2x3 array, so the first $ is 2, and the
second $ is 3)?

size_t opDollar(int dim)()
{

}

Where dim is the dimension in witch the $ is being used.


D will totally rock if these features are supported.


T


--
Mike Wey



--
Bye,
Gor Gyolchanyan.