Store loop conditions before dispatching signal

If we store the loop condition before executing the functor we have a
better chance of avoiding iterator invalidation from any trickery on the
subscriber side.
This commit is contained in:
Danny Robson 2011-09-16 22:57:25 +10:00
parent d024c588db
commit a3c602407f

View File

@ -106,9 +106,14 @@ namespace util {
/// Execute all callbacks, ignoring the return parameters. Does not combine results.
void operator () (Args... tail) {
for (auto i = m_children.cbegin (); i != m_children.cend (); ) {
auto i = m_children.cbegin ();
bool looping = m_children.cend () != i;
while (looping) {
// Increment before we execute so that the caller is able to deregister during execution.
auto current = i++;
looping = m_children.cend () != i;
(*current)(tail...);
}
}