Using the gain signal in boost :: bind

I am trying to transfer the start for boost :: signal to boost :: bind object. So I want to trigger a signal with some pre-packaged arguments when calling boost ::.

What I have:

boost::signals2::signal<void(int)> sig; boost::function<void()> f = boost::bind( &(sig.operator()), &sig, 10); 

But that does not work. I get the following error: error: there is no corresponding function to call bind (, ...

I also tried this:

 boost::function<void()> f = boost::bind( (void(boost::signals2::signal<void(int)>::*)(int)) &(sig.operator()), &sig, 10); 

But then I get the "address of the overloaded function without context type information."

So what is the correct syntax for this?

+4
source share
1 answer

The instance boost :: signals2 :: signal is a function object (aka functor) and can be connected directly, as described here . The only problem in this case is that the signal is not copyable, and therefore it cannot be copied to the object returned by bind. So, first you need to wrap it boost :: ref. Here is an example:

 #include <boost/signals2.hpp> #include <boost/bind.hpp> #include <boost/ref.hpp> int main(void) { boost::signals2::signal<void(int)> sig; boost::function<void()> f = boost::bind(boost::ref(sig), 10); } 
+9
source

All Articles