]> OCCT Git - occt.git/commitdiff
0033554: Foundation Classes - Missed hash specialization for enumerations
authordpasukhi <dpasukhi@opencascade.com>
Thu, 14 Dec 2023 21:39:25 +0000 (21:39 +0000)
committervglukhik <vglukhik@opencascade.com>
Fri, 15 Dec 2023 19:53:06 +0000 (19:53 +0000)
Fixed problem with missed hash specialization

src/NCollection/NCollection_DefaultHasher.hxx

index 4007ea2739816e488bb77495d487fa19f98eac93..188bb1b23f538a45ada1df7c0e41d184fbd7c08c 100644 (file)
  *              IsEqual.
 */
 template <class TheKeyType>
-DEFINE_HASHER(NCollection_DefaultHasher, TheKeyType, std::hash<TheKeyType>, std::equal_to<TheKeyType>)
+struct NCollection_DefaultHasher
+{
+  size_t operator()(const TheKeyType& theKey) const noexcept
+  {
+    return HashCode<TheKeyType>(theKey);
+  }
+  bool operator() (const TheKeyType& theK1, const TheKeyType& theK2) const noexcept
+  {
+    return IsEqual<TheKeyType>(theK1, theK2);
+  }
+
+private:
+  // For non-enums
+  template <class T = TheKeyType>
+  typename std::enable_if<!std::is_enum<T>::value, size_t>::type
+    HashCode(const TheKeyType& theKey) const noexcept
+  {
+    return std::hash<TheKeyType>{}(theKey);
+  }
+
+  // For non-enums
+  template <class T = TheKeyType>
+  typename std::enable_if<!std::is_enum<T>::value, bool>::type
+    IsEqual(const TheKeyType& theK1, const TheKeyType& theK2) const noexcept
+  {
+    return std::equal_to<TheKeyType>{}(theK1, theK2);
+  }
+
+  // For enums
+  template <class T = TheKeyType>
+  typename std::enable_if<std::is_enum<T>::value, size_t>::type
+    HashCode(const TheKeyType& theKey) const noexcept
+  {
+    return static_cast<size_t>(theKey);
+  }
 
+  // For enums
+  template <class T = TheKeyType>
+  typename std::enable_if<std::is_enum<T>::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<TheKeyType>    \