Add member format_as for std

This commit is contained in:
Victor Zverovich
2024-09-20 07:08:47 -07:00
parent 6d43c755bc
commit a197a994c5
4 changed files with 38 additions and 19 deletions

View File

@ -42,6 +42,7 @@
#ifndef FMT_MODULE
# include <cmath> // std::signbit
# include <cstddef> // std::byte
# include <cstdint> // uint32_t
# include <cstring> // std::memcpy
# include <initializer_list> // std::initializer_list
@ -3919,6 +3920,18 @@ constexpr auto format_as(Enum e) noexcept -> underlying_t<Enum> {
}
} // namespace enums
#ifdef __cpp_lib_byte
template <> struct formatter<std::byte> : formatter<unsigned> {
static auto format_as(std::byte b) -> unsigned char {
return static_cast<unsigned char>(b);
}
template <typename Context>
auto format(std::byte b, Context& ctx) const -> decltype(ctx.out()) {
return formatter<unsigned>::format(format_as(b), ctx);
}
};
#endif
class bytes {
private:
string_view data_;