Error on recursive alias

bearophile bearophileHUGS at lycos.com
Sun Aug 25 09:07:41 PDT 2013


Johan Mollevik:

> x and y are the two dimensional indices into the 4x4 array 
> block and v
> is the vallue at block[y][x]

OK. Something like this?


import std.stdio, std.typecons;

struct NaturalScan(T) {
     T[][] data;
     size_t r, c;

     @property bool empty() const pure nothrow {
         return r == data.length;
     }

     @property Tuple!(size_t, size_t, T) front()
     const pure nothrow {
         return typeof(return)(r, c, data[r][c]);
     }

     void popFront() pure nothrow {
         c = (c + 1) % data[r].length;
         if (c == 0)
             r++;
     }
}

NaturalScan!T naturalScan(T)(T[][] m) {
     return typeof(return)(m);
}

void main() {
     auto mat = [[10, 20], [30, 40, 50], [60, 70]];
     foreach (r, c, v; mat.naturalScan)
         writefln("%d %d %d", r, c, v);
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list