The future of foreach| or just ...
downs
default_357-line at yahoo.de
Sun Dec 23 05:13:17 PST 2007
Or just do this:
>
> module lockstep;
> import std.stdio;
>
> struct _lockstep(T) {
> T[] a, b;
> int opApply(int delegate(size_t id, ref T, ref T) dg) {
> foreach (id, entry; a) if (auto res=dg(id, entry, b[id])) return res;
> return 0;
> }
> int opApply(int delegate(ref T, ref T) dg) {
> foreach (id, entry; a) if (auto res=dg(entry, b[id])) return res;
> return 0;
> }
> }
>
> _lockstep!(T) lockstep(T)(T[] a, T[] b) { _lockstep!(T) res; res.a=a; res.b=b; return res; }
>
> void main() {
> foreach (entry1, entry2; lockstep([1, 2, 3], [4, 5, 6]))
> writefln(entry1, " - ", entry2);
> }
>
:)
--downs
More information about the Digitalmars-d
mailing list