From 4bb381d3e9d7048b6ed84c6e1e904b04c83fab7d Mon Sep 17 00:00:00 2001 From: terik23 Date: Mon, 25 Mar 2019 00:33:22 +0500 Subject: [PATCH] clean-up nameof_type_impl --- include/nameof.hpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index 40a2b61..69fafd6 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -124,28 +124,24 @@ struct identity final { template [[nodiscard]] constexpr std::string_view nameof_type_impl() noexcept { #if defined(__clang__) - constexpr auto str = __PRETTY_FUNCTION__; - constexpr auto size = sizeof(__PRETTY_FUNCTION__) - 1; + std::string_view name{__PRETTY_FUNCTION__}; constexpr auto prefix = sizeof("std::string_view nameof::detail::nameof_type_impl() [T = nameof::detail::identity<") - 1; constexpr auto suffix = sizeof(">]") - 1; #elif defined(__GNUC__) - constexpr auto str = __PRETTY_FUNCTION__; - constexpr auto size = sizeof(__PRETTY_FUNCTION__) - 1; + std::string_view name{__PRETTY_FUNCTION__}; constexpr auto prefix = sizeof("constexpr std::string_view nameof::detail::nameof_type_impl() [with T = nameof::detail::identity<") - 1; constexpr auto suffix = sizeof(">; std::string_view = std::basic_string_view]") - 1; #elif defined(_MSC_VER) - constexpr auto str = __FUNCSIG__; - constexpr auto size = sizeof(__FUNCSIG__) - 1; + std::string_view name{__FUNCSIG__}; constexpr auto prefix = sizeof("class std::basic_string_view > __cdecl nameof::detail::nameof_type_impl>(void) noexcept") - 1; #else - constexpr auto str = "nameof_type::unsupported_compiler"; - constexpr auto size = sizeof("nameof_type::unsupported_compiler") - 1; + std::string_view name{"nameof_type::unsupported_compiler"}; constexpr auto prefix = 0; constexpr auto suffix = 0; #endif - - std::string_view name{str + prefix, size - prefix - suffix}; + name.remove_prefix(prefix); + name.remove_suffix(suffix); if (name.size() > sizeof("enum") && name[0] == 'e' && name[1] == 'n' && name[2] == 'u' && name[3] == 'm' && name[4] == ' ') { name.remove_prefix(sizeof("enum")); }