title: Arbitrary number of nested-loops?
body: <p>I'm looking to take an arbitrary number of lists (e.g. [2, 1, 4 . . .], [8, 3, ...], . . .) and pick numbers from each list in order to generate all permutations. E.g.:</p>
  
  <p>[2, 8, ...],
  [2, 3, ...],
  [1, 8, ...],
  [1, 3, ...],
  [4, 8, ...],
  [4, 3, ...],
     ...</p>
  
  <p>This is easily accomplished using nested for-loops, but since I'd like to it accept an arbitrary number of lists it seems that the for-loops would have to be hard coded. One for each list. Also, as my program will likely generate many tens of thousands of permutations, I'l like to generate a single permutation at a time (instead of computing them all in one go and storing the result to a vector). Is there a way to accomplish this programatically? </p>
  
  <p>Since the number of lists is know at compile time, I thought maybe I could use template based meta-programming. However that seems clumsy and also doesn't meet the "one at a time" requirement. Any suggestions?</p>