update NameofEnum

This commit is contained in:
Neargye 2018-09-04 19:04:09 +05:00
parent 819c58c8eb
commit ff6553a754

View file

@ -459,18 +459,17 @@ constexpr cstring Nameof(const char* name, std::size_t size, bool with_suffix =
} }
template <typename T, template <typename T,
typename = typename std::enable_if<std::is_enum<T>::value>::type> typename D = typename std::decay<T>::type,
NAMEOF_CONSTEXPR cstring NameofEnum(T value) { typename U = typename std::underlying_type<D>::type,
typename S = typename std::is_signed<U>::type,
typename = typename std::enable_if<std::is_enum<D>::value>::type>
NAMEOF_CONSTEXPR cstring NameofEnum(D value) {
#if defined(__clang__) || defined(_MSC_VER) #if defined(__clang__) || defined(_MSC_VER)
return detail::NameofPretty( return detail::NameofPretty(
std::is_unsigned<typename std::underlying_type<T>::type>::value detail::NameofEnumImpl<D, S::value ? -NAMEOF_ENUM_MAX_SEARCH_DEPTH : 0>{}(static_cast<int>(value)),
? detail::NameofEnumImpl<T, 0>{}(static_cast<int>(value))
: detail::NameofEnumImpl<T, -NAMEOF_ENUM_MAX_SEARCH_DEPTH>{}(static_cast<int>(value)),
false); false);
#elif defined(__GNUC__) #elif defined(__GNUC__)
return std::is_unsigned<typename std::underlying_type<T>::type>::value return detail::NameofEnumImpl<D, S::value ? -NAMEOF_ENUM_MAX_SEARCH_DEPTH : 0>{}(static_cast<int>(value));
? detail::NameofEnumImpl<T, 0>{}(static_cast<int>(value))
: detail::NameofEnumImpl<T, -NAMEOF_ENUM_MAX_SEARCH_DEPTH>{}(static_cast<int>(value));
#else #else
return {}; return {};
#endif #endif
@ -497,7 +496,7 @@ constexpr cstring NameofRaw(const char* name, std::size_t size) {
#define NAMEOF_RAW(...) ::nameof::NameofRaw<decltype(__VA_ARGS__)>(#__VA_ARGS__, (sizeof(#__VA_ARGS__) / sizeof(char)) - 1) #define NAMEOF_RAW(...) ::nameof::NameofRaw<decltype(__VA_ARGS__)>(#__VA_ARGS__, (sizeof(#__VA_ARGS__) / sizeof(char)) - 1)
// Used to obtain the simple (unqualified) string name of a enum variable. // Used to obtain the simple (unqualified) string name of a enum variable.
#define NAMEOF_ENUM(...) ::nameof::NameofEnum<::std::decay<decltype(__VA_ARGS__)>::type>(__VA_ARGS__) #define NAMEOF_ENUM(...) ::nameof::NameofEnum<decltype(__VA_ARGS__)>(__VA_ARGS__)
// Used to obtain the string name of a type. // Used to obtain the string name of a type.
#define NAMEOF_TYPE(...) ::nameof::NameofType<decltype(__VA_ARGS__)>() #define NAMEOF_TYPE(...) ::nameof::NameofType<decltype(__VA_ARGS__)>()