[PATCH] D136850: [ADT] Simplify hashing for tuples

Joe Loser via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 08:10:23 PDT 2022


jloser created this revision.
jloser added reviewers: scott.linder, dblaikie, MaskRay, kazu.
Herald added a subscriber: StephenFan.
Herald added a project: All.
jloser requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136850

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


Index: llvm/include/llvm/ADT/Hashing.h
===================================================================
--- llvm/include/llvm/ADT/Hashing.h
+++ llvm/include/llvm/ADT/Hashing.h
@@ -651,24 +651,8 @@
   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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136850.471172.patch
Type: text/x-patch
Size: 1167 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221027/a870098a/attachment.bin>


More information about the llvm-commits mailing list