diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index d1477ca1e1..f96b888e28 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -1844,9 +1844,7 @@ template class StaticCallbackManager { public: /// Add any callable. Small trivially-copyable callables (like [this] lambdas) /// are stored inline without heap allocation. - template void add(F &&callback) { - this->callbacks_.push_back(Callback::create(std::forward(callback))); - } + template void add(F &&callback) { this->add_(Callback::create(std::forward(callback))); } /// Call all callbacks in this manager. void call(Ts... args) { @@ -1859,6 +1857,8 @@ template class StaticCallbackManager { void operator()(Ts... args) { call(args...); } protected: + /// Non-template core to avoid code duplication per lambda type. + void add_(Callback cb) { this->callbacks_.push_back(cb); } StaticVector, N> callbacks_; };