Actually make this a compile-time check

This commit is contained in:
Charles Dang 2022-04-01 06:18:24 -04:00
parent 87605e745e
commit aadb6b4aaa
2 changed files with 11 additions and 3 deletions

View file

@ -17,6 +17,7 @@
#include "gui/core/event/handler.hpp"
#include "hotkey/hotkey_command.hpp"
#include "utils/general.hpp"
#include <SDL2/SDL_events.h>
@ -525,7 +526,7 @@ public:
} else if constexpr(is_text_input_event(E)) {
VALIDATE_AND_ADD_TO_QUEUE(signal_text_input)
} else {
assert(false && "No matching signal queue found for event");
static_assert(utils::dependent_false_v<E>, "No matching signal queue found for event");
}
}
@ -569,7 +570,7 @@ public:
} else if constexpr(is_text_input_event(E)) {
VALIDATE_AND_REMOVE_FROM_QUEUE(signal_text_input)
} else {
assert(false && "No matching signal queue found for event");
static_assert(utils::dependent_false_v<E>, "No matching signal queue found for event");
}
}

View file

@ -24,7 +24,7 @@ inline bool chars_equal_insensitive(char a, char b) { return tolower(a) == tolow
inline bool chars_less_insensitive(char a, char b) { return tolower(a) < tolower(b); }
/**
* Equivalent to as @c std::is_same_v except both types are passed throgh std::decay first.
* Equivalent to as @c std::is_same_v except both types are passed through std::decay first.
*
* @tparam T1 The first type to compare.
* @tparam T2 The second type to compare.
@ -32,6 +32,13 @@ inline bool chars_less_insensitive(char a, char b) { return tolower(a) < tolower
template<typename T1, typename T2>
inline constexpr bool decayed_is_same = std::is_same_v<std::decay_t<T1>, std::decay_t<T2>>;
/**
* Workaround for the fact that static_assert(false) is invalid.
* See https://devblogs.microsoft.com/oldnewthing/20200311-00/?p=103553
*/
template<typename>
inline constexpr bool dependent_false_v = false;
namespace detail
{
/**