From 571c02d475708fba0a84d518fdf20587800ccecd Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Tue, 24 Jun 2025 02:02:11 +0500 Subject: [PATCH] Add xchar support for std::byte formatter (#4480) Signed-off-by: Vladislav Shchapov --- include/fmt/format.h | 5 +++-- test/xchar-test.cc | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 8ee403e8..6a9d8bc6 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3904,13 +3904,14 @@ constexpr auto format_as(Enum e) noexcept -> underlying_t { } // namespace enums #ifdef __cpp_lib_byte -template <> struct formatter : formatter { +template +struct formatter : formatter { static auto format_as(std::byte b) -> unsigned char { return static_cast(b); } template auto format(std::byte b, Context& ctx) const -> decltype(ctx.out()) { - return formatter::format(format_as(b), ctx); + return formatter::format(format_as(b), ctx); } }; #endif diff --git a/test/xchar-test.cc b/test/xchar-test.cc index 44b19e87..a94c1bd2 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -171,6 +171,13 @@ TEST(xchar_test, join) { EXPECT_EQ(fmt::format(L"({})", fmt::join(t, L", ")), L"(a, 1, 2)"); } +#ifdef __cpp_lib_byte +TEST(xchar_test, join_bytes) { + auto v = std::vector{std::byte(1), std::byte(2), std::byte(3)}; + EXPECT_EQ(fmt::format(L"{}", fmt::join(v, L", ")), L"1, 2, 3"); +} +#endif + enum streamable_enum {}; std::wostream& operator<<(std::wostream& os, streamable_enum) {