Boost logo

Boost Users :

Subject: [Boost-users] [lambda] smart self binding of a function object
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-05-11 09:34:15


sorry for double posting, the first message had the wrong subject
[lamda] instead of [lambda].

On May 11, 3:11 am, alfC <alfredo.cor..._at_[hidden]> wrote:
> 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<double(double)> 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<double(double)> operator()(double x_value, YYYY y_arg){
>    return bind(
>          &f::operator(), //maybe needs cast to double(*)
> (double,double)
>          *this,
>          x_value,
>          y_arg
>    );
>  }
>  function<double(double)> 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);
>
> Thank you,
> Alfredo
> answers using other libraries are also accepted :)
> _______________________________________________
> Boost-users mailing list
> Boost-us..._at_[hidden]http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> --
> Sie haben diese Nachricht erhalten, da Sie der Google Groups-Gruppe Boost Users beigetreten sind.
> Wenn Sie Nachrichten in dieser Gruppe posten möchten, senden Sie eine E-Mail an boostusers_at_googlegroups.com.
> Wenn Sie aus dieser Gruppe austreten möchten, senden Sie eine E-Mail an boostusers+unsubscribe_at_googlegroups.com.
> Besuchen Sie die Gruppe unterhttp://groups.google.com/group/boostusers?hl=de, um weitere Optionen zu erhalten.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net