Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

This patch replaces the recursive implementation of isEqualImpl with a
C++17 fold expression.

This patch replaces the recursive implementation of isEqualImpl with a
C++17 fold expression.
@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

This patch replaces the recursive implementation of isEqualImpl with a
C++17 fold expression.


Full diff: https://github.com/llvm/llvm-project/pull/159508.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMapInfo.h (+7-11)
diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index b91a908d992f8..57a8674e35015 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -194,20 +194,16 @@ template <typename... Ts> struct DenseMapInfo<std::tuple<Ts...>> {
     return getHashValueImpl<0>(values);
   }
 
-  template <unsigned I>
-  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);
-    }
+  template <std::size_t... Is>
+  static bool isEqualImpl(const Tuple &lhs, const Tuple &rhs,
+                          std::index_sequence<Is...>) {
+    return (DenseMapInfo<std::tuple_element_t<Is, Tuple>>::isEqual(
+                std::get<Is>(lhs), std::get<Is>(rhs)) &&
+            ...);
   }
 
   static bool isEqual(const Tuple &lhs, const Tuple &rhs) {
-    return isEqualImpl<0>(lhs, rhs);
+    return isEqualImpl(lhs, rhs, std::index_sequence_for<Ts...>{});
   }
 };
 

@kazutakahirata kazutakahirata merged commit ab00172 into llvm:main Sep 18, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250917_ADT_DenseMapInfo_isEqualImpl branch September 18, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants