Skip to content

Commit

Permalink
Revert slot_list_call change
Browse files Browse the repository at this point in the history
Slot entries may remove themself during calling, hence the next
iterator needs to be fetched before calling the current one.
  • Loading branch information
kannibalox committed Dec 14, 2024
1 parent f63dc0a commit f7680d5
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions rak/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,35 @@

namespace rak {

template <typename Container, typename... Args>
template <typename Container>
inline void
slot_list_call(const Container& slot_list, Args&&... args) {
for (const auto& slot : slot_list) {
slot(std::forward<Args>(args)...);
slot_list_call(const Container& slot_list) {
if (slot_list.empty())
return;

typename Container::const_iterator first = slot_list.begin();
typename Container::const_iterator next = slot_list.begin();

while (++next != slot_list.end()) {
(*first)();
first = next;
}

(*first)();
}

template <typename Container, typename Arg1>
inline void
slot_list_call(const Container& slot_list, Arg1 arg1) {
if (slot_list.empty())
return;

typename Container::const_iterator first = slot_list.begin();
typename Container::const_iterator next = slot_list.begin();

while (++next != slot_list.end()) {
(*first)(arg1);
first = next;
}
}

Expand Down

0 comments on commit f7680d5

Please sign in to comment.