diff options
author | Thomas Lively <tlively@google.com> | 2022-10-19 15:55:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-19 13:55:10 -0700 |
commit | 8f0c8ce9b4bcfe446d8908e3104d7992b9896a30 (patch) | |
tree | a122bee58b16d4798e25a08df5e1aac08d8a5a75 /src/support/hash.h | |
parent | 829fa11c56d05335f441aab85953b4ef7ab56ba1 (diff) | |
download | binaryen-8f0c8ce9b4bcfe446d8908e3104d7992b9896a30.tar.gz binaryen-8f0c8ce9b4bcfe446d8908e3104d7992b9896a30.tar.bz2 binaryen-8f0c8ce9b4bcfe446d8908e3104d7992b9896a30.zip |
[NFC] Add a generic hash implementation for tuples (#5162)
We already provided a specialization of `std::hash` for arbitrary pairs, so add
one for `std::tuple` as well. Use the new specialization where we were
previously using nested pairs just to be able to use the pair specialization.
Diffstat (limited to 'src/support/hash.h')
-rw-r--r-- | src/support/hash.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/support/hash.h b/src/support/hash.h index fb0e710a5..fc8b358f2 100644 --- a/src/support/hash.h +++ b/src/support/hash.h @@ -61,6 +61,24 @@ template<typename T1, typename T2> struct hash<pair<T1, T2>> { } }; +// And hashing tuples is useful, too. +template<typename T, typename... Ts> struct hash<tuple<T, Ts...>> { +private: + template<size_t... I> + static void rehash(const tuple<T, Ts...>& tup, + size_t& digest, + std::index_sequence<I...>) { + (wasm::rehash(digest, std::get<1 + I>(tup)), ...); + } + +public: + size_t operator()(const tuple<T, Ts...>& tup) const { + auto digest = wasm::hash(std::get<0>(tup)); + rehash(tup, digest, std::index_sequence_for<Ts...>{}); + return digest; + } +}; + } // namespace std #endif // wasm_support_hash_h |