blob: ffad3c6ce419857dfa260f62e663308428466aaf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#pragma once
template <typename... Args>
class event {
using func_type = std::function<void(Args...)>;
std::mutex event_lock;
std::vector<func_type> m_funcs;
public:
void add(const func_type& func) {
std::lock_guard<std::mutex> lock(event_lock);
m_funcs.emplace_back(func);
}
void call(Args... params) {
std::lock_guard<std::mutex> lock(event_lock);
for (auto& func : m_funcs) {
if (func) func(std::forward<Args>(params)...);
}
}
};
|