fix nameof_type
This commit is contained in:
parent
8df003ea53
commit
d69bd50d9c
2 changed files with 7 additions and 16 deletions
|
@ -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 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.
|
* Enum value must be in range `[-256, 256]`. If you need another range, add specialization enum_range for necessary enum type.
|
||||||
```cpp
|
```cpp
|
||||||
#include <nameof.hpp>
|
#include <nameof.hpp>
|
||||||
|
|
|
@ -130,16 +130,16 @@ struct identity final {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename... T>
|
||||||
[[nodiscard]] constexpr std::string_view nameof_type_impl() noexcept {
|
[[nodiscard]] constexpr std::string_view nameof_type_impl() noexcept {
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
std::string_view name{__PRETTY_FUNCTION__};
|
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 prefix = sizeof("std::string_view nameof::detail::nameof_type_impl() [T = <nameof::detail::identity<") - 1;
|
||||||
constexpr auto suffix = sizeof(">]") - 1;
|
constexpr auto suffix = sizeof(">>]") - 1;
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
std::string_view name{__PRETTY_FUNCTION__};
|
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 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<char>]") - 1;
|
constexpr auto suffix = sizeof(">}; std::string_view = std::basic_string_view<char>]") - 1;
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
std::string_view name{__FUNCSIG__};
|
std::string_view name{__FUNCSIG__};
|
||||||
constexpr auto prefix = sizeof("class std::basic_string_view<char,struct std::char_traits<char> > __cdecl nameof::detail::nameof_type_impl<struct nameof::detail::identity<") - 1;
|
constexpr auto prefix = sizeof("class std::basic_string_view<char,struct std::char_traits<char> > __cdecl nameof::detail::nameof_type_impl<struct nameof::detail::identity<") - 1;
|
||||||
|
@ -151,17 +151,6 @@ template <typename T>
|
||||||
#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
|
#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
|
||||||
name.remove_prefix(prefix);
|
name.remove_prefix(prefix);
|
||||||
name.remove_suffix(suffix);
|
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() == ' ') {
|
while (name.back() == ' ') {
|
||||||
name.remove_suffix(1);
|
name.remove_suffix(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue