From 33023e32753df13eb9d1847f28cabba138f8f07b Mon Sep 17 00:00:00 2001 From: neargye Date: Thu, 14 Nov 2019 20:41:51 +0500 Subject: [PATCH] msvc binsize improve on clang all already ok --- include/nameof.hpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index 2d4688c..1dc08e5 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -552,7 +552,6 @@ constexpr auto n() noexcept { # elif defined(_MSC_VER) constexpr std::string_view name{__FUNCSIG__ + 63, sizeof(__FUNCSIG__) - 81 - (__FUNCSIG__[sizeof(__FUNCSIG__) - 19] == ' ' ? 1 : 0)}; # endif - static_assert(name.size() > 0, "Type does not have a name."); return cstring{name}; #else @@ -591,20 +590,26 @@ template template [[nodiscard]] constexpr auto nameof_type() noexcept { #if defined(_MSC_VER) - return detail::n>>(); + constexpr auto name = detail::n>>(); #else - return detail::n>(); + constexpr auto name = detail::n>(); #endif + static_assert(name.size() > 0, "Type does not have a name."); + + return name; } // Obtains string name of full type, with reference and cv-qualifiers. template [[nodiscard]] constexpr auto nameof_full_type() noexcept { #if defined(_MSC_VER) - return detail::n>(); + constexpr auto name = detail::n>(); #else - return detail::n(); + constexpr auto name = detail::n(); #endif + static_assert(name.size() > 0, "Type does not have a name."); + + return name; } } // namespace nameof @@ -615,7 +620,8 @@ template constexpr auto name = ::nameof::detail::pretty_name(#__VA_ARGS__, true); \ static_assert(name.size() > 0, "Expression does not have a name."); \ constexpr auto size = name.size(); \ - return ::nameof::cstring{name}; }() + constexpr auto nameof = ::nameof::cstring{name}; \ + return nameof; }() // Obtains simple (unqualified) full (with template suffix) string name of variable, function, macro. #define NAMEOF_FULL(...) []() constexpr noexcept { \ @@ -623,7 +629,8 @@ template constexpr auto name = ::nameof::detail::pretty_name(#__VA_ARGS__, false); \ static_assert(name.size() > 0, "Expression does not have a name."); \ constexpr auto size = name.size(); \ - return ::nameof::cstring{name}; }() + constexpr auto nameof_full = ::nameof::cstring{name}; \ + return nameof_full; }() // Obtains raw string name of variable, function, macro. #define NAMEOF_RAW(...) []() constexpr noexcept { \ @@ -631,7 +638,8 @@ template constexpr auto name = ::std::string_view{#__VA_ARGS__}; \ static_assert(name.size() > 0, "Expression does not have a name."); \ constexpr auto size = name.size(); \ - return ::nameof::cstring{name}; }() + constexpr auto nameof_raw = ::nameof::cstring{name}; \ + return nameof_raw; }() // Obtains simple (unqualified) string enum name of enum variable. #define NAMEOF_ENUM(...) ::nameof::nameof_enum(__VA_ARGS__)