@@ -1115,61 +1115,57 @@ template <typename E>
1115
1115
1116
1116
// Obtains name of static storage enum variable.
1117
1117
// 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 {
1120
1120
using D = std::decay_t <decltype (V)>;
1121
+ static_assert (std::is_enum_v<D>, " nameof::nameof_enum requires member enum type." );
1121
1122
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>;
1125
1124
}
1126
1125
1127
1126
// Obtains name of type, reference and cv-qualifiers are ignored.
1128
1127
template <typename T>
1129
1128
[[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)." );
1131
1129
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>;
1135
1132
}
1136
1133
1137
1134
// Obtains full name of type, with reference and cv-qualifiers.
1138
1135
template <typename T>
1139
1136
[[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)." );
1141
1137
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>;
1145
1140
}
1146
1141
1147
1142
// 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 {
1151
1145
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." );
1152
1148
constexpr string_view name = detail::pretty_name (detail::type_name_v<U>);
1153
1149
static_assert (!name.empty (), " Type does not have a short name." );
1154
- return name;
1150
+ return cstring< name. size ()>{name} ;
1155
1151
}
1156
1152
1157
1153
// 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> ;
1164
1160
}
1165
1161
1166
1162
// 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> ;
1173
1169
}
1174
1170
1175
1171
} // namespace nameof
0 commit comments