Subarrays of arrays

Omid mehdioa at gmail.com
Sun Dec 30 09:43:06 PST 2012


On Sunday, 30 December 2012 at 12:51:58 UTC, bearophile wrote:
> Omid:
>
>> arr = [[1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15,16,17,18]]
>>
>> I want to obtain a subarray like
>>
>> assert(arr[][0] == [1,7,13]);
>
> This gives a range, not an array, so if you want an array, you 
> have to call std.array.array later:
>
> http://dlang.org/phobos/std_range.html#transversal
>
>
>> assert(arr[1][] == [7,8,9,10,11,12];
>
> Just use array[1]. Or array[1].dup is you want a copy.
>
>
>> assert(arr[0,2][1] == [2,14]);
>
> Enumerated indexes are not supported, so you need a iota + 
> filter + transversal + array.
>
>
>> assert(arr[0,2][0..3,5] == [[1,2,3,6],[13,14,15,18]]);
>
> This requires a iota + filter + chain + array, or something 
> like that.
>
> If you don't want to do all this, you have to write your 
> slicing and dicing array struct :-( Someday it will probably be 
> present in Phobos.
>
> Bye,
> bearophile

Thanks, though I didn't understand a word you said:). I should 
learn iota, filter, transversal first.


More information about the Digitalmars-d-learn mailing list