D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15860 - lockstep should support foreach_reverse
Summary: lockstep should support foreach_reverse
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: ZombineDev
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2016-04-01 15:30 UTC by ZombineDev
Modified: 2016-04-26 14:49 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ZombineDev 2016-04-01 15:30:10 UTC
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/lgqnssnayocvxdjpqkns@forum.dlang.org
Comment 1 Simen Kjaeraas 2016-04-01 20:19:32 UTC
Fixed in PR 4138:
https://github.com/D-Programming-Language/phobos/pull/4138
Comment 2 Simen Kjaeraas 2016-04-07 06:32:26 UTC
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 github-bugzilla 2016-04-26 14:49:36 UTC
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