I want to generate combination of vectors of a vectors of vectors. For ex: if
std::vector<std::vector<int>> arr = {{1,2},{1,3},{1,4},{1,5}}
Comb(arr, 2) shall return:
{
{{1,2},{1,3}},{{1,2},{1,4}}, {{1,2},{1,5}}, {{1,3},{1,4}}, {{1,3},{1,5}}, {{1,4},{1,5}}
}
(i.e, considering vectors as objects that needs to be combinated)
The code below does combinations for integers, I beleive I can get what I need by modifying this code: for ex. by starting to change type of function to vector<vector<vector> since we have to return vector of vector of vectors.
Thanks everyone that shows interest in this question.
std::vector<std::vector<int>> Combinations::combs(int n, int r) {
std::vector<bool> v(n);
std::fill(v.end() - r, v.end(), true);
std::vector<std::vector<int>> sol;
do {
std::vector<int> row;
for (int i = 0; i < n; ++i) {
if (v[i]) {
row.push_back(i+1);
}
}
sol.push_back(row);
} while (std::next_permutation(v.begin(), v.end()));
return sol;
}