From f018bd9ae7cf418188285c03d8fe2aacecbd4730 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Tue, 27 Sep 2016 12:33:08 -0700 Subject: [PATCH] Add hash_value support for tuples. --- include/llvm/ADT/Hashing.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/llvm/ADT/Hashing.h b/include/llvm/ADT/Hashing.h index c3b574102f6..8b1a305852b 100644 --- a/include/llvm/ADT/Hashing.h +++ b/include/llvm/ADT/Hashing.h @@ -53,6 +53,7 @@ #include #include #include +#include #include namespace llvm { @@ -656,6 +657,33 @@ hash_code hash_value(const std::basic_string &arg) { return hash_combine_range(arg.begin(), arg.end()); } +template +struct UnsignedConstantIndexSet { }; + +template +struct MakeUnsignedConstantIndexSet { + typedef typename MakeUnsignedConstantIndexSet::Type + Type; +}; + +template +struct MakeUnsignedConstantIndexSet { + typedef UnsignedConstantIndexSet Type; +}; + +template +hash_code hash_value_tuple_helper(const std::tuple &arg, + UnsignedConstantIndexSet indices) { + return hash_combine(hash_value(std::get(arg))...); +} + +template +hash_code hash_value(const std::tuple &arg) { + return hash_value_tuple_helper( + arg, + typename MakeUnsignedConstantIndexSet<0, sizeof...(Ts)>::Type()); +} + } // namespace llvm #endif