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