Boost logo

Boost Users :

Subject: Re: [Boost-users] Passing signals as functions
From: Igor R (boost.lists_at_[hidden])
Date: 2008-12-30 16:26:04


> 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();
}


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