[llvm] 8d35558 - [ADT] Simplify hashing for tuples

Joe Loser via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 12:46:38 PDT 2022


Author: Joe Loser
Date: 2022-10-27T13:44:43-06:00
New Revision: 8d35558527ba9faa8a2a17201a2b3a3d9053e2f9

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

LOG: [ADT] Simplify hashing for tuples

Instead of using `std::index_sequence` with a helper function template to access
each element in the tuple, leverage `std::apply` from C++17 to do the heavy
lifting for us.

Differential Revision: https://reviews.llvm.org/D136850

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h
index 74a87a3d8dbbd..d023e76ae67ac 100644
--- a/llvm/include/llvm/ADT/Hashing.h
+++ b/llvm/include/llvm/ADT/Hashing.h
@@ -651,24 +651,8 @@ hash_code hash_value(const std::pair<T, U> &arg) {
   return hash_combine(arg.first, arg.second);
 }
 
-// Implementation details for the hash_value overload for std::tuple<...>(...).
-namespace hashing {
-namespace detail {
-
-template <typename... Ts, std::size_t... Indices>
-hash_code hash_value_tuple_helper(const std::tuple<Ts...> &arg,
-                                  std::index_sequence<Indices...>) {
-  return hash_combine(std::get<Indices>(arg)...);
-}
-
-} // namespace detail
-} // namespace hashing
-
-template <typename... Ts>
-hash_code hash_value(const std::tuple<Ts...> &arg) {
-  // TODO: Use std::apply when LLVM starts using C++17.
-  return ::llvm::hashing::detail::hash_value_tuple_helper(
-      arg, typename std::index_sequence_for<Ts...>());
+template <typename... Ts> hash_code hash_value(const std::tuple<Ts...> &arg) {
+  return std::apply([](const auto &...xs) { return hash_combine(xs...); }, arg);
 }
 
 // Declared and documented above, but defined here so that any of the hashing


        


More information about the llvm-commits mailing list