Problem
I have a function double subs(std::function<double(double)> func), and I want to wrap it in a new function that looks like this
template<typename... Args> double subsWrap(std::function<double(Args... args)> func)
that applies subs to some function that takes more inputs as
subs( subs( subs( ... func(...) ) ) )
with each subs applied to only one of the arguments of func at a time.
Minimal example
Let's say that we have a function
auto subs = [] (std::function<double(double)> func){return func(2) + func(5.3);};
and we want to apply it to
auto f2=[](double x, double y){return std::sin(x*std::exp(x/y)); };
as
subs( [&f2](double y){ return subs( [&y,&f2](double x){ return f2(x,y); } ); } )
For f2, this is easy, so there is no need for a wrapper. However, if we want to do the same thing for a function of a greater number of arguments (e.g. double(double,double,double,double,double)) things start to become complicated.
There has to be a way to do this automatically, but I am not even sure how to start.