Bug 15860 – lockstep should support foreach_reverse

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-04-01T15:30:00Z
Last change time
2016-04-26T14:49:37Z
Keywords
pull
Assigned to
petar.p.kirov
Creator
petar.p.kirov

Comments

Comment #0 by petar.p.kirov — 2016-04-01T15:30:10Z
auto arr1 = [1, 2, 3, 4, 5]; auto arr2 = [6, 7, 8, 9, 10]; foreach_reverse (ref a, b; lockstep(arr1, arr2)) a += b; assert (result == [15, 13, 11, 9, 7]); Forum thread: http://forum.dlang.org/post/[email protected]
Comment #1 by simen.kjaras — 2016-04-01T20:19:32Z
Comment #2 by simen.kjaras — 2016-04-07T06:32:26Z
The pull request above adds foreach_reverse without index to any set of bidirectional ranges (but if one or more is not bidirectional, foreach_reverse is of course not possible). Indexed reverse iteration has more requirements: All iterated ranges must have have a length, and the stoppingPolicy must be requireSameLength. Sadly, the latter is a runtime value, so it has to be handled with enforce. I'd have prefered to disallow it at compile-time.
Comment #3 by github-bugzilla — 2016-04-26T14:49:36Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/154b0e9cb8f9b0d93a59faf913006a4b66862bc9 Fix Issue 15860 - lockstep should support foreach_reverse https://github.com/dlang/phobos/commit/23fcb244efbb545485fb5fd8635144340e4193d3 Merge pull request #4138 from Biotronic/fix-15860 Fix Issue 15860 - lockstep should support foreach_reverse