add observer_handler class

This commit is contained in:
MihailRis
2025-04-02 14:55:53 +03:00
parent b3feb5945b
commit 3beafe953f
6 changed files with 72 additions and 13 deletions
+4 -4
View File
@@ -7,6 +7,7 @@
#include "delegates.hpp"
#include "typedefs.hpp"
#include "util/observer_handler.hpp"
namespace util {
template <class... Types>
@@ -35,13 +36,12 @@ namespace util {
int id = nextid++;
handlers[id] = std::move(handler);
order.push_back(id);
return observer_handler(new int(id), [this](int* id) { //-V508
return observer_handler([this, id]() {
std::lock_guard lock(mutex);
handlers.erase(*id);
handlers.erase(id);
order.erase(
std::remove(order.begin(), order.end(), *id), order.end()
std::remove(order.begin(), order.end(), id), order.end()
);
delete id;
});
}