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.<div class="gmail_extra">
<br><br><div class="gmail_quote">On Mon, Nov 19, 2012 at 11:25 PM, Mike Wey <span dir="ltr"><<a href="mailto:mike-wey@example.com" target="_blank">mike-wey@example.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 11/19/2012 07:04 PM, H. S. Teoh wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm experimenting with implementing "true" multidimensional arrays in D.<br>
It's actually very nice, compared with the hassle of memory management<br>
in C/C++, and it even lets you give opIndex multiple parameters so that<br>
you can write things like arr[1,2] instead of the uglier arr[1][2] (or<br>
worse, arr[2][1]).<br>
<br>
Two questions, though:<br>
<br>
1) Is multidimensional slicing supported? I.e., does opSlice support<br>
notation like arr[1..2, 2..3]?<br>
</blockquote>
<br></div>
This is currently not supported. Would be nice to have tough.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2) Is opDollar supported for multidimensional arrays? I.e., when you<br>
write arr[1..$, 2..$], the $ in each dimension can potentially be<br>
different values (say you have a 2x3 array, so the first $ is 2, and the<br>
second $ is 3)?<br>
</blockquote>
<br></div>
size_t opDollar(int dim)()<br>
{<br>
<br>
}<br>
<br>
Where dim is the dimension in witch the $ is being used.<div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
D will totally rock if these features are supported.<br>
<br>
<br>
T<br>
<br>
</blockquote>
<br>
-- <br></div></div><span class="HOEnZb"><font color="#888888">
Mike Wey<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br>
</div>