Browse Source
logging/log: use `underlying_type` instead of hardcoding types
pull/15/merge
liushuyu
4 years ago
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437
1 changed files with
4 additions and
2 deletions
-
src/common/logging/log.h
|
|
@ -16,10 +16,12 @@ |
|
|
// a generic formatter for enum classes (<= 32 bits) |
|
|
// a generic formatter for enum classes (<= 32 bits) |
|
|
#if FMT_VERSION >= 80100 |
|
|
#if FMT_VERSION >= 80100 |
|
|
template <typename T> |
|
|
template <typename T> |
|
|
struct fmt::formatter<T, std::enable_if_t<std::is_enum_v<T>, char>> : formatter<u32> { |
|
|
|
|
|
|
|
|
struct fmt::formatter<T, std::enable_if_t<std::is_enum_v<T>, char>> |
|
|
|
|
|
: formatter<std::underlying_type_t<T>> { |
|
|
template <typename FormatContext> |
|
|
template <typename FormatContext> |
|
|
auto format(const T& value, FormatContext& ctx) -> decltype(ctx.out()) { |
|
|
auto format(const T& value, FormatContext& ctx) -> decltype(ctx.out()) { |
|
|
return fmt::formatter<u32>::format(static_cast<u32>(value), ctx); |
|
|
|
|
|
|
|
|
return fmt::formatter<std::underlying_type_t<T>>::format( |
|
|
|
|
|
static_cast<std::underlying_type_t<T>>(value), ctx); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
#endif |
|
|
#endif |
|
|
|