Fix enum class key in hashed containers

This commit is contained in:
Flössie
2021-11-24 15:32:04 +01:00
parent 23214ae5cd
commit ac19ea4507
4 changed files with 24 additions and 9 deletions

View File

@@ -20,6 +20,7 @@
#include <functional>
#include <map>
#include <type_traits>
#include <gtkmm.h>
@@ -74,6 +75,17 @@ private:
MyMutex mutex;
};
struct ScopedEnumHash {
template<typename T, typename std::enable_if<std::is_enum<T>::value && !std::is_convertible<T, int>::value, int>::type = 0>
size_t operator ()(T val) const noexcept
{
using type = typename std::underlying_type<T>::type;
return std::hash<type>{}(static_cast<type>(val));
}
};
// TODO: The documentation says gdk_threads_enter and gdk_threads_leave should be replaced
// by g_main_context_invoke(), g_idle_add() and related functions, but this will require more extensive changes.
// We silence those warnings until then so that we notice the others.