Skip to content

Commit 3f16643

Browse files
committed
use cstring for allow NTTP
1 parent 174b23d commit 3f16643

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

include/nameof.hpp

+25-29
Original file line numberDiff line numberDiff line change
@@ -1115,61 +1115,57 @@ template <typename E>
11151115

11161116
// Obtains name of static storage enum variable.
11171117
// This version is much lighter on the compile times and is not restricted to the enum_range limitation.
1118-
template <auto V>
1119-
[[nodiscard]] constexpr auto nameof_enum() noexcept -> detail::enable_if_enum_t<decltype(V), string_view> {
1118+
template <auto V, detail::enable_if_enum_t<decltype(V), int> = 0>
1119+
[[nodiscard]] constexpr auto nameof_enum() noexcept {
11201120
using D = std::decay_t<decltype(V)>;
1121+
static_assert(std::is_enum_v<D>, "nameof::nameof_enum requires member enum type.");
11211122
static_assert(detail::nameof_enum_supported<D>::value, "nameof::nameof_enum unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
1122-
constexpr string_view name = detail::enum_name_v<D, V>;
1123-
static_assert(!name.empty(), "Enum value does not have a name.");
1124-
return name;
1123+
return detail::enum_name_v<D, V>;
11251124
}
11261125

11271126
// Obtains name of type, reference and cv-qualifiers are ignored.
11281127
template <typename T>
11291128
[[nodiscard]] constexpr string_view nameof_type() noexcept {
1130-
static_assert(detail::nameof_type_supported<T>::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
11311129
using U = detail::identity<detail::remove_cvref_t<T>>;
1132-
constexpr string_view name = detail::type_name_v<U>;
1133-
static_assert(!name.empty(), "Type does not have a name.");
1134-
return name;
1130+
static_assert(detail::nameof_type_supported<U>::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
1131+
return detail::type_name_v<U>;
11351132
}
11361133

11371134
// Obtains full name of type, with reference and cv-qualifiers.
11381135
template <typename T>
11391136
[[nodiscard]] constexpr string_view nameof_full_type() noexcept {
1140-
static_assert(detail::nameof_type_supported<T>::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
11411137
using U = detail::identity<T>;
1142-
constexpr string_view name = detail::type_name_v<U>;
1143-
static_assert(!name.empty(), "Type does not have a full name.");
1144-
return name;
1138+
static_assert(detail::nameof_type_supported<U>::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
1139+
return detail::type_name_v<U>;
11451140
}
11461141

11471142
// Obtains short name of type.
1148-
template <typename T>
1149-
[[nodiscard]] constexpr auto nameof_short_type() noexcept -> detail::enable_if_has_short_name_t<T, string_view> {
1150-
static_assert(detail::nameof_type_supported<T>::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
1143+
template <typename T, detail::enable_if_has_short_name_t<T, int> = 0>
1144+
[[nodiscard]] constexpr auto nameof_short_type() noexcept {
11511145
using U = detail::identity<detail::remove_cvref_t<T>>;
1146+
static_assert(detail::nameof_type_supported<U>::value, "nameof::nameof_type unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
1147+
static_assert(!std::is_array_v<T> && !std::is_pointer_v<T>, "nameof::nameof_member requires non array and non pointer type.");
11521148
constexpr string_view name = detail::pretty_name(detail::type_name_v<U>);
11531149
static_assert(!name.empty(), "Type does not have a short name.");
1154-
return name;
1150+
return cstring<name.size()>{name};
11551151
}
11561152

11571153
// Obtains name of member.
1158-
template <auto V>
1159-
[[nodiscard]] constexpr auto nameof_member() noexcept -> std::enable_if_t<std::is_member_pointer_v<decltype(V)>, string_view> {
1160-
static_assert(detail::nameof_member_supported<decltype(V)>::value, "nameof::nameof_member unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
1161-
constexpr string_view name = detail::member_name_v<V>;
1162-
static_assert(!name.empty(), "Member does not have a name.");
1163-
return name;
1154+
template <auto V, std::enable_if_t<std::is_member_pointer_v<decltype(V)>, int> = 0>
1155+
[[nodiscard]] constexpr auto nameof_member() noexcept {
1156+
using U = decltype(V);
1157+
static_assert(std::is_member_pointer_v<U>, "nameof::nameof_member requires member pointer type.");
1158+
static_assert(detail::nameof_member_supported<U>::value, "nameof::nameof_member unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
1159+
return detail::member_name_v<V>;
11641160
}
11651161

11661162
// Obtains name of a function, a global or class static variable.
1167-
template <auto V>
1168-
[[nodiscard]] constexpr auto nameof_pointer() noexcept -> std::enable_if_t<std::is_pointer_v<decltype(V)>, string_view> {
1169-
static_assert(detail::nameof_pointer_supported<decltype(V)>::value, "nameof::nameof_pointer unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
1170-
constexpr string_view name = detail::pointer_name_v<V>;
1171-
static_assert(!name.empty(), "Pointer does not have a name.");
1172-
return name;
1163+
template <auto V, std::enable_if_t<std::is_pointer_v<decltype(V)>, int> = 0>
1164+
[[nodiscard]] constexpr auto nameof_pointer() noexcept {
1165+
using U = decltype(V);
1166+
static_assert(std::is_pointer_v<U>, "nameof::nameof_pointer requires pointer type.");
1167+
static_assert(detail::nameof_pointer_supported<U>::value, "nameof::nameof_pointer unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
1168+
return detail::pointer_name_v<V>;
11731169
}
11741170

11751171
} // namespace nameof

0 commit comments

Comments
 (0)