For example:
<1,2,3> as an input to the function comb to get combination of 2 elements will output result <<1,2>,<1,3>,<2,3>>, which as input to same function will get
<<<1,2>,<1,3>>,<<1,3>,<2,3>>,<<1,2>,<2,3>>, which as input to the same function will get
….
Logic is the same, only type changes, so it can be made generic.
I tried to write something like this:
template<typename V>
vector<vector<vector<V>::const_iterator>> comb(const vector<V>){
....
while(next_combination(...))
vector<vector<vector<V>::const_iterator>> results;
return results;
}
vector<string> input
comb(comb(comb(input)));
But compiler keep complaining can’t deduce the returning value’s type.
Thanks.
Maybe the following will help:
Note the changes:
combis a vector of vectorscombis notconstbecausenext_combinationchanges itcomb; all that copying seems necessary