fix: also support magic_enum 0.9.5 (#6981)

this is not a perfect version-check - there are version inbetween we
haven't actually tested, but magic_enum 0.9.5 and 0.9.8 both work as
expected

Parent-pr: 6980
This commit is contained in:
pajlada
2026-05-04 18:02:39 +00:00
committed by GitHub
parent 505df040bf
commit 6ddd9af2a3
2 changed files with 21 additions and 4 deletions
+17 -4
View File
@@ -10,6 +10,15 @@
#include <concepts>
/// MAGIC_ENUM_VERSION_AT_LEAST(0, 9, 8) equivalent to magic enum version >= 0.9.8
#define MAGIC_ENUM_VERSION_AT_LEAST(major, minor, patch) \
((MAGIC_ENUM_VERSION_MAJOR > (major)) || \
(MAGIC_ENUM_VERSION_MAJOR == (major) && \
MAGIC_ENUM_VERSION_MINOR > (minor)) || \
(MAGIC_ENUM_VERSION_MAJOR == (major) && \
MAGIC_ENUM_VERSION_MINOR == (minor) && \
MAGIC_ENUM_VERSION_PATCH >= (patch)))
namespace chatterino::qmagicenum::detail {
template <typename T, typename U>
@@ -54,10 +63,14 @@ consteval bool isLatin1(std::string_view maybe)
}
template <typename BinaryPredicate>
constexpr bool eq(
QStringView a, QStringView b,
[[maybe_unused]] BinaryPredicate &&
p) noexcept(magic_enum::detail::is_nothrow_invocable_v<BinaryPredicate>)
constexpr bool
eq(QStringView a, QStringView b, [[maybe_unused]] BinaryPredicate &&p) noexcept(
#if MAGIC_ENUM_VERSION_AT_LEAST(0, 9, 8)
magic_enum::detail::is_nothrow_invocable_v<BinaryPredicate>
#else
magic_enum::detail::is_nothrow_invocable<BinaryPredicate>()
#endif
)
{
// Note: QStringView::operator== isn't constexpr
if (a.size() != b.size())
+4
View File
@@ -71,8 +71,12 @@ inline constexpr auto TAGGED_DATA_STORAGE =
template <typename C, typename E, typename Tag, E V>
consteval auto enumTaggedDataStorage()
{
#if MAGIC_ENUM_VERSION_AT_LEAST(0, 9, 8)
constexpr std::string_view utf8 =
TAGGED_DATA_STORAGE<decltype(V), Tag, V>.str();
#else
constexpr std::string_view utf8 = TAGGED_DATA_STORAGE<decltype(V), Tag, V>;
#endif
static_assert(isLatin1<utf8.size()>(utf8),
"Can't convert non-latin1 UTF8 to UTF16");