TransverseOptions

Options for the FrontTransversal and Transversal ranges (below).

Values

ValueMeaning
assumeJagged

When transversed, the elements of a range of ranges are assumed to have different lengths (e.g. a jagged array).

enforceNotJagged

The transversal enforces that the elements of a range of ranges have all the same length (e.g. an array of arrays, all having the same length). Checking is done once upon construction of the transversal range.

assumeNotJagged

The transversal assumes, without verifying, that the elements of a range of ranges have all the same length. This option is useful if checking was already done from the outside of the range.

Examples

1 import std.algorithm.comparison : equal;
2 import std.exception : assertThrown;
3 
4 auto arr = [[1, 2], [3, 4, 5]];
5 
6 auto r1 = arr.frontTransversal!(TransverseOptions.assumeJagged);
7 assert(r1.equal([1, 3]));
8 
9 // throws on construction
10 assertThrown!Exception(arr.frontTransversal!(TransverseOptions.enforceNotJagged));
11 
12 auto r2 = arr.frontTransversal!(TransverseOptions.assumeNotJagged);
13 assert(r2.equal([1, 3]));
14 
15 // either assuming or checking for equal lengths makes
16 // the result a random access range
17 assert(r2[0] == 1);
18 static assert(!__traits(compiles, r1[0]));

Meta

Suggestion Box / Bug Report