From 481f928f4d0b46a19f2b2fe27277599d35fbbdc6 Mon Sep 17 00:00:00 2001 From: terik23 Date: Mon, 22 Jul 2019 00:13:32 +0500 Subject: [PATCH] clean-up impl --- include/nameof.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index 2117c9e..e0c7a6b 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -87,7 +87,7 @@ template using check_t = typename check::type; template -[[nodiscard]] constexpr std::string_view nameof_impl(std::string_view name, bool with_template_suffix) noexcept { +[[nodiscard]] constexpr std::string_view nameof_impl(std::string_view name, bool remove_template_suffix = true) noexcept { static_assert(std::is_void_v, "nameof::detail::nameof_impl requires void type."); if (name.length() >= 1 && (name.front() == '"' || name.front() == '\'')) { return {}; // Narrow multibyte string literal. @@ -154,7 +154,9 @@ template break; } } - name.remove_suffix(with_template_suffix ? 0 : s); + if (remove_template_suffix) { + name.remove_suffix(s); + } if (name.length() > 0 && ((name.front() >= 'a' && name.front() <= 'z') || (name.front() >= 'A' && name.front() <= 'Z') || @@ -176,11 +178,11 @@ template [[nodiscard]] constexpr std::string_view nameof_enum_impl() noexcept { static_assert(std::is_enum_v, "nameof::nameof_enum_impl requires enum type."); #if defined(__clang__) - constexpr auto name = nameof_impl({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2}, false); + constexpr auto name = nameof_impl({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2}); #elif defined(__GNUC__) && __GNUC__ >= 9 - constexpr auto name = nameof_impl({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 51}, false); + constexpr auto name = nameof_impl({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 51}); #elif defined(_MSC_VER) - constexpr auto name = nameof_impl({__FUNCSIG__, sizeof(__FUNCSIG__) - 17}, false); + constexpr auto name = nameof_impl({__FUNCSIG__, sizeof(__FUNCSIG__) - 17}); #else constexpr std::string_view name; // Unsupported compiler. #endif @@ -266,10 +268,10 @@ template } // namespace nameof // Obtains simple (unqualified) string name of variable, function, enum, macro. -#define NAMEOF(...) ::nameof::detail::nameof_impl<::nameof::detail::check_t>(#__VA_ARGS__, false) +#define NAMEOF(...) ::nameof::detail::nameof_impl<::nameof::detail::check_t>(#__VA_ARGS__) // Obtains simple (unqualified) full (with template suffix) string name of variable, function, enum, macro. -#define NAMEOF_FULL(...) ::nameof::detail::nameof_impl<::nameof::detail::check_t>(#__VA_ARGS__, true) +#define NAMEOF_FULL(...) ::nameof::detail::nameof_impl<::nameof::detail::check_t>(#__VA_ARGS__, false) // Obtains raw string name of variable, function, enum, macro. #define NAMEOF_RAW(...) ::nameof::detail::nameof_raw_impl<::nameof::detail::check_t>(#__VA_ARGS__)