If you pass a jagged range of ranges to std.range.transposed, once one of the subranges is consumed, .front will cause an invalid access to the empty subrange's .front, causing a runtime error. However, the returned range's .empty will still be false, even though you can't safely use .front anymore! So std.range.transposed should either return empty if *any* of its ranges are empty, or else, its .front should be modified so that empty subranges will be skipped over (or should there be an option to specify a default element?).
(In reply to comment #0) > If you pass a jagged range of ranges to std.range.transposed, once one of the > subranges is consumed, .front will cause an invalid access to the empty > subrange's .front, causing a runtime error. > > However, the returned range's .empty will still be false, even though you can't > safely use .front anymore! > > So std.range.transposed should either return empty if *any* of its ranges are > empty, or else, its .front should be modified so that empty subranges will be > skipped over (or should there be an option to specify a default element?). This shows some usages the stadard Haskell function transpose, I'd like the D version to do something similar. No need for a default element: Prelude> import Data.List (transpose) Prelude Data.List> transpose [[1,2,3],[4,5,6],[7,8,9]] [[1,4,7],[2,5,8],[3,6,9]] Prelude Data.List> let a = [[7,4,2,8,7],[8,0,8],[3],[1,6,0,7,7,2,0],[8,9,3,1],[6],[6]] Prelude Data.List> transpose a [[7,8,3,1,8,6,6],[4,0,6,9],[2,8,0,3],[8,7,1],[7,7],[2],[0]] Prelude Data.List> transpose [[1],[],[3,4]] [[1,3],[4]]
https://github.com/D-Programming-Language/phobos/pull/2786
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/1ddb5010b642ff729e0dcad104b1ee60fb1e9afa Issue 9507: transposed() behaves poorly with jagged range of ranges https://github.com/D-Programming-Language/phobos/commit/a58fb70753483eae56cee997aa9befb14ac9b0bb Merge pull request #2786 from quickfur/issue9507 Issue 9507: transposed() behaves poorly with jagged range of ranges
Commits pushed to 2.067 at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/1ddb5010b642ff729e0dcad104b1ee60fb1e9afa Issue 9507: transposed() behaves poorly with jagged range of ranges https://github.com/D-Programming-Language/phobos/commit/a58fb70753483eae56cee997aa9befb14ac9b0bb Merge pull request #2786 from quickfur/issue9507