diff --git a/include/fmt/format.h b/include/fmt/format.h index afcb32f5..8ec527e6 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 205997ec..bb10460f 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); }