carb::delegate::Delegate< void(Args…)>

Defined in carb/delegate/Delegate.h

template<class ...Args>
class Delegate<void(Args...)> : public carb::delegate::detail::DelegateBase<::carb::thread::mutex, detail::DefaultExec, void(Args...)>

Implements a thread-safe callback system that can have multiple subscribers.

A delegate is a weak-coupling callback system. Essentially, a system uses Delegate to have a callback that can be received by multiple subscribers.

Delegate has two ways to uniquely identify a bound callback: Bind() will output a Handle, or the caller can provide a key of any type with BindWithKey(). Either the Handle or the given key can be passed to Unbind() in order to remove a callback.

Delegate can call all bound callbacks with the Call() function. Recursive calling is allowed with caveats listed below.

Delegate is thread-safe for all operations. Call() can occur simultaneously in multiple threads. An Unbind() will wait if the bound callback is currently executing in another thread.

Delegate can be destroyed from a binding (during Call()) as the internal state is not disposed of until all active calls have been completed. See ~Delegate().

Delegate does not hold any internal locks while calling bound callbacks. It is strongly recommended to avoid holding locks when invoking Delegate’s Call() function.

These tenets make up the basis of Carbonite’s Basic Callback Hygiene as described in the Coding Style Guidelines .


This delegate is not recommended for use when called from with a carb.tasking task. Instead, use carb::tasking::Delegate.

Public Functions

Delegate() = default

Constructs an empty delegate.

inline Delegate(Delegate &&other)

Move constructor.


other – The Delegate to move from. This Delegate will be left in a valid but empty state.

inline Delegate &operator=(Delegate &&other)

Move-assign operator.


other – The Delegate to move-assign from. Will be swapped with *this.