mirror of
https://github.com/fmtlib/fmt.git
synced 2025-06-24 17:01:42 +02:00
Add xchar support for std::byte formatter (#4480)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
committed by
GitHub
parent
f4345467fc
commit
571c02d475
@ -3904,13 +3904,14 @@ constexpr auto format_as(Enum e) noexcept -> underlying_t<Enum> {
|
||||
} // namespace enums
|
||||
|
||||
#ifdef __cpp_lib_byte
|
||||
template <> struct formatter<std::byte> : formatter<unsigned> {
|
||||
template <typename Char>
|
||||
struct formatter<std::byte, Char> : formatter<unsigned, Char> {
|
||||
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);
|
||||
return formatter<unsigned, Char>::format(format_as(b), ctx);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
@ -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>{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) {
|
||||
|
Reference in New Issue
Block a user