diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 48af7f674a..52a0746057 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -1174,12 +1174,18 @@ template using ExternalRAMAllocator = RAMAllocator; * Functions to constrain the range of arithmetic values. */ -template T clamp_at_least(T value, T min) { +template +concept comparable_with = requires(T a, U b) { + { a > b } -> std::convertible_to; + { a < b } -> std::convertible_to; +}; + +template U> T clamp_at_least(T value, U min) { if (value < min) return min; return value; } -template T clamp_at_most(T value, T max) { +template U> T clamp_at_most(T value, U max) { if (value > max) return max; return value;