Subarrays of arrays

Omid mehdioa at gmail.com
Mon Dec 31 05:29:01 PST 2012


On Sunday, 30 December 2012 at 18:55:50 UTC, bearophile wrote:
> Omid:
>
>
> This code works with the latest beta compiler:
>
>
> import std.algorithm: filter, equal, map, canFind;
> import std.range: transversal, iota;
>
> void main() {
>     auto arr = [[ 1, 2, 3, 4, 5, 6],
>                 [ 7, 8, 9,10,11,12],
>                 [13,14,15,16,17,18]];
>
>     auto r1 = transversal(arr, 0);
>     assert(r1.equal([1, 7, 13]));
>
>     assert(arr[1] == [7,8,9,10,11,12]);
>
>     auto r2 = [0, 2]
>               .map!(i => arr[i])()
>               .transversal(1);
>     assert(r2.equal([2, 14]));
>
>     auto r3 = [0, 2]
>               .map!(i => arr[i][0..3] ~ arr[i][5])();
>     assert(r3.equal([[1,2,3,6],[13,14,15,18]]));
> }
>
>
> Bye,
> bearophile

Thanks again. I started learning std.array and I should say it 
fits all my needs as a mathematics and combinatorics researcher. 
Now I think I am able to give up commercial softwares.


More information about the Digitalmars-d-learn mailing list