[Issue 15357] Cannot call std.algorithm.iteration.each on the result of std.range.lockstep

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Nov 18 19:09:09 PST 2015


https://issues.dlang.org/show_bug.cgi?id=15357

ryan at rcorre.net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ryan at rcorre.net

--- Comment #4 from ryan at rcorre.net ---
I think each should mirror the behavior of foreach.
Give it a range that returns one element, and the first variable is interpreted
as an index. Give it a range that returns two elements, and each variable is
one of those elements.

unittest {
  import std.range, std.algorithm, std.stdio;

  auto a = [ 'a', 'b', 'c' ];
  auto b = [ 'd', 'e', 'f' ];

  // print each character with an index
  foreach(i, c ; a) writeln(i, " : ", c);
  a.each!((i, c) => writeln(i, " : ", c));

  // print pairs of characters
  foreach(c1, c2 ; a.lockstep(b)) writeln(c1, " : ", c2);
  a.lockstep(b).each!((c1, c2) => writeln(c1, " : ", c2));
}

--


More information about the Digitalmars-d-bugs mailing list