Event Callback Framework

Medium C++ Concurrency
Solve this problem

Implement a lightweight event callback framework in C++. The framework allows registering callbacks and dispatching events to all registered handlers.

Constraints

  • Use std::function<void(int)>.
  • Support register() and dispatch().
  • Maximum 8 callbacks.
  • No dynamic allocation.
  • dispatch(v) calls all registered callbacks with v.
Starter codeC++
1#include <functional>2class Event {3public:4    void reg(std::function<void(int)> cb);5    void dispatch(int v);6};