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
Fixed in PR 4138: https://github.com/D-Programming-Language/phobos/pull/4138
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.
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