improving

This commit is contained in:
neargye 2019-07-25 18:58:42 +05:00
parent 583f889aa2
commit b35e1e6133

View file

@ -181,34 +181,31 @@ template <typename E, E V>
[[nodiscard]] constexpr std::string_view nameof_enum_impl() noexcept { [[nodiscard]] constexpr std::string_view nameof_enum_impl() noexcept {
static_assert(std::is_enum_v<E>, "nameof::nameof_enum_impl requires enum type."); static_assert(std::is_enum_v<E>, "nameof::nameof_enum_impl requires enum type.");
#if defined(__clang__) #if defined(__clang__)
constexpr auto name = nameof_impl<void>({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2}); return nameof_impl<void>({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2});
#elif defined(__GNUC__) && __GNUC__ >= 9 #elif defined(__GNUC__) && __GNUC__ >= 9
constexpr auto name = nameof_impl<void>({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 51}); return nameof_impl<void>({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 51});
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
constexpr auto name = nameof_impl<void>({__FUNCSIG__, sizeof(__FUNCSIG__) - 17}); return nameof_impl<void>({__FUNCSIG__, sizeof(__FUNCSIG__) - 17});
#else #else
constexpr std::string_view name; // Unsupported compiler. return {}; // Unsupported compiler.
#endif #endif
return name;
} }
template <typename E, int O, int... I> template <typename E, int O, int... I>
[[nodiscard]] constexpr auto enum_names_impl(std::integer_sequence<int, I...>) noexcept { [[nodiscard]] constexpr auto enum_names_impl(std::integer_sequence<int, I...>) noexcept {
static_assert(std::is_enum_v<E>, "nameof::detail::enum_names_impl requires enum type."); static_assert(std::is_enum_v<E>, "nameof::detail::enum_names_impl requires enum type.");
constexpr std::array<std::string_view, sizeof...(I)> names{{nameof_enum_impl<E, static_cast<E>(I + O)>()...}};
return names; return std::array<std::string_view, sizeof...(I)>{{nameof_enum_impl<E, static_cast<E>(I + O)>()...}};
} }
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__)
constexpr std::string_view name{__PRETTY_FUNCTION__ + 83, sizeof(__PRETTY_FUNCTION__) - 87}; std::string_view name{__PRETTY_FUNCTION__ + 83, sizeof(__PRETTY_FUNCTION__) - 87};
#elif defined(__GNUC__) #elif defined(__GNUC__)
constexpr std::string_view name{__PRETTY_FUNCTION__ + 98, sizeof(__PRETTY_FUNCTION__) - 151}; std::string_view name{__PRETTY_FUNCTION__ + 98, sizeof(__PRETTY_FUNCTION__) - 151};
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
constexpr std::string_view name{__FUNCSIG__ + 139, sizeof(__FUNCSIG__) - 157}; std::string_view name{__FUNCSIG__ + 139, sizeof(__FUNCSIG__) - 157};
#else #else
return {}; // Unsupported compiler. return {}; // Unsupported compiler.
#endif #endif