Skip to content

Commit

Permalink
Issue 9507: transposed() behaves poorly with jagged range of ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
H. S. Teoh committed Dec 5, 2014
1 parent 6473aef commit 1ddb501
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions std/range/package.d
Expand Up @@ -5025,8 +5025,10 @@ struct Transposed(RangeOfRanges)

@property auto front()
{
import std.algorithm : map;
return map!"a.front"(_input.save);
import std.algorithm : filter, map;
return _input.save
.filter!(a => !a.empty)
.map!(a => a.front);
}

void popFront()
Expand All @@ -5036,8 +5038,11 @@ struct Transposed(RangeOfRanges)
while (!r.empty)
{
auto e = r.front;
e.popFront();
r.front = e;
if (!e.empty)
{
e.popFront();
r.front = e;
}

r.popFront();
}
Expand Down Expand Up @@ -5076,6 +5081,18 @@ private:
assert(transposed(ror).empty);
}

// Issue 9507
unittest
{
import std.algorithm : equal;

auto r = [[1,2], [3], [4,5], [], [6]];
assert(r.transposed.equal!equal([
[1, 3, 4, 6],
[2, 5]
]));
}

/**
Given a range of ranges, returns a range of ranges where the $(I i)'th subrange
contains the $(I i)'th elements of the original subranges.
Expand Down

0 comments on commit 1ddb501

Please sign in to comment.