enumerate all combinations in c++
- by BCS
My question is similar to this combinations question but in my case I have N (N 4) small sets (1-2 items per set for now might go to 3 maybe 4) and want to generate each combination of one item from each set.
The current solution looks somethinging along the lines of this
for(T:: iterator a = setA.begin(); a != setA.end(); ++a)
for(T:: iterator b = setB.begin(); b != setB.end(); ++b)
for(T:: iterator c = setC.begin(); c != setC.end(); ++c)
for(T:: iterator d = setD.begin(); d != setD.end(); ++d)
for(T:: iterator e = setE.begin(); e != setE.end(); ++e)
something(*a,*b,*c,*d,*e);
Simple, effective, probably reasonably efficient, but ugly and not very extensible. Does anyone know of a better/cleaner way to do this?