There is an excellent C++ solution (actually 2 solutions: a recursive and a non-recursive), to a Cartesian Product of a vector of integer vectors. For purposes of illustration/simplicity, let us just focus on the non-recursive version.
My question is, how can one generalize this code with templates to take a std::tuple
of homogeneous vectors that looks like this:
{{2,5,9},{"foo","bar"}}
and generate a homogeneous vector of tuple
{{2,"foo"},{2,"bar"},{5,"foo"},{5,"bar"},{9,"foo"},{9,"bar"}}
If it makes life any easier, let us assume that the internal vectors in the input are each homogeneous. So inputs like this are not allowed: {{5,"baz"}{'c',-2}}
EDIT changed input from jagged vector to a tuple
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…