Signal/Slot implementation with a focus on automatic connection handling
- Automatic connection handling
- when a
Signal
orSlot
goes out of scope, the connection is severed - no need to implement an interface or inherit a base class
- when a
- Type-safe
- Header only
- Not thread-safe
- Not reentrant-safe
Slot<std::string> observer([](std::string s) {
std::cout << s << std::endl;
});
Signal<std::string> subject;
subject.connect(observer);
subject.emit("Hello World");
class Button {
public:
Signal<> pressed;
private:
void onMouseButtonDownInsideButtonArea() {
pressed.emit();
}
};
class Popup {
public:
const Slot<> show = Slot<>(this, &Popup::render);
private:
void render() { }
};
Button button;
Popup popup;
button.pressed.connect(popup.show);