Multidimensional slice
Rafael
rfkadyrov at gmail.com
Wed Dec 19 06:08:24 PST 2012
On Wednesday, 19 December 2012 at 13:28:24 UTC, Nekroze wrote:
> On Wednesday, 19 December 2012 at 12:27:32 UTC, Rafael wrote:
>> 1) It is possible to implement multiindex access using
>> opIndex* methods, moreover this is the simplest way to
>> multiindex access realization. So, we have [i, j, k] notation.
>> Next step after it - slices implementation and it looks
>> logical to save the same notation for it: [i1..i2, j1..j2, k].
>> But it impossible, if I understand correctly.
>>
>> 2) On the other hand. Syntax via [i][j] leads to some
>> overhead: first index access [i] must return some light
>> accessor object (like range (or iterator)) which supports the
>> index access operation. But using this approach it is possible
>> to implement multidimensional slices. And this means, that
>> opIndex* methods with multiindex are not needed.
>
> Well if you are looking at operator overloading you can
> overload opSlice as described here
> http://dlang.org/operatoroverloading.html#Slice however i am
> not sure if you can defined multiple slices delimited by commas
> in the same [] block but it is worth a try.
...and we return to my initial question :)
The answer is: no, D is not support multidimension slices.
Possible way to solve it is to define some auxiliary structure
Slice, and use multiindex by following way:
S [ Slice(0, $), 2] = A [ Slice(0, $), 2];
More information about the Digitalmars-d-learn
mailing list