Johan Mollevik wrote: > bearophile wrote: > >> 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 > > That looks like it might work for 2 dimensions and as that is the use > case I have right now I might settle for that. (and I can add more > overloads manually if needed) > > The original code was genereal enough to handle any number of > dimensions thou. > > Bassically this would work like this > > uint[][][] array=... > > foreach(x,v;opApplyN(array)){//using only one index (x) > //v has type uint[][] > } > > > foreach(x,y,v;opApplyN(array)){//using two indeces (x,y) > //v has type uint[] > } > > > foreach(x,y,z,v;opApplyN(array)){//using three index (x,y,z) > //v has type uint > } > > So if someone know anything of why I get the error on recursive aliases > I might try to get that working again otherwise I might try your code > as it is enough for now > > Thnks for the help by the way
Hmm, your solution does not work with static arrays it seems, will se if I can sort that out