[Issue 5550] std.range.enumerate()

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 17 01:12:11 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=5550



--- Comment #12 from bearophile_hugs at eml.cc 2014-01-17 01:12:05 PST ---
This should go in the unittests of enumerate():


void main() {
    auto arr = [0];
    foreach (immutable i, ref x; arr.enumerate)
        x++;
    assert(arr[0] == 1);
    foreach (immutable i, ref x; arr.enumerate(10))
        x++;        
    assert(arr[0] == 2);
}



And in the "documentation unittests" of enumerate I think it's a good idea to
add (I explain this use case in the #Comment4):

void main() {
    import std.stdio, std.range;

    auto M = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
    foreach (immutable r, row; M)
        foreach (immutable c, ref item; row.enumerate[1 .. $])
            item = c * 10 + r;
    writefln("%(%s\n%)", M);
}


With its output:

[0, 10, 20, 30]
[0, 11, 21, 31]
[0, 12, 22, 32]

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list