From: dpasukhi Date: Thu, 14 Dec 2023 21:39:25 +0000 (+0000) Subject: 0033554: Foundation Classes - Missed hash specialization for enumerations X-Git-Tag: V7_8_0~2 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=5b0f5b52b9f904c8b6051ac4d6e71d435351bf9e;p=occt.git 0033554: Foundation Classes - Missed hash specialization for enumerations Fixed problem with missed hash specialization --- 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 \