mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0033554: Foundation Classes - Missed hash specialization for enumerations
Fixed problem with missed hash specialization
This commit is contained in:
parent
06282d9c7c
commit
5b0f5b52b9
@ -29,8 +29,50 @@
|
|||||||
* IsEqual.
|
* IsEqual.
|
||||||
*/
|
*/
|
||||||
template <class TheKeyType>
|
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) \
|
#define DEFINE_DEFAULT_HASHER_PURE(TheKeyType) \
|
||||||
template <> struct NCollection_DefaultHasher<TheKeyType> \
|
template <> struct NCollection_DefaultHasher<TheKeyType> \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user