A modern, header-only Event Bus / Observer framework written in C++20, featuring RAII-based subscriptions, strong typing, and a clean API.
This project was built as a learning exercise in modern C++ design, focusing on decoupled architectures commonly used in game engines, tools, and event-driven systems.
- ✅ RAII subscriptions (auto-unsubscribe on destruction)
- ✅ Strongly-typed events
- ✅
subscribe<T>()/publish(T)simple API - ✅ Multiple subscribers per event
- ✅ Thread-safe subscribe / unsubscribe / publish
- ✅ Header-only (easy drop-in)
- ✅ Clean separation between event logic and application code
#include "eventbus/event_bus.hpp"
struct ScoreChanged {
int newScore;
};
eventbus::EventBus bus;
auto sub = bus.subscribe<ScoreChanged>([](const ScoreChanged& e){
std::cout << "Score updated: " << e.newScore << "\n";
});
bus.publish(ScoreChanged{10});
bus.publish<ScoreChanged>(20);
// sub destroyed -> auto unsubscribe
## 🧠 Design Overview
Each event type has its own subscriber list
Subscriptions return a move-only RAII token
Callbacks are stored type-erased internally
publish() copies subscribers under a lock, then invokes callbacks safely
No inheritance or base Event class required
## 🕹 Included Demo
The examples/ folder demonstrates a game-like system with:
score updates
achievements
logging
automatic unsubscribe via scope
## 🔗 Full Version
👉 Download the full project (with complete examples & documentation):
https://gabrielpopovic.gumroad.com/l/uagncm
(This repository acts as a public preview of the project.)
## 🛠 Build & Run Example
Using g++
g++ -std=c++20 -Iinclude examples/main.cpp -o example
./example
Using CMake
cmake -S . -B build
cmake --build build
./build/example
🎯 Use Cases
Game engines (HUD, achievements, audio, logging)
Tooling & editors
Event-driven simulations
Learning modern C++ architecture patterns
📜 License
MIT License
🙌 Feedback Welcome
This project was built as part of my journey learning modern C++.
Suggestions, critiques, and improvements are very welcome!