Skip to content

Commit 4e9e5a1

Browse files
authored
src: add enum handle for ToStringHelper + formatting
Fixes: #56666 PR-URL: #56829 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 79d0ed7 commit 4e9e5a1

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/debug_utils-inl.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ struct ToStringHelper {
3838

3939
template <typename T,
4040
typename test_for_number = typename std::
41-
enable_if<std::is_arithmetic<T>::value, bool>::type,
41+
enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>, bool>,
4242
typename dummy = bool>
43-
static std::string Convert(const T& value) { return std::to_string(value); }
43+
static std::string Convert(const T& value) {
44+
return std::to_string(value);
45+
}
4446
static std::string_view Convert(const char* value) {
4547
return value != nullptr ? value : "(null)";
4648
}
@@ -58,8 +60,7 @@ struct ToStringHelper {
5860
const char* digits = "0123456789abcdef";
5961
do {
6062
unsigned digit = v & ((1 << BASE_BITS) - 1);
61-
*--ptr =
62-
(BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
63+
*--ptr = (BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
6364
} while ((v >>= BASE_BITS) != 0);
6465
return ptr;
6566
}
@@ -139,12 +140,10 @@ std::string COLD_NOINLINE SPrintFImpl( // NOLINT(runtime/string)
139140
ret += node::ToUpper(ToBaseString<4>(arg));
140141
break;
141142
case 'p': {
142-
CHECK(std::is_pointer<typename std::remove_reference<Arg>::type>::value);
143+
CHECK(std::is_pointer_v<typename std::remove_reference_t<Arg>>);
143144
char out[20];
144-
int n = snprintf(out,
145-
sizeof(out),
146-
"%p",
147-
*reinterpret_cast<const void* const*>(&arg));
145+
int n = snprintf(
146+
out, sizeof(out), "%p", *reinterpret_cast<const void* const*>(&arg));
148147
CHECK_GE(n, 0);
149148
ret += out;
150149
break;

0 commit comments

Comments
 (0)