Object-based interface for a range of ranges

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 27 23:25:06 PST 2016


On 01/27/2016 08:59 PM, Luís Marques wrote:
> This works:
>
>      int[][] a;
>      RandomAccessFinite!(int[]) r = inputRangeObject(a);
>
> What would be a good way to achieve something equivalent to this?:
>
>      int[][] a;
>      RandomAccessFinite!(RandomAccessFinite!int) r = inputRangeObject(a);

All I can say is the following compiles. I hope it works too. :)

import std.range;
import std.algorithm;
import std.conv;

void main() {
     int[][] a;
     RandomAccessFinite!(RandomAccessFinite!int) r
         = inputRangeObject(
             a.map!(e => inputRangeObject(e).to!(RandomAccessFinite!int)));
}

Instead of to!(RandomAccessFinite!int) one can use the cast operator as 
well.

Ali



More information about the Digitalmars-d mailing list