mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
workaround enum_type_name
This commit is contained in:
parent
d73a985f52
commit
b6743e4a26
2 changed files with 8 additions and 2 deletions
|
|
@ -274,6 +274,7 @@ constexpr std::uint8_t log2(T value) noexcept {
|
|||
|
||||
return log2<U>(static_cast<U>(value));
|
||||
} else {
|
||||
static_assert(std::is_integral_v<T>, "magic_enum::detail::log2 requires integral type.");
|
||||
auto ret = std::uint8_t{0};
|
||||
for (; value > static_cast<T>(1); value >>= static_cast<T>(1), ++ret) {};
|
||||
|
||||
|
|
@ -288,6 +289,8 @@ constexpr bool is_pow2(T x) noexcept {
|
|||
|
||||
return is_pow2<U>(static_cast<U>(x));
|
||||
} else {
|
||||
static_assert(std::is_integral_v<T>, "magic_enum::detail::is_pow2 requires integral type.");
|
||||
|
||||
return x != 0 && (x & (x - 1)) == 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -595,7 +598,12 @@ template <typename E>
|
|||
[[nodiscard]] constexpr std::string_view enum_type_name() noexcept {
|
||||
using D = std::decay_t<E>;
|
||||
static_assert(std::is_enum_v<D>, "Requires enum type.");
|
||||
#if defined(_MSC_VER)
|
||||
// TODO: https://github.com/Neargye/nameof/issues/22
|
||||
constexpr std::string_view name = std::string_view{detail::type_name_v<D>}.substr(5, detail::type_name_v<D>.size() - 5);
|
||||
#else
|
||||
constexpr std::string_view name = detail::type_name_v<D>;
|
||||
#endif
|
||||
static_assert(name.size() > 0, "Enum type does not have a name.");
|
||||
|
||||
return name;
|
||||
|
|
|
|||
|
|
@ -571,14 +571,12 @@ TEST_CASE("type_traits") {
|
|||
REQUIRE_FALSE(is_scoped_enum_v<number>);
|
||||
}
|
||||
|
||||
/* TODO: https://github.com/Neargye/nameof/issues/22
|
||||
TEST_CASE("enum_type_name") {
|
||||
REQUIRE(enum_type_name<Color&>() == "Color");
|
||||
REQUIRE(enum_type_name<Numbers>() == "Numbers");
|
||||
REQUIRE(enum_type_name<Directions&>() == "Directions");
|
||||
REQUIRE(enum_type_name<number>() == "number");
|
||||
}
|
||||
*/
|
||||
|
||||
#if defined(MAGIC_ENUM_SUPPORTED_ALIASES)
|
||||
TEST_CASE("aliases") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue