transposed

Given a range of ranges, returns a range of ranges where the i'th subrange contains the i'th elements of the original subranges.

Transposed!(RangeOfRanges, opt)
transposed
(
RangeOfRanges rr
)
if (
isForwardRange!RangeOfRanges &&
isInputRange!(ElementType!RangeOfRanges)
&&
hasAssignableElements!RangeOfRanges
)

Parameters

opt

Controls the assumptions the function makes about the lengths of the ranges (i.e. jagged or not)

rr RangeOfRanges

Range of ranges

Examples

import std.algorithm.comparison : equal;
int[][] ror = [
    [1, 2, 3],
    [4, 5, 6]
];
auto xp = transposed(ror);
assert(equal!"a.equal(b)"(xp, [
    [1, 4],
    [2, 5],
    [3, 6]
]));
int[][] x = new int[][2];
x[0] = [1, 2];
x[1] = [3, 4];
auto tr = transposed(x);
int[][] witness = [ [ 1, 3 ], [ 2, 4 ] ];
uint i;

foreach (e; tr)
{
    assert(array(e) == witness[i++]);
}

Meta