
On Tue, May 11, 2010 at 4:11 AM, alfC
Hi,
I usually have function-classes that take two arguments.
class f{ double operator()(double x, double y) const { x*y+y; } };
called as:
f myf; cout << myf(4.,3.);
for some purposes I need a function of only one variable (parametrized in the first or second argument. So I end up doing:
using boost::function; using namespace boost::lambda; function
myf_at5 = bind(&f::operator(), myf, 5., _1); // myf_at5 is myf(5.,*) So, now I can pass myf_at5 to something that accepts a function of one variable.
root_finder( myf_at5, ...);
since I have access to f I would like to make f smart enough to handle its own binding. Eg.
class f{ ... // same as before function
operator()(double x_value, YYYY y_arg){ return bind( &f::operator(), //maybe needs cast to double(*) (double,double) *this, x_value, y_arg ); } function operator()(XXXX x_arg, double y_value){ return bind( &f::operator(), //maybe needs cast *this, x_arg, y_value ); } }; The question is: What should be the type of XXXX and YYYY?
in such a way that I can just call
root_finder( myf(5., _1) , ... ); or more complicated things like root_finder( myf(5., _1 * 2.), ...);
in other words, myf(5.,_1) is the same as the old bind(&f::operator(), myf, 5., _1);
The way I would do this would be Boost.Phoenix, rewrite your f like (I
am not making this fully generic, although it would be easy to do,
just keeping it as doubles):
class f_impl{
template