I have a bunch of functions with input x
and y
. I allow input type to be either pass by reference (if it is already there) and pass by temporary input (using &&) (if not exist and need to create a temporary object).
Basically, I define and overload functions as follow
double foo(const std:::vector<int> & x, const std:::vector<int> & y){
// Do something
}
double foo(const std:::vector<int> & x,std:::vector<int>&& y){
// Do something
}
double foo(std:::vector<int>&& x,const std:::vector<int> & y){
// Do something
}
double foo(std:::vector<int>&& x,std:::vector<int>&& y){
// Do something
}
//Do something
is exactly the same but the only difference is the input type. Is there a way I can simplify the code without too much redundancy? I do not want to have foo(std:::vector<int> x,std:::vector<int> y)
for memory issue.
Aucun commentaire:
Enregistrer un commentaire