foreach change for multi-dimensional data
ixid via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jan 28 05:33:11 PST 2016
This is an idle thought hence putting it on the Learn-level
forum. An idea struck me for foreach to make working with more
complicated data types or heavily nested data easier.
uint[][] a = [[1,2,3],[4,5,6]];
foreach(uint[] b; a)
b.writeln;
At present you can specify the type of 'b' in this example. If
you want to iterate over each uint you have to write (and
obviously you can omit the type for 'b' and 'c'):
foreach(uint[] b; a)
foreach(uint c; b)
c.writeln;
It would be nice if you could do something like this:
foreach(uint c; a)
c.writeln;
Where it will take the ForeachType of 'a' until it finds a match
to the type of 'c' and iterate over all that data. It would make
it much less messy to apply a function that takes uint to all the
data rather than having to nest loops or map maps.
More information about the Digitalmars-d-learn
mailing list