clean-up NAMEOF_TYPE_RTTI

This commit is contained in:
neargye 2020-06-05 15:24:13 +05:00
parent d099f13d12
commit f4f4908d7e

View file

@ -559,16 +559,18 @@ constexpr auto n() noexcept {
template <typename... T> template <typename... T>
inline constexpr auto type_name_v = n<T...>(); inline constexpr auto type_name_v = n<T...>();
inline auto n(const char* tn) {
#if __has_include(<cxxabi.h>) #if __has_include(<cxxabi.h>)
inline std::string demangle(const char* tn) {
auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr); auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
auto r = std::string{dmg != nullptr ? dmg : tn}; auto r = std::string{dmg != nullptr ? dmg : tn};
std::free(dmg); std::free(dmg);
return r; return r;
#else
return std::string_view{tn};
#endif
} }
#else
constexpr std::string_view demangle(const char* tn) noexcept {
return std::string_view{tn};
}
#endif
} // namespace nameof::detail } // namespace nameof::detail
@ -691,7 +693,7 @@ template <typename T>
#define NAMEOF_FULL_TYPE_EXPR(...) ::nameof::nameof_full_type<decltype(__VA_ARGS__)>() #define NAMEOF_FULL_TYPE_EXPR(...) ::nameof::nameof_full_type<decltype(__VA_ARGS__)>()
// Obtains string name of type using RTTI. // Obtains string name of type using RTTI.
#define NAMEOF_TYPE_RTTI(...) ::nameof::detail::n(typeid(__VA_ARGS__).name()) #define NAMEOF_TYPE_RTTI(...) ::nameof::detail::demangle(typeid(__VA_ARGS__).name())
#if defined(_MSC_VER) #if defined(_MSC_VER)
# pragma warning(pop) # pragma warning(pop)