From 5b0f5b52b9f904c8b6051ac4d6e71d435351bf9e Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Thu, 14 Dec 2023 21:39:25 +0000 Subject: [PATCH] 0033554: Foundation Classes - Missed hash specialization for enumerations Fixed problem with missed hash specialization --- src/NCollection/NCollection_DefaultHasher.hxx | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/NCollection/NCollection_DefaultHasher.hxx b/src/NCollection/NCollection_DefaultHasher.hxx index 4007ea2739..188bb1b23f 100644 --- a/src/NCollection/NCollection_DefaultHasher.hxx +++ b/src/NCollection/NCollection_DefaultHasher.hxx @@ -29,8 +29,50 @@ * IsEqual. */ template -DEFINE_HASHER(NCollection_DefaultHasher, TheKeyType, std::hash, std::equal_to) +struct NCollection_DefaultHasher +{ + size_t operator()(const TheKeyType& theKey) const noexcept + { + return HashCode(theKey); + } + bool operator() (const TheKeyType& theK1, const TheKeyType& theK2) const noexcept + { + return IsEqual(theK1, theK2); + } +private: + // For non-enums + template + typename std::enable_if::value, size_t>::type + HashCode(const TheKeyType& theKey) const noexcept + { + return std::hash{}(theKey); + } + + // For non-enums + template + typename std::enable_if::value, bool>::type + IsEqual(const TheKeyType& theK1, const TheKeyType& theK2) const noexcept + { + return std::equal_to{}(theK1, theK2); + } + + // For enums + template + typename std::enable_if::value, size_t>::type + HashCode(const TheKeyType& theKey) const noexcept + { + return static_cast(theKey); + } + + // For enums + template + typename std::enable_if::value, bool>::type + IsEqual(const TheKeyType& theK1, const TheKeyType& theK2) const noexcept + { + return theK1 == theK2; + } +}; #define DEFINE_DEFAULT_HASHER_PURE(TheKeyType) \ template <> struct NCollection_DefaultHasher \