Why is std.algorithm so complicated to use?

Ali Çehreli acehreli at yahoo.com
Tue Jul 10 18:20:31 PDT 2012


On 07/10/2012 10:48 AM, Simen Kjaeraas wrote:
 > On Tue, 10 Jul 2012 16:15:09 +0200, Jacob Carlborg <doob at 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



More information about the Digitalmars-d mailing list