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.
1 auto comb1 = map!"a.dup"(Comb!(uint)(5, 2)); 2 uint[][] vals; 3 foreach(c; comb1) { 4 vals ~= c; 5 } 6 auto sorted = sort(vals); 7 assert(sorted.canFind([0u,1])); 8 assert(sorted.canFind([0u,2])); 9 assert(sorted.canFind([0u,3])); 10 assert(sorted.canFind([0u,4])); 11 assert(sorted.canFind([1u,2])); 12 assert(sorted.canFind([1u,3])); 13 assert(sorted.canFind([1u,4])); 14 assert(sorted.canFind([2u,3])); 15 assert(sorted.canFind([2u,4])); 16 assert(sorted.canFind([3u,4])); 17 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".