diff --git a/esphome/core/automation.h b/esphome/core/automation.h index eb8c9316ba4..82dce303d28 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -27,20 +27,21 @@ template class TemplatableValue { public: TemplatableValue() : type_(NONE) {} - template::value, int> = 0> TemplatableValue(F value) : type_(VALUE) { + template + requires(!std::invocable) TemplatableValue(F value) : type_(VALUE) { new (&this->value_) T(std::move(value)); } // For stateless lambdas (convertible to function pointer): use function pointer - template::value && std::is_convertible::value, int> = 0> - TemplatableValue(F f) : type_(STATELESS_LAMBDA) { + template + requires std::invocable && std::convertible_to TemplatableValue(F f) + : type_(STATELESS_LAMBDA) { this->stateless_f_ = f; // Implicit conversion to function pointer } // For stateful lambdas (not convertible to function pointer): use std::function - template::value && !std::is_convertible::value, int> = 0> - TemplatableValue(F f) : type_(LAMBDA) { + template + requires std::invocable &&(!std::convertible_to) TemplatableValue(F f) : type_(LAMBDA) { this->f_ = new std::function(std::move(f)); }