29template <
typename... Ts>
30constexpr bool isValueOrLvalueReferenceToConst()
32 return (( (! std::is_reference_v<Ts>)
33 || (std::is_lvalue_reference_v<Ts> && std::is_const_v<std::remove_reference_t<Ts>>)) && ...);
36template <
typename... Args>
37class CallbackListenerList
40 static_assert (isValueOrLvalueReferenceToConst<Args...>(),
41 "CallbackListenerList can only forward values or const lvalue references");
43 using Callback = std::function<void (Args...)>;
45 ErasedScopeGuard addListener (Callback callback)
47 jassert (callback !=
nullptr);
49 const auto it = callbacks.insert (callbacks.end(), std::move (callback));
52 return ErasedScopeGuard { [
this, it]
59 void call (Args... args)
61 listeners.
call ([&] (
auto& l) { l (std::forward<Args> (args)...); });
65 std::list<Callback> callbacks;
66 ListenerList<Callback> listeners;
void call(Callback &&callback)
void add(ListenerClass *listenerToAdd)
void remove(ListenerClass *listenerToRemove)