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:
parent
d024c588db
commit
a3c602407f
@ -106,9 +106,14 @@ namespace util {
|
|||||||
|
|
||||||
/// Execute all callbacks, ignoring the return parameters. Does not combine results.
|
/// Execute all callbacks, ignoring the return parameters. Does not combine results.
|
||||||
void operator () (Args... tail) {
|
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.
|
// Increment before we execute so that the caller is able to deregister during execution.
|
||||||
auto current = i++;
|
auto current = i++;
|
||||||
|
looping = m_children.cend () != i;
|
||||||
|
|
||||||
(*current)(tail...);
|
(*current)(tail...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user