Ctor to generate all possible combinations of array indices for a length r array. This is a special-case optimization and is faster than simply using the other ctor to generate all length r combinations from seq(0, length).
General ctor. array is a sequence from which to generate the * combinations. r is the length of the combinations to be generated.
Advances to the next combination. The array returned by front will be overwritten with the new results.
Gets the current combination.
Only supports iterating over up to size_t.max combinations. This was a conscious tradeoff to allow this range to have a length of type size_t, since iterating over such huge combination spaces would be insanely slow anyhow.
auto comb1 = map!"a.dup"(Comb!(uint)(5, 2)); uint[][] vals; foreach(c; comb1) { vals ~= c; } auto sorted = sort(vals); assert(sorted.canFind([0u,1])); assert(sorted.canFind([0u,2])); assert(sorted.canFind([0u,3])); assert(sorted.canFind([0u,4])); assert(sorted.canFind([1u,2])); assert(sorted.canFind([1u,3])); assert(sorted.canFind([1u,4])); assert(sorted.canFind([2u,3])); assert(sorted.canFind([2u,4])); assert(sorted.canFind([3u,4])); assert(sorted.length == 10);
Generates every possible combination of r elements of the given sequence, or array indices from zero to N, depending on which c'tor is called. Uses an input range interface.
Note: The buffer that is returned by front is recycled across iterations. To duplicate it instead, use map!"a.dup" or map!"a.idup".