|
Boost Users : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-03-15 12:22:34
On Friday 14 March 2003 09:45 pm, Faheem Mitha wrote:
> Dear People,
>
> I have defined a function as follows.
>
> double accept_prob_fn(const double x, const double be, const double
> theta, const double a, const double
> b);
>
> Now, I define the temporary function object
>
> bind(accept_prob_fn, _1, be, theta, a, b);
>
> So this function object would return the first argument, x. However, I
> want to save this function object to a function object called foo,
> say.
>
> So I want to do something like
>
> Type foo = bind(accept_prob_fn, _1, be, theta, a, b);
>
> However, the problem I have is that I'm not sure what type foo should
> be. I forced an error with my compiler (to try to see what it thought
> the type of the rhs should be) by using Type as double, but all I got
> was
>
> brent.cc:9: cannot convert `boost::_bi::bind_t<double, double
> (*)(double, double, double, double, double),
> boost::_bi::list5<boost::arg<1>, boost::_bi::value<double>,
> boost::_bi::value<double>,
> boost::_bi::value<double>, boost::_bi::value<double> > >' to
> `double' in initialization
>
> Eww.
>
> I've tried looking at the documentation, but I find it pretty much
> incomprehensible. Could someone
>
> a) Tell me what "Type" should be.
The type is "unspecified", may vary from compiler to compiler, and is hideous
on every compiler. For these reasons, it's intentional that you can't name
the type directly (see
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1438.htm, section
IIIB).
However, you can include <boost/function.hpp> and make the Type:
boost::function<double(double x)>
(or, if your compiler isn't up to par, boost::function1<double, double>). See
the Boost.Function documentation for more information about the Function
library.
Doug
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