From 4a6eadbde0619b249bde5e019d69e3e8afb02260 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 3 Dec 2020 08:50:28 -0800 Subject: [PATCH] Make std::byte formattabe (#1981) --- include/fmt/format.h | 5 ++++- test/format-test.cc | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index afcb32f5cf3e..8ec527e6a0a7 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3538,7 +3538,7 @@ struct formatter : formatter { \ template \ auto format(Type const& val, FormatContext& ctx) -> decltype(ctx.out()) { \ - return formatter::format(val, ctx); \ + return formatter::format(static_cast(val), ctx); \ } \ } @@ -3552,6 +3552,9 @@ FMT_FORMAT_AS(Char*, const Char*); FMT_FORMAT_AS(std::basic_string, basic_string_view); FMT_FORMAT_AS(std::nullptr_t, const void*); FMT_FORMAT_AS(detail::std_string_view, basic_string_view); +#if __cplusplus >= 201703L +FMT_FORMAT_AS(std::byte, unsigned); +#endif template struct formatter : formatter { diff --git a/test/format-test.cc b/test/format-test.cc index 205997ec827f..bb10460f40f4 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1762,6 +1762,13 @@ TEST(FormatTest, JoinArg) { #endif } +#if __cplusplus >= 201703L +TEST(FormatTest, JoinBytes) { + std::vector v = {std::byte(1), std::byte(2), std::byte(3)}; + EXPECT_EQ("1, 2, 3", fmt::format("{}", fmt::join(v, ", "))); +} +#endif + template std::string str(const T& value) { return fmt::format("{}", value); }