On 07/10/2012 10:48 AM, Simen Kjaeraas wrote:
> On Tue, 10 Jul 2012 16:15:09 +0200, Jacob Carlborg <d...@me.com> wrote:

>> How do you store your ranges in a struct or class? Most of them are
>> voldemort types.
>
> Well, there is std.range.inputRangeObject, but as the name indicates

As the name "misleads"... :)

>, it's
> only an input range.

... it can be used as any one of the non-OutputRanges:

import std.algorithm;
import std.range;
import std.stdio;

void main() {
     int[] a1 = [1, 2, 3];

     ForwardRange!int r1 = inputRangeObject(map!"2 * a"(a1));
     ForwardRange!int r2 = inputRangeObject(map!"a ^^ 2"(a1));

     auto a2 = [r1, r2];

     writeln(a2);
}

Replace ForwardRange!int above with any other non-OutputRange, and as long as the input to inputRangeObject() is compatible, it will work. (static if magic).

Ali

Reply via email to