[signals2, bind] connecting a slot with unrelated signature

Hello, Lets assume we've got an arbitrary signal that we don't know it's exact signature, and a function we'd like to connect as a slot. The function ignores all the signal arguments: void callback() { std::cout << "kuku" << std::endl; } int main() { signals2::signal<void(int, double, int)> sig; sig.connect(boost::bind(callback)); sig(); } The above compiles and works. Now I'd like not just to ignore signal's args, but to pass my own param: void callback(int cookie) { std::cout << cookie << std::endl; } int main() { signals2::signal<void(int, double, int)> sig; // I'd like to bind cookie=5 and to connect such a binder to the signal. // Is this possible without defining "manual" functors? sig.connect(???); sig(); }

It turns out that the simple nested binds with protect() solve this. Sorry for the noise.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 06 August 2009, Igor R wrote:
It turns out that the simple nested binds with protect() solve this.
Why do you need nested binds? Doesn't this work?: #include <boost/signals2/signal.hpp> #include <iostream> using namespace boost; void callback(int cookie) { std::cout << cookie << std::endl; } int main() { signals2::signal<void(int, double, int)> sig; // I'd like to bind cookie=5 and to connect such a binder to the signal. sig.connect(bind(&callback, 5)); sig(1, 2.2, 3); return 0; } -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkp7LBwACgkQ5vihyNWuA4UWVgCfcn2/dm5odcy7NvR80IDx1dps U3IAnj+DTRbr6W4jLi+lqY+6GwyqraRO =4rtH -----END PGP SIGNATURE-----

Why do you need nested binds? Doesn't this work?: <...> sig.connect(bind(&callback, 5));
Actually, my question arose because the above line failed to compile. But when I re-check it now, it compiles as expected. I was probably hallucinating... Sorry.
participants (2)
-
Frank Mori Hess
-
Igor R