higher-order funcs for ranges (with usual interface)
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Wed Feb 2 05:19:47 PST 2011
On Wed, 02 Feb 2011 13:18:07 +0000, Lars T. Kyllingstad wrote:
> [...]
>
> struct Map(Range, In, Out)
> if (isInputRange!Range && is(ElementType!Range : In)
> {
> Range input;
> Out delegate(In) f;
>
> @property bool empty() { return input.empty; }
>
> // Inefficient, should cache front... @property Out front() {
> return f(input.front); }
>
> void popFront() { input.popFront(); }
> }
>
> Map!(Range, Out) map(Range, In, Out)(Range input, Out delegate(In) f)
> if (isInputRange!R && is(ElementType!Range : In)
> {
> return typeof(return)(input, f);
> }
Oops, seems i missed a few closing parentheses on the template
constraints.
-Lars
More information about the Digitalmars-d-learn
mailing list