From f4f4908d7eb7f22187061429cd0e244a090d3e15 Mon Sep 17 00:00:00 2001 From: neargye Date: Fri, 5 Jun 2020 15:24:13 +0500 Subject: [PATCH] clean-up NAMEOF_TYPE_RTTI --- include/nameof.hpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index f637342..34e80db 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -559,16 +559,18 @@ constexpr auto n() noexcept { template inline constexpr auto type_name_v = n(); -inline auto n(const char* tn) { #if __has_include() +inline std::string demangle(const char* tn) { auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr); auto r = std::string{dmg != nullptr ? dmg : tn}; std::free(dmg); 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 @@ -691,7 +693,7 @@ template #define NAMEOF_FULL_TYPE_EXPR(...) ::nameof::nameof_full_type() // 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) # pragma warning(pop)