Array index slicing
Christophe Travert
travert at phare.normalesup.org
Mon Jul 16 02:06:37 PDT 2012
"bearophile" , dans le message (digitalmars.D:172300), a écrit :
> If enumerate() is well implemented it's one way to avoid that
> problem (other solutions are possible), now 'c' gets sliced, so
> it doesn't start from zero:
>
> import std.stdio;
> void main() {
> auto M = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
> foreach (r, row; M)
> foreach (c, ref item; enumerate(row)[1 .. $])
> item = c * 10 + r;
> writefln("%(%s\n%)", M);
> }
enumerate could be useful with retro too. You may want to change the
order of the enumeration, but not the order of the indices.
More information about the Digitalmars-d
mailing list