From 61e2b2b6eb3965b2bb3281fd0c7558710613fe90 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 26 Oct 2025 18:03:26 -0500 Subject: [PATCH] remove --- esphome/core/automation.h | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/esphome/core/automation.h b/esphome/core/automation.h index 5787373cbc..0512752d50 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -27,20 +27,11 @@ template class TemplatableValue { public: TemplatableValue() : type_(NONE) {} - template TemplatableValue(F value) requires(!std::invocable) : type_(VALUE) { + template::value, int> = 0> TemplatableValue(F value) : type_(VALUE) { new (&this->value_) T(std::move(value)); } - // For stateless lambdas (convertible to function pointer): use function pointer - template - TemplatableValue(F f) requires std::invocable && std::convertible_to - : type_(STATELESS_LAMBDA) { - this->stateless_f_ = f; // Implicit conversion to function pointer - } - - // For stateful lambdas (not convertible to function pointer): use std::function - template - TemplatableValue(F f) requires std::invocable &&(!std::convertible_to) : type_(LAMBDA) { + template::value, int> = 0> TemplatableValue(F f) : type_(LAMBDA) { this->f_ = new std::function(std::move(f)); } @@ -50,8 +41,6 @@ template class TemplatableValue { new (&this->value_) T(other.value_); } else if (type_ == LAMBDA) { this->f_ = new std::function(*other.f_); - } else if (type_ == STATELESS_LAMBDA) { - this->stateless_f_ = other.stateless_f_; } } @@ -62,8 +51,6 @@ template class TemplatableValue { } else if (type_ == LAMBDA) { this->f_ = other.f_; other.f_ = nullptr; - } else if (type_ == STATELESS_LAMBDA) { - this->stateless_f_ = other.stateless_f_; } other.type_ = NONE; } @@ -91,23 +78,16 @@ template class TemplatableValue { } else if (type_ == LAMBDA) { delete this->f_; } - // STATELESS_LAMBDA/NONE: no cleanup needed (function pointer or empty, not heap-allocated) } bool has_value() { return this->type_ != NONE; } T value(X... x) { - switch (this->type_) { - case STATELESS_LAMBDA: - return this->stateless_f_(x...); // Direct function pointer call - case LAMBDA: - return (*this->f_)(x...); // std::function call - case VALUE: - return this->value_; - case NONE: - default: - return T{}; + if (this->type_ == LAMBDA) { + return (*this->f_)(x...); } + // return value also when none + return this->type_ == VALUE ? this->value_ : T{}; } optional optional_value(X... x) { @@ -129,13 +109,11 @@ template class TemplatableValue { NONE, VALUE, LAMBDA, - STATELESS_LAMBDA, } type_; union { T value_; std::function *f_; - T (*stateless_f_)(X...); }; };