Bug 10845 – std.range.Cycle broken for reference type forward ranges
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-18T04:59:00Z
Last change time
2014-01-25T14:20:52Z
Assigned to
nobody
Creator
peter.alexander.au
Comments
Comment #0 by peter.alexander.au — 2013-08-18T04:59:56Z
import std.stdio;
import std.range;
import std.algorithm;
void main()
{
auto a = inputRangeObject(iota(3).filter!"true");
writeln(a.cycle.take(10));
}
Outputs
[0, 1, 2, 0, 1, 2,
then asserts: http://dpaste.dzfl.pl/84de028d
The problem is Cycle.popFront:
void popFront()
{
_current.popFront();
if (_current.empty) _current = _original;
}
It should be _current = _original.save, otherwise the _original range is consumed on the second iteration.
Comment #1 by monarchdodra — 2013-08-18T05:47:49Z
(In reply to comment #0)
> import std.stdio;
> import std.range;
> import std.algorithm;
>
> void main()
> {
> auto a = inputRangeObject(iota(3).filter!"true");
> writeln(a.cycle.take(10));
> }
>
> Outputs
>
> [0, 1, 2, 0, 1, 2,
>
> then asserts: http://dpaste.dzfl.pl/84de028d
>
> The problem is Cycle.popFront:
>
> void popFront()
> {
> _current.popFront();
> if (_current.empty) _current = _original;
> }
>
> It should be _current = _original.save, otherwise the _original range is
> consumed on the second iteration.
I have an open pull for improving cycle:
https://github.com/D-Programming-Language/phobos/pull/1149
So I integrated the fix in it. That said, given how often my pulls get reviewed and pulled, it might be best if you created a pull for this that _I_ could review and pull...
Comment #2 by github-bugzilla — 2014-01-25T14:15:51Z