diff --git a/include/nameof.hpp b/include/nameof.hpp index ccf0a4c..3154847 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -1115,61 +1115,57 @@ template // Obtains name of static storage enum variable. // This version is much lighter on the compile times and is not restricted to the enum_range limitation. -template -[[nodiscard]] constexpr auto nameof_enum() noexcept -> detail::enable_if_enum_t { +template = 0> +[[nodiscard]] constexpr auto nameof_enum() noexcept { using D = std::decay_t; + static_assert(std::is_enum_v, "nameof::nameof_enum requires member enum type."); static_assert(detail::nameof_enum_supported::value, "nameof::nameof_enum unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); - constexpr string_view name = detail::enum_name_v; - static_assert(!name.empty(), "Enum value does not have a name."); - return name; + return detail::enum_name_v; } // Obtains name of type, reference and cv-qualifiers are ignored. template [[nodiscard]] constexpr string_view nameof_type() noexcept { - static_assert(detail::nameof_type_supported::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); using U = detail::identity>; - constexpr string_view name = detail::type_name_v; - static_assert(!name.empty(), "Type does not have a name."); - return name; + static_assert(detail::nameof_type_supported::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); + return detail::type_name_v; } // Obtains full name of type, with reference and cv-qualifiers. template [[nodiscard]] constexpr string_view nameof_full_type() noexcept { - static_assert(detail::nameof_type_supported::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); using U = detail::identity; - constexpr string_view name = detail::type_name_v; - static_assert(!name.empty(), "Type does not have a full name."); - return name; + static_assert(detail::nameof_type_supported::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); + return detail::type_name_v; } // Obtains short name of type. -template -[[nodiscard]] constexpr auto nameof_short_type() noexcept -> detail::enable_if_has_short_name_t { - static_assert(detail::nameof_type_supported::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); +template = 0> +[[nodiscard]] constexpr auto nameof_short_type() noexcept { using U = detail::identity>; + static_assert(detail::nameof_type_supported::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); + static_assert(!std::is_array_v && !std::is_pointer_v, "nameof::nameof_member requires non array and non pointer type."); constexpr string_view name = detail::pretty_name(detail::type_name_v); static_assert(!name.empty(), "Type does not have a short name."); - return name; + return cstring{name}; } // Obtains name of member. -template -[[nodiscard]] constexpr auto nameof_member() noexcept -> std::enable_if_t, string_view> { - static_assert(detail::nameof_member_supported::value, "nameof::nameof_member unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); - constexpr string_view name = detail::member_name_v; - static_assert(!name.empty(), "Member does not have a name."); - return name; +template , int> = 0> +[[nodiscard]] constexpr auto nameof_member() noexcept { + using U = decltype(V); + static_assert(std::is_member_pointer_v, "nameof::nameof_member requires member pointer type."); + static_assert(detail::nameof_member_supported::value, "nameof::nameof_member unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); + return detail::member_name_v; } // Obtains name of a function, a global or class static variable. -template -[[nodiscard]] constexpr auto nameof_pointer() noexcept -> std::enable_if_t, string_view> { - static_assert(detail::nameof_pointer_supported::value, "nameof::nameof_pointer unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); - constexpr string_view name = detail::pointer_name_v; - static_assert(!name.empty(), "Pointer does not have a name."); - return name; +template , int> = 0> +[[nodiscard]] constexpr auto nameof_pointer() noexcept { + using U = decltype(V); + static_assert(std::is_pointer_v, "nameof::nameof_pointer requires pointer type."); + static_assert(detail::nameof_pointer_supported::value, "nameof::nameof_pointer unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); + return detail::pointer_name_v; } } // namespace nameof