Hello I have a function which signature is
std::string f(double x, double param1, double param2, double param3);
I would like to call it on a std::vector xvalues for the parameter x using something like std::transform for a particular value of param1, param2 and param3.
It would be the equivalent of:
double param1(1.);
double param2(1.1);
double param3(1.2);
std::vector<std::string> results();
for (std::vector<double>::const_iterator it = xvalues.begin() ; it != xvalues.end() ; ++xvalues)
{
results.push_back(f(*it, param1, param2, param3);
}
How can this be done in a more elegant manner ?
Kind regards
Tony
You should look into boost::bind which will allow you, as the name indicates, to ‘bind’ arguments to your function
f:The result of this bind is an unary function (
_1being a placeholder for the argument which it should be called with) : all other parameters will have fixed valuesparam1,param2,param3.