Possible Duplicate:
Which C++ signals/slots library should I choose?
I've been using boost signals/signals 2 for a while to allow event hookups/function dispatching.
It works fine but I have two issues with it.
-This is the more minor one, but handling disconnects can be a pain. I use the trackable class to help with this, but it doesn't solve everything. Having to keep track of the connection if I want to disconnect the signal at an arbitrary time is a bit of nuisance as well
-This is the bigger one. There's no way to copy the signals, meaning I need to implement a copy constructor every time I add a signal to a class, and if I do copy the class, it will no longer have any events hooked up. The obvious solution is to make the held Signal a pointer, then it's copyable and shareable, but this feels dirty and of bad form.
Given the above I started looking for alternatives, but the above issues seem common to signal libraries. I was wondering if anyone had suggestions of getting around the above problems; perhaps a way to deal with them directly.
I was also considering going back to my original solution before I started using boost signals. Something like this:
boost::unordered_map<std::string, boost::function>
the boost::function will take the place of slots/callbacks, then I add a Dispatch function to the class holding this map that will loop trough and call each boost::function. With this approach, I can remove callbacks easily at anytime, and I can copy the map. I was told this wasn't a good way to do it, but looking at it now, I can't really see the problem here.
Further, now that there's variadic templates, it should be an easy task to make a small class around this map to deal with the Dispatch/Add/Remove callbacks calls to the map.
Is this a bad approach?