Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-05-30 10:28:17


Darren Vincent Hart wrote:
[...]
> struct widget
> {
> boost::signal<bool ()> sig;
> boost::signal<bool (char)> keypress;
> bool test()
> {
> cout << "widget::test() - sig empty: " << (sig.empty() ? "true" :
> "false") << endl;
> sig();
> return true;
> }
> };
[...]
> // bind to a widget signal handler, BROKEN
> //handler<bool> handler_b( boost::bind<bool>(&widget::sig, &widget_a)
> ); // <-- Broken
[...]
> // store the function object returned by binding a widget signal,
> BROKEN
> //boost::function<bool ()> fp = boost::bind(&widget::sig, &widget_a);
> // <-- BROKEN
>
> // executre the functor returned by binding a widget signal, BROKEN
> // (builds, but doesn't really call widget_a.sig())
> boost::bind(&widget::sig, &widget_a)(); // <-- Test if binding works
> at all, it doesn't

bind(&widget::sig, &widget_a)() gets you a reference to widget_a->sig since
&widget::sig is a data member. You still need to call it.

bool call(signal<bool()> const & s) { return s(); }

bind(call, bind(&widget::sig, &widget_a)) ();

will probably do what you want.

You can use apply<> from <boost/bind/apply.hpp> instead of 'call':

bind(apply<bool>(), bind(&widget::sig, &widget_a)) (); // should call
widget_a->sig

HTH


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