Bug 23453 – Generic iota should be a forward range

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-11-03T11:57:48Z
Last change time
2022-11-04T08:13:29Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2022-11-03T11:57:48Z
As of Phobos v2.100.2, the generic version of std.range.iota used for non-numeric types is not a forward range, because it does not implement the `save` method: --- import std.range; void main() { auto r1 = iota('a', 'z'); auto r2 = r1.save; // Error } --- However, iota stores all of its state internally, and copies of it can be iterated independently: --- import std.range; void main() { auto r1 = iota('a', 'z'); auto r2 = r1; r1.popFront; assert(r2.front == 'a'); // OK } --- Since it is already effectively a forward range in practice, iota should implement `save` and make this functionality available to generic algorithms.
Comment #1 by dlang-bot — 2022-11-03T18:40:52Z
@pbackus created dlang/phobos pull request #8619 "Fix 23453 - Generic iota should be a forward range" fixing this issue: - Fix 23453 - Generic iota should be a forward range https://github.com/dlang/phobos/pull/8619
Comment #2 by dlang-bot — 2022-11-04T08:13:29Z
dlang/phobos pull request #8619 "Fix 23453 - Generic iota should be a forward range" was merged into master: - be1dad3480b652f125c4d59fa5b3fb3bce4c5ec4 by Paul Backus: Fix 23453 - Generic iota should be a forward range https://github.com/dlang/phobos/pull/8619