From 2e61a86b2f2a8bf14b70180e4e99613a9b91bd51 Mon Sep 17 00:00:00 2001 From: neargye Date: Sun, 25 Aug 2019 17:02:00 +0500 Subject: [PATCH] improve name_impl --- include/magic_enum.hpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 8e20dc1..319e1c9 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -122,18 +122,19 @@ inline constexpr auto range_v = range_impl(); return {}; // Invalid name. } +template +struct always_false final : std::false_type {}; + template -[[nodiscard]] constexpr std::string_view name_impl() noexcept { +[[nodiscard]] constexpr auto name_impl() noexcept { static_assert(std::is_enum_v, "magic_enum::detail::name_impl requires enum type."); -#if defined(__clang__) +#if defined(__clang__) || defined(__GNUC__) && __GNUC__ >= 9 return pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2}); -#elif defined(__GNUC__) && __GNUC__ >= 9 - return pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 51}); #elif defined(_MSC_VER) return pretty_name({__FUNCSIG__, sizeof(__FUNCSIG__) - 17}); #else -# error "magic_enum: Unsupported compiler (https://github.com/Neargye/magic_enum#compiler-compatibility)." - return {}; // Unsupported compiler. + static_assert(always_false{}, "magic_enum: Unsupported compiler (https://github.com/Neargye/magic_enum#compiler-compatibility)."); + return std::string_view{}; // Unsupported compiler. #endif }