Skip to content

Commit 0f0fb76

Browse files
committed
src: add enum handle for ToStringHelper + formatting
Fixes: #56666
1 parent ec26b1c commit 0f0fb76

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/debug_utils-inl.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ 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>
4343
static std::string Convert(const T& value) { return std::to_string(value); }
4444
static std::string_view Convert(const char* value) {
@@ -58,8 +58,7 @@ struct ToStringHelper {
5858
const char* digits = "0123456789abcdef";
5959
do {
6060
unsigned digit = v & ((1 << BASE_BITS) - 1);
61-
*--ptr =
62-
(BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
61+
*--ptr = (BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
6362
} while ((v >>= BASE_BITS) != 0);
6463
return ptr;
6564
}
@@ -139,12 +138,10 @@ std::string COLD_NOINLINE SPrintFImpl( // NOLINT(runtime/string)
139138
ret += node::ToUpper(ToBaseString<4>(arg));
140139
break;
141140
case 'p': {
142-
CHECK(std::is_pointer<typename std::remove_reference<Arg>::type>::value);
141+
CHECK(std::is_pointer_v<typename std::remove_reference_t<Arg>>);
143142
char out[20];
144-
int n = snprintf(out,
145-
sizeof(out),
146-
"%p",
147-
*reinterpret_cast<const void* const*>(&arg));
143+
int n = snprintf(
144+
out, sizeof(out), "%p", *reinterpret_cast<const void* const*>(&arg));
148145
CHECK_GE(n, 0);
149146
ret += out;
150147
break;

0 commit comments

Comments
 (0)