[llvm] ec061cd - [ADT] Simplify DenseMapInfo<std::tuple<...>> with constexpr if (NFC) (#156810)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 07:46:09 PDT 2025


Author: Kazu Hirata
Date: 2025-09-04T07:46:03-07:00
New Revision: ec061cd6ba8e63b6fbb5e8181ecbfd127a68d678

URL: https://github.com/llvm/llvm-project/commit/ec061cd6ba8e63b6fbb5e8181ecbfd127a68d678
DIFF: https://github.com/llvm/llvm-project/commit/ec061cd6ba8e63b6fbb5e8181ecbfd127a68d678.diff

LOG: [ADT] Simplify DenseMapInfo<std::tuple<...>> with constexpr if (NFC) (#156810)

This patch consolidates two implementations of getHashValueImpl into
one with "constexpr if", which should be more readable than the
SFINAE-based approach.

The same applies to isEqualImpl.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/DenseMapInfo.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index ec7a116856bb4..717156c4bd196 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -179,41 +179,35 @@ template <typename... Ts> struct DenseMapInfo<std::tuple<Ts...>> {
     return Tuple(DenseMapInfo<Ts>::getTombstoneKey()...);
   }
 
-  template <unsigned I>
-  static unsigned getHashValueImpl(const Tuple &values, std::false_type) {
-    using EltType = std::tuple_element_t<I, Tuple>;
-    std::integral_constant<bool, I + 1 == sizeof...(Ts)> atEnd;
-    return detail::combineHashValue(
-        DenseMapInfo<EltType>::getHashValue(std::get<I>(values)),
-        getHashValueImpl<I + 1>(values, atEnd));
-  }
-
-  template <unsigned I>
-  static unsigned getHashValueImpl(const Tuple &, std::true_type) {
-    return 0;
+  template <unsigned I> static unsigned getHashValueImpl(const Tuple &values) {
+    if constexpr (I == sizeof...(Ts))
+      return 0;
+    else {
+      using EltType = std::tuple_element_t<I, Tuple>;
+      return detail::combineHashValue(
+          DenseMapInfo<EltType>::getHashValue(std::get<I>(values)),
+          getHashValueImpl<I + 1>(values));
+    }
   }
 
   static unsigned getHashValue(const std::tuple<Ts...> &values) {
-    std::integral_constant<bool, 0 == sizeof...(Ts)> atEnd;
-    return getHashValueImpl<0>(values, atEnd);
+    return getHashValueImpl<0>(values);
   }
 
   template <unsigned I>
-  static bool isEqualImpl(const Tuple &lhs, const Tuple &rhs, std::false_type) {
-    using EltType = std::tuple_element_t<I, Tuple>;
-    std::integral_constant<bool, I + 1 == sizeof...(Ts)> atEnd;
-    return DenseMapInfo<EltType>::isEqual(std::get<I>(lhs), std::get<I>(rhs)) &&
-           isEqualImpl<I + 1>(lhs, rhs, atEnd);
-  }
-
-  template <unsigned I>
-  static bool isEqualImpl(const Tuple &, const Tuple &, std::true_type) {
-    return true;
+  static bool isEqualImpl(const Tuple &lhs, const Tuple &rhs) {
+    if constexpr (I == sizeof...(Ts))
+      return true;
+    else {
+      using EltType = std::tuple_element_t<I, Tuple>;
+      return DenseMapInfo<EltType>::isEqual(std::get<I>(lhs),
+                                            std::get<I>(rhs)) &&
+             isEqualImpl<I + 1>(lhs, rhs);
+    }
   }
 
   static bool isEqual(const Tuple &lhs, const Tuple &rhs) {
-    std::integral_constant<bool, 0 == sizeof...(Ts)> atEnd;
-    return isEqualImpl<0>(lhs, rhs, atEnd);
+    return isEqualImpl<0>(lhs, rhs);
   }
 };
 


        


More information about the llvm-commits mailing list