Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-01-09 07:06:27


Will wrote:
> Hi, I'm looking for a general technique for binding signals with
> varying signatures together.
> Obviously i can create custom functions for any specific case, but i'm
> wondering if boost::bind could be used to help out here?
>
> i.e.
>
> boost::signal1<void, const char *> sig1;
> boost::signal0<void> sig2;
>
> void bing() {
> std::cout << "bing" << std::endl;
> }
>
> // connect sig1 to sig2 such that calling sig1 will invoke sig2
> // ... <- how do i do this?
>
> // connect sig2 to some function
> sig2.connect(&bing);

    sig1.connect( boost::bind( boost::ref( sig2 ) ) );

should work. In general, boost::bind( f, a1, a2... ) will call f( a1,
a2... ), so bind( f ) will simply call f(); the argument will be ignored
(because there is no _1 in the bound argument list).

Another (clearer) example of bind ignoring an input argument is bind( f,
_2 ), which only passes the second argument and ignores the first.

The ref() is needed since sig2 is noncopyable.

> // call the signal
> sig1("some string");


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