[Issue 17091] std.range.zip cannot "save" correctly
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Jan 15 09:33:02 PST 2017
https://issues.dlang.org/show_bug.cgi?id=17091
--- Comment #1 from Kazuki Komatsu <enjouzensyou.boinc at gmail.com> ---
(In reply to Kazuki Komatsu from comment #0)
> Following code cannot be done correctly.
> I tested the following code on DMDv2.072.2.
> The line of the 4th `writeln` should output "[Tuple!(int, int)(1, 4),
> Tuple!(int, int)(2, 5), Tuple!(int, int)(3, 6)]".
>
> ----
> import std.range;
> import std.algorithm;
> import std.stdio;
>
> void main()
> {
> auto s1 = [1, 2, 3].inputRangeObject;
> auto s2 = [4, 5, 6].inputRangeObject;
>
> writeln(s1.save); // [1, 2, 3], OK
> writeln(s2.save); // [1, 2, 3], OK
>
> auto added = s1.zip(s2);
> writeln(zs.save); // [Tuple!(int, int)(1, 4), Tuple!(int, int)(2, 5),
> Tuple!(int, int)(3, 6)], OK
> writeln(zs.save); // [], NG
> }
> ----
Sorry, `auto added = s1.zip(s2);` is wrong.
The correct code is following one
--------
import std.range;
import std.algorithm;
import std.stdio;
void main()
{
auto s1 = [1, 2, 3].inputRangeObject;
auto s2 = [4, 5, 6].inputRangeObject;
writeln(s1.save); // [1, 2, 3], OK
writeln(s2.save); // [1, 2, 3], OK
auto zs = s1.zip(s2);
writeln(zs.save); // [Tuple!(int, int)(1, 4), Tuple!(int, int)(2, 5),
Tuple!(int, int)(3, 6)], OK
writeln(zs.save); // [], NG
}
--------
--
More information about the Digitalmars-d-bugs
mailing list