diff --git a/esphome/components/api/homeassistant_service.h b/esphome/components/api/homeassistant_service.h index 26269bcae4..90cfe751b6 100644 --- a/esphome/components/api/homeassistant_service.h +++ b/esphome/components/api/homeassistant_service.h @@ -12,10 +12,10 @@ template class TemplatableStringValue : public TemplatableValue() {} - template::value, int> = 0> + template::value, int> = 0> TemplatableStringValue(F value) : TemplatableValue(value) {} - template::value, int> = 0> + template::value, int> = 0> TemplatableStringValue(F f) : TemplatableValue([f](X... x) -> std::string { return to_string(f(x...)); }) {} }; diff --git a/esphome/core/automation.h b/esphome/core/automation.h index e5460bef34..f43fb98f20 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -21,10 +21,10 @@ template class TemplatableValue { public: TemplatableValue() : type_(EMPTY) {} - template::value, int> = 0> + template::value, int> = 0> TemplatableValue(F value) : type_(VALUE), value_(value) {} - template::value, int> = 0> + template::value, int> = 0> TemplatableValue(F f) : type_(LAMBDA), f_(f) {} bool has_value() { return this->type_ != EMPTY; } diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 22ed018855..d677e34649 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -186,17 +186,6 @@ template class CallbackManager { std::vector> callbacks_; }; -// https://stackoverflow.com/a/37161919/8924614 -template -struct is_callable // NOLINT -{ - template static auto test(U *p) -> decltype((*p)(std::declval()...), void(), std::true_type()); - - template static auto test(...) -> decltype(std::false_type()); - - static constexpr auto value = decltype(test(nullptr))::value; // NOLINT -}; - void delay_microseconds_safe(uint32_t us); template class Deduplicator { @@ -274,6 +263,18 @@ template constexpr const T &clamp(const T &v, const T &lo, const T & } #endif +// std::is_invocable from C++17 +#if __cpp_lib_is_invocable >= 201703 +using std::is_invocable; +#else +// https://stackoverflow.com/a/37161919/8924614 +template struct is_invocable { // NOLINT(readability-identifier-naming) + template static auto test(U *p) -> decltype((*p)(std::declval()...), void(), std::true_type()); + template static auto test(...) -> decltype(std::false_type()); + static constexpr auto value = decltype(test(nullptr))::value; // NOLINT +}; +#endif + // std::bit_cast from C++20 #if __cpp_lib_bit_cast >= 201806 using std::bit_cast;