This commit is contained in:
neargye 2019-03-21 11:56:59 +05:00
parent c25c0b607e
commit c015859ddb

View file

@ -36,7 +36,7 @@
#include <string_view> #include <string_view>
#if !defined(NAMEOF_ENUM_MAX_SEARCH_DEPTH) #if !defined(NAMEOF_ENUM_MAX_SEARCH_DEPTH)
# define NAMEOF_ENUM_MAX_SEARCH_DEPTH 64 # define NAMEOF_ENUM_MAX_SEARCH_DEPTH 256
#endif #endif
namespace nameof { namespace nameof {
@ -154,29 +154,34 @@ constexpr std::string_view nameof_enum_impl() {
template <typename T, int I> template <typename T, int I>
struct nameof_enum_t { struct nameof_enum_t {
constexpr std::string_view operator()(int value) const { constexpr std::string_view operator()(int value) const {
return (value - I == 0) switch (value - I) {
? nameof_enum_impl<T, T(I)>() case 0:
: (value - I == 1) return nameof_enum_impl<T, T{I}>();
? nameof_enum_impl<T, T(I + 1)>() case 1:
: (value - I == 2) return nameof_enum_impl<T, T{I + 1}>();
? nameof_enum_impl<T, T(I + 2)>() case 2:
: (value - I == 3) return nameof_enum_impl<T, T{I + 2}>();
? nameof_enum_impl<T, T(I + 3)>() case 3:
: (value - I == 4) return nameof_enum_impl<T, T{I + 3}>();
? nameof_enum_impl<T, T(I + 4)>() case 4:
: (value - I == 5) return nameof_enum_impl<T, T{I + 4}>();
? nameof_enum_impl<T, T(I + 5)>() case 5:
: (value - I == 6) return nameof_enum_impl<T, T{I + 5}>();
? nameof_enum_impl<T, T(I + 6)>() case 6:
: (value - I == 7) return nameof_enum_impl<T, T{I + 6}>();
? nameof_enum_impl<T, T(I + 7)>() case 7:
: nameof_enum_t<T, I + 8>{}(value); return nameof_enum_impl<T, T{I + 7}>();
default:
return nameof_enum_t<T, I + 8>{}(value);
}
} }
}; };
template <typename T> template <typename T>
struct nameof_enum_t<T, NAMEOF_ENUM_MAX_SEARCH_DEPTH> { struct nameof_enum_t<T, NAMEOF_ENUM_MAX_SEARCH_DEPTH> {
constexpr std::string_view operator()(int) const { return {"nameof_enum::out_of_range"}; } constexpr std::string_view operator()(int) const {
return { "nameof_enum::out_of_range" };
}
}; };
constexpr std::string_view nameof_type_impl_(std::string_view name) { constexpr std::string_view nameof_type_impl_(std::string_view name) {