[llvm] [STLExtras] Add a template for detecting whether a type has an equality comparison operator (PR #176429)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 16 09:07:24 PST 2026


================
@@ -2682,6 +2682,17 @@ template <typename T> using has_sizeof = decltype(sizeof(T));
 template <typename T>
 constexpr bool is_incomplete_v = !is_detected<detail::has_sizeof, T>::value;
 
+// Detect types with equality comparison operators.
+namespace detail {
+template <typename T>
+using has_equality_comparison =
+    decltype(std::declval<const T &>() == std::declval<const T &>());
+} // namespace detail
+
+/// Detects when type `const T` can be compared for equality with itself.
+template <typename T>
----------------
kuhar wrote:

We could allow for two template arguments, `T` and `U`, so that we can check if two types are comparable. The default can be that `U = T`.

https://github.com/llvm/llvm-project/pull/176429


More information about the llvm-commits mailing list