How to iterate all k-subsets of a range in a specific order?
Tommi
tommitissari at hotmail.com
Fri Oct 5 04:22:57 PDT 2012
Uh... never mind. I guess this one was kind of like a magic
trick; the solution was so obvious and simple I neglected it:
void fun(R)(R r)
if (isForwardRange!R)
{
writeln("idx x y");
auto idx = 0;
auto rsaved = r.save;
for (size_t n = 0; !r.empty; r.popFront(), ++n)
{
size_t n2 = 0;
for (auto r2 = rsaved; n2 < n; r2.popFront(), ++n2)
{
writefln("%s : %s %s", idx, r2.front, r.front);
++idx;
}
}
}
More information about the Digitalmars-d-learn
mailing list