diff --git a/README.md b/README.md index 48b0fbb..bc3b171 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ Header-only C++17 library provides nameof macros and functions to obtain simple * Nameof expression argument are identified, but do not evaluated. +* Nameof type returns compiler-specific type name. + * Enum value must be in range `[-256, 256]`. If you need another range, add specialization enum_range for necessary enum type. ```cpp #include diff --git a/include/nameof.hpp b/include/nameof.hpp index 3ed5fb8..14f5f82 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -130,16 +130,16 @@ struct identity final { } } -template +template [[nodiscard]] constexpr std::string_view nameof_type_impl() noexcept { #if defined(__clang__) 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; + constexpr auto prefix = sizeof("std::string_view nameof::detail::nameof_type_impl() [T = >]") - 1; #elif defined(__GNUC__) 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; + 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) std::string_view name{__FUNCSIG__}; constexpr auto prefix = sizeof("class std::basic_string_view > __cdecl nameof::detail::nameof_type_impl #if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) name.remove_prefix(prefix); name.remove_suffix(suffix); -# if defined(_MSC_VER) - if (name.size() > sizeof("enum") && name[0] == 'e' && name[1] == 'n' && name[2] == 'u' && name[3] == 'm' && name[4] == ' ') { - name.remove_prefix(sizeof("enum")); - } - if (name.size() > sizeof("class") && name[0] == 'c' && name[1] == 'l' && name[2] == 'a' && name[3] == 's' && name[4] == 's' && name[5] == ' ') { - name.remove_prefix(sizeof("class")); - } - if (name.size() > sizeof("struct") && name[0] == 's' && name[1] == 't' && name[2] == 'r' && name[3] == 'u' && name[4] == 'c' && name[5] == 't' && name[6] == ' ') { - name.remove_prefix(sizeof("struct")); - } -# endif while (name.back() == ' ') { name.remove_suffix(1); }