From fa938cff96decb7b4806520d1472c02828727175 Mon Sep 17 00:00:00 2001 From: neargye Date: Mon, 2 Dec 2019 14:17:48 +0500 Subject: [PATCH] fix nameof_type --- include/nameof.hpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index 38c0d27..e6fbc74 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -554,6 +554,7 @@ 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 @@ -562,6 +563,9 @@ constexpr auto n() noexcept { #endif } +template +inline constexpr auto type_name_v = n(); + } // namespace nameof::detail // Checks is nameof_type supported compiler. @@ -588,28 +592,22 @@ template // Obtains string name of type, reference and cv-qualifiers are ignored. template -[[nodiscard]] constexpr auto nameof_type() noexcept { +[[nodiscard]] constexpr std::string_view nameof_type() noexcept { #if defined(_MSC_VER) - constexpr auto name = detail::n>>(); + return detail::type_name_v>>; #else - constexpr auto name = detail::n>(); + return detail::type_name_v>; #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 { +[[nodiscard]] constexpr std::string_view nameof_full_type() noexcept { #if defined(_MSC_VER) - constexpr auto name = detail::n>(); + return detail::type_name_v>; #else - constexpr auto name = detail::n(); + return detail::type_name_v; #endif - static_assert(name.size() > 0, "Type does not have a name."); - - return name; } } // namespace nameof