Subarrays of arrays
    bearophile 
    bearophileHUGS at lycos.com
       
    Sun Dec 30 10:55:48 PST 2012
    
    
  
Omid:
> Thanks, though I didn't understand a word you said:).
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
    
    
More information about the Digitalmars-d-learn
mailing list