30 _entries.push_back(std::make_unique<Entry>(Entry{.Id =
id, .Item = std::move(
item)}));
45 const auto it = Locate(
id);
46 if (
it == _entries.end() || (*it)->Removed)
52 if (_dispatchDepth > 0)
55 (*it)->Removed =
true;
67 if (_dispatchDepth == 0)
72 for (
auto&
entry : _entries)
74 entry->Removed =
true;
78 bool Empty()
const {
return _live == 0; }
80 size_t Size()
const {
return _live; }
85 const auto it = Locate(
id);
86 return it != _entries.end() && !(*it)->Removed ? &(*it)->Item :
nullptr;
93 const size_t count = _entries.size();
99 DispatchScope
scope{*
this};
103 Entry&
entry = *_entries[
i];
114 DispatchIf([](
const T&) {
return true; }, std::forward<decltype(fn)>(
fn));
122 bool Removed =
false;
128 explicit DispatchScope(CallbackRegistry&
registry) : Registry(
registry) { ++Registry._dispatchDepth; }
132 if (--Registry._dispatchDepth == 0 && Registry._entries.size() != Registry._live)
134 std::erase_if(Registry._entries, [](
const auto&
entry) { return entry->Removed; });
137 DispatchScope(
const DispatchScope&) =
delete;
138 DispatchScope& operator=(
const DispatchScope&) =
delete;
140 CallbackRegistry& Registry;
146 const auto it = std::ranges::lower_bound(_entries,
id, {}, [](
const auto&
entry) {
return entry->Id; });
147 return it != _entries.end() && (*it)->Id ==
id ?
it : _entries.end();
150 std::vector<std::unique_ptr<Entry>> _entries;
152 int _dispatchDepth = 0;