Create Combinations from Vectors

Hello all,

I am new to C++ programming and have an interesting question that I can't seem to find answered anywhere. I apologize if this is not in the correct sub-forum. Here goes:

I'm trying to write a function that forms all possible combinations of elements from multiple vectors all nested inside one vector. It's hard to explain in words, so this is what I'm talking about:

vector (a, b)
vector (c, d)

And a call to the function should result in:

vector (a, c)
vector (a, d)
vector (b, c)
vector (b, d)

In this case, a, b, c, & d are variable names (which happen to be vectors of int) and the vectors containing them are all uniform length (2 in this example), but their type is not really relevant here. I've been trying to translate some Python code that accomplishes this task, but uses strings in a list instead of vectors in a vector, but I can't change it over correctly because it uses string concatenation.

The Python code is:
def fr(args):
  if not args:
    return [""]
  r = []
  for i in args[0]:
    for tmp in fr(args[1:]):
      r.append(i + tmp)
  return r

where args is a list of strings of uniform length and r & tmp are other lists that store the same.

Please note that the vectors inside the outer vector are always of uniform size and the function does not need to be recursive as the Python one is.
Essentially, I'm trying to be able to run this:

std::vector<std::vector<T> > data;
// data is initialized and used
std::vector<std::vector<T> > combos = make_combos(data);

Any and all information would be highly appreciated!
Topic archived. No new replies allowed.