As we know that output parameters are really bad thing
void foo(set<int> *x)
Here x is actually expected parameters, this is pretty common practice in Linux system calls. But for c++ this seems not be a good coding practice.
I have a scenario, where i have to backtrack through a list of list of strings, and return all possible combination of strings from each list.
a b
d e
f g
Possible combinations are:
a d f, a d g, a e f, a e g, etc...
list<list<string> > parameters;
A straightforward backtracking solution would be:
void getCombinations(list<list<string> > ¶m,
list<list<string> >::iterator it,
vector<string> &backtracker,
list<vector<string> > &output){
if(it == param.end()){
output.append(backtracker);
}
for(auto i = it->begin; i!= it->end(); i++){
backtracker.push_back(*i);
getCombinations(param, it+1, backtracker, output)
backtracker.pop_back();
}
}
Now, How can i avoid output parameters here, such that i could return the output list?
Output parameters show up all the time in C++. You could however encapsulate the output datastructure with the methods.
My experience is that 95% of the time someone is soapboxing about practices it's personal peevishness. The other 5% of the time it's good good sense.