1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-10 23:44:29 +00:00

add compile check at enum_name

This commit is contained in:
Neargye 2020-01-25 23:51:50 +05:00
parent 6b220c83fc
commit e3dd165a4a
2 changed files with 4 additions and 5 deletions

View file

@ -511,7 +511,10 @@ template <typename E>
// This version is much lighter on the compile times and is not restricted to the enum_range limitation.
template <auto V>
[[nodiscard]] constexpr auto enum_name() noexcept -> detail::enable_if_enum_t<decltype(V), std::string_view> {
return detail::name_v<std::decay_t<decltype(V)>, V>;
constexpr std::string_view name = detail::name_v<std::decay_t<decltype(V)>, V>;
static_assert(name.size() > 0, "Enum value does not have a name.");
return name;
}
// Returns string enum name from enum value.