From fc7e9c8a0c1ebabe7b3bd9a63b604a4ce7182c73 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 11 Feb 2026 12:20:36 -0600 Subject: [PATCH] add reverse operators --- esphome/core/helpers.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 9bf5b0eeb4..dfca1e51f0 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -1841,4 +1841,10 @@ class CompactString { static_assert(sizeof(CompactString) == 20, "CompactString must be exactly 20 bytes"); +// Reverse comparison overloads so CompactString works on either side of == and != +inline bool operator==(const std::string &lhs, const CompactString &rhs) { return rhs == lhs; } +inline bool operator==(const char *lhs, const CompactString &rhs) { return rhs == lhs; } +inline bool operator!=(const std::string &lhs, const CompactString &rhs) { return !(rhs == lhs); } +inline bool operator!=(const char *lhs, const CompactString &rhs) { return !(rhs == lhs); } + } // namespace esphome