Bug 17952 – std.range.transposed save is invalid

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2017-10-30T16:00:26Z
Last change time
2017-12-18T22:56:09Z
Assigned to
Alexandru Razvan Caciulescu
Creator
Steven Schveighoffer
See also
https://issues.dlang.org/show_bug.cgi?id=13041

Comments

Comment #0 by schveiguy — 2017-10-30T16:00:26Z
auto x = [[1,2,3],[4,5,6]].transposed; auto y = x.save; assert(x.equal([[1,4],[2,5],[3,6]])); y.popFront; assert(x.equal([[1,4],[2,5],[3,6]])); // FAILS, x is really [[2,5],[3,6]] The only way .save can truly be implemented is by duplicating the RangeOfRanges range, and there is no standard for doing this (.dup is not consistent across ranges). We have 2 options: 1. Deprecate .save (i.e. make transposed NOT a forward range) 2. convert the RangeOfRanges element to an array, and duplicate on every .save. Neither option is particularly good. My vote would be for option 1.
Comment #1 by schveiguy — 2017-10-30T17:50:53Z
Scratch that, x is not really [[2,5],[3,6]], it's an empty range! Just using equals destroys it. transposed clearly isn't even close to a forward range.
Comment #2 by schveiguy — 2017-10-30T17:54:13Z
To ensure this test case is checking the right issue, change the third line to: assert(y.equal([[1,4],[2,5],[3,6]])); And get rid of the y.popFront. Clearly, we should be able to iterate y without iterating x. But that's not what happens (consuming any saved range consumes them all).
Comment #3 by github-bugzilla — 2017-11-01T18:57:15Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/cd55be3311cee1ab9a0dbcb5fc4ef56374b9c7aa Fix Issue 17952 - std.range.transposed save is invalid https://github.com/dlang/phobos/commit/fec4b60ce6003c311bdb8e348d42be825d0625fa Merge pull request #5832 from Darredevil/issue-17952-transposed-save Fix Issue 17952 - std.range.transposed save is invalid merged-on-behalf-of: Andrei Alexandrescu <[email protected]>
Comment #4 by github-bugzilla — 2017-12-18T22:56:09Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/cd55be3311cee1ab9a0dbcb5fc4ef56374b9c7aa Fix Issue 17952 - std.range.transposed save is invalid https://github.com/dlang/phobos/commit/fec4b60ce6003c311bdb8e348d42be825d0625fa Merge pull request #5832 from Darredevil/issue-17952-transposed-save