From 40c0d888e69decf39fa614c4d07badbe5d92e6a3 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Wed, 2 Jul 2025 23:10:30 +0200 Subject: [PATCH] Added std::hash for tuples, because why not. --- source/mijin/util/hash.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/mijin/util/hash.hpp b/source/mijin/util/hash.hpp index 9ebe40b..7b359bb 100644 --- a/source/mijin/util/hash.hpp +++ b/source/mijin/util/hash.hpp @@ -6,6 +6,8 @@ #define MIJIN_UTIL_HASH_HPP_INCLUDED 1 #include +#include +#include namespace mijin { @@ -16,4 +18,21 @@ inline void hashCombine(std::size_t& seed, const T& value, const THasher& hasher } } +template +struct std::hash> +{ + std::size_t operator()(const std::tuple& tuple) const noexcept + { + return hashImpl(tuple, std::index_sequence_for()); + } + + template + std::size_t hashImpl(const std::tuple& tuple, std::index_sequence) const noexcept + { + std::size_t result = 0; + (mijin::hashCombine(result, std::get(tuple)), ...); + return result; + } +}; + #endif // MIJIN_UTIL_HASH_HPP_INCLUDED