_indexed_ iteration using opApply or range

spir denis.spir at gmail.com
Sun Dec 12 11:47:04 PST 2010


Hello,

Had a nice time figuring out how to let opApply allow index iteration like:
    foreach (i, x ; collection) {}
Finally managed to do it adding 'i' everywhere:

struct S1 {
    private int[] elements = [];
    int opApply (int delegate (ref uint, ref int) block) {
        foreach (uint i, int n ; this.elements)
            block(i, n);
        return 0;
    }
}

Is this the intended idiom?
Now, I'm trying to make this work with ranges instead (input range only as of now). Seems i'm not smart enough to guess it alone...

Thank you,
Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d-learn mailing list