Iterating over multiple collections in parallel
Walter Bright
newshound1 at digitalmars.com
Sat Jul 5 11:55:23 PDT 2008
Koroskin Denis wrote:
> I spend a lot of time on this and have found no solution how to do it
> with existing D feature set, but this is surely doable with a few
> inter-function gotos and an exception if collections sizes don't match.
It's a well-known problem, and not so easy to solve in an intuitive,
non-klunky way. Some of the issues are what do you do when the
collections are of different sizes? Error? Iterate to the minimum?
Iterate to the maximum and use default values for the shorter collections?
The best I can offer at the moment is:
foreach (i; 0 .. a.length)
a[i] = b[i] + c[i];
More information about the Digitalmars-d
mailing list