diff options
author | Jacques Lucke <jacques@blender.org> | 2021-03-17 13:37:46 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-03-17 13:37:46 +0300 |
commit | ac60e6474569a69ffa4b9c28f9ae79ef674c5408 (patch) | |
tree | 8c721e4f9cb58ea03b3b17fe0063f8ba1cdec112 /source/blender/blenlib/BLI_hash.hh | |
parent | e00a47ffd611b0ab06dba2a4933ab15871d576e6 (diff) |
BLI: provide a default hash for enums
This avoids some boilerplate code that was necessary when using enums
as keys in maps or sets.
Diffstat (limited to 'source/blender/blenlib/BLI_hash.hh')
-rw-r--r-- | source/blender/blenlib/BLI_hash.hh | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh index 2e3212cc83b..39695b110b1 100644 --- a/source/blender/blenlib/BLI_hash.hh +++ b/source/blender/blenlib/BLI_hash.hh @@ -88,11 +88,18 @@ namespace blender { * If there is no other specialization of #DefaultHash for a given type, try to call `hash()` on * the value. If there is no such method, this will result in a compiler error. Usually that means * that you have to implement a hash function using one of three strategies listed above. + * + * In the case of an enum type, the default hash is just to cast the enum value to an integer. */ template<typename T> struct DefaultHash { uint64_t operator()(const T &value) const { - return value.hash(); + if constexpr (std::is_enum_v<T>) { + return (uint64_t)value; + } + else { + return value.hash(); + } } }; |