Chaining a dynamic number of Ranges

Enerqi kelvin.d.ward at googlemail.com
Sat Jul 21 09:42:48 PDT 2012


Hello

I'm playing around with my first D program and can't figure out a 
way to chain a dynamic number of ranges. In this example I'm 
trying to chain a two dimensional array into effectively a one 
dimensional array, so I can later sort it as one sequence.


--------
import std.algorithm;
import std.range;

// n is determined at runtime
uint[][] arrays = new uint[][n];
foreach(ref a; arrays)
{
     a = new uint[10];
     copy(iota(10), a);
}

auto c = chain(arrays[0], arrays[1]);
foreach(a; arr[2..$])
{
     c = chain(c, a);
}
--------

Gives a compile error:
Error: cannot implicitly convert expression (chain(c,a)) of type 
Result to Result

any ideas?

Thanks.




More information about the Digitalmars-d-learn mailing list