D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13041 - std.range.transposed consumes sub-ranges
Summary: std.range.transposed consumes sub-ranges
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
: 13824 (view as issue list)
Depends on:
Blocks:
 
Reported: 2014-07-04 14:13 UTC by bearophile_hugs
Modified: 2017-11-02 13:24 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2014-07-04 14:13:02 UTC
void main() {
    import std.stdio, std.algorithm, std.range;
    auto M = [[[1, 2]], [[3, 4]]];
    M.filter!(r => r.dup.transposed.walkLength).writeln;
    M.filter!(r => r.transposed.walkLength).writeln;
}


Output with dmd 2.066beta:
[[[1, 2]], [[3, 4]]]
[[[]], [[]]]

I expected:
[[[1, 2]], [[3, 4]]]
[[[1, 2]], [[3, 4]]]
Comment 1 Peter Alexander 2015-01-02 21:40:17 UTC
*** Issue 13824 has been marked as a duplicate of this issue. ***
Comment 2 Steven Schveighoffer 2017-11-01 20:46:54 UTC
Given how issue 17952 was resolved (we deprecated transposed being a forward range, as it would require dup'ing per save), I think we can close this as WONTFIX.

Once Transposed.save is removed, we can update the docs to reflect that transposed may consume sub-ranges. I think this is just in the nature of transposed and how forward ranges are stored.
Comment 3 hsteoh 2017-11-01 21:22:28 UTC
I wonder if there's any possibility of implementing .save for a random-access range, if the subranges are also random-access.

In this case, we wouldn't need to consume the subranges at all, but can simply store a set of current indices to implement .transposed.
Comment 4 Steven Schveighoffer 2017-11-02 13:24:31 UTC
It certainly is possible. Note there is current work to update Transposed to use transverse to allow indexing https://github.com/dlang/phobos/pull/5805.

I think we can go further building upon transverse, and its related option on how to treat the data.

But it would be a strange relationship between transposed and its subranges. If the subranges were indexable, then Transposed can be a forward range, otherwise it can't. Seems unintuitive, and not sure it's worth all the effort.

In other cases as well (if, for instance, the RangeOfRanges stores everything by value), then save could also be implemented. We may have a hard time detecting this because the relationship between Transposed and whether it's valid to make a copy is confusing and not well-established.