fix merge

This commit is contained in:
J. Nick Koston
2025-12-19 20:11:21 -10:00
parent 2d6103f0d0
commit df5193ff73

View File

@@ -1008,50 +1008,6 @@ template<typename... Ts> class LazyCallbackManager<void(Ts...)> {
std::unique_ptr<CallbackManager<void(Ts...)>> callbacks_;
};
template<typename... X> class LazyCallbackManager;
/** Lazy-allocating callback manager that only allocates memory when callbacks are registered.
*
* This is a drop-in replacement for CallbackManager that saves memory when no callbacks
* are registered (common case after the Controller Registry eliminated per-entity callbacks
* from API and web_server components).
*
* Memory overhead comparison (32-bit systems):
* - CallbackManager: 12 bytes (empty std::vector)
* - LazyCallbackManager: 4 bytes (nullptr unique_ptr)
*
* @tparam Ts The arguments for the callbacks, wrapped in void().
*/
template<typename... Ts> class LazyCallbackManager<void(Ts...)> {
public:
/// Add a callback to the list. Allocates the underlying CallbackManager on first use.
void add(std::function<void(Ts...)> &&callback) {
if (!this->callbacks_) {
this->callbacks_ = make_unique<CallbackManager<void(Ts...)>>();
}
this->callbacks_->add(std::move(callback));
}
/// Call all callbacks in this manager. No-op if no callbacks registered.
void call(Ts... args) {
if (this->callbacks_) {
this->callbacks_->call(args...);
}
}
/// Return the number of registered callbacks.
size_t size() const { return this->callbacks_ ? this->callbacks_->size() : 0; }
/// Check if any callbacks are registered.
bool empty() const { return !this->callbacks_ || this->callbacks_->size() == 0; }
/// Call all callbacks in this manager.
void operator()(Ts... args) { this->call(args...); }
protected:
std::unique_ptr<CallbackManager<void(Ts...)>> callbacks_;
};
/// Helper class to deduplicate items in a series of values.
template<typename T> class Deduplicator {
public: