How would you implement multicast for TR1 functors? I have my callback slots implemented like
void setCallback(std::tr1::function<void (std::string)> cb)
{
this->callback = cb;
}
but need to pass more than one callback in one of them. I don't want to go into more complex solutions like observer, as this is the only case I need multicast so far. I also cannot use Boost.Signals (as suggested here), because I cannot use Boost. I don't need to explicitly handle disabling callback when subscriber no longer exist.
Put them in a list / vector. If you have to remove them individually you have to wrap them some how (because they are not comparable).
Have a sequence of them rather than a single function (i.e. a
vector<...>
), and when calling back, iterate over the sequence and call.e.g
You most likely want:
with
callbacks
a container (whichever you like) ofstd::tr1::function
objects instead of a single one. When dispatching, iterate over the callbacks.Also, if you want to be able to remove callbacks later, you can do something along these lines: