Passing signals as functions
Hi, I have a signal boost::signal<void ()> foo that I would like to pass to a function taking a function<void ()>. Currently, I pass the pointer to a helper function that calls foo(), but I suspect there's an easier way. Same goes for the more advanced case, where i have a signal boost::signal<void (Bar)> foo which i would like to the same function (taking a function<void ()>), after binding the signal parameter to a specific value. Does anyone know how to do this as well? thanks, Remko
I have a signal boost::signal<void ()> foo that I would like to pass to a function taking a function<void ()>. Currently, I pass the pointer to a helper function that calls foo(), but I suspect there's an easier way.
Same goes for the more advanced case, where i have a signal boost::signal<void (Bar)> foo which i would like to the same function (taking a function<void ()>), after binding the signal parameter to a specific value. Does anyone know how to do this as well?
You could define the function as a template that takes "callable" parameter, then pass either boost::function or boost::signal (or a binder with that signal). template<typename Callable> func(Callable callable) { callable(); }
Hi Igor,
You could define the function as a template that takes "callable" parameter, then pass either boost::function or boost::signal (or a binder with that signal).
The problem is that the function taking the function parameter is a pure virtual, so I can't really use a template function, can I? cheers, Remko
participants (2)
-
Igor R
-
Remko Tronçon