www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.range and opApply

What's the attitude of std.range toward opApply?
In some situations I use opApply (and I think some syntax sugar can be added to
define a yield, to make a third way to define lazy iterables in D) and I'd like
to write code like this too:
take(Range(100), 8)

import std.range: isInputRange, take;

struct Range {
    int stop;
    int opApply(int delegate(ref int) dg) {
        int result;

        for (int i = 0; i < stop; i++) {
            result = dg(i);
            if (result)

        return result;

void main() {
    auto r = take(Range(100), 8);

Is it planned to improve those std.range functions to work with opApply too, or
do I have to rewrite them all and them some in my dlibs2, so they can support
both the range protocol and opApply?

May 18 2010