diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index a9d4b8ea..838ac7df 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -9,6 +9,8 @@ #define FMT_FORMAT_INL_H_ #ifndef FMT_MODULE +# include // ptrdiff_t + # include # include // errno # include diff --git a/include/fmt/format.h b/include/fmt/format.h index cf61a8d2..3f67b22a 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -51,9 +51,8 @@ # include // malloc, free # include // memcpy -# include // std::signbit -# include // std::byte -# include // std::numeric_limits +# include // std::signbit +# include // std::numeric_limits # if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI) // Workaround for pre gcc 5 libstdc++. # include // std::allocator_traits @@ -4069,19 +4068,6 @@ constexpr auto format_as(Enum e) noexcept -> underlying_t { } } // namespace enums -#ifdef __cpp_lib_byte -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); - } -}; -#endif - struct bytes { string_view data; diff --git a/include/fmt/std.h b/include/fmt/std.h index ad71d2b1..8a9dd8c4 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -15,7 +15,8 @@ # include # include # include -# include +# include // std::byte +# include // std::exception # include // std::reference_wrapper # include # include @@ -666,6 +667,19 @@ struct formatter +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); + } +}; +#endif + template struct formatter, Char, enable_if_t::value>> diff --git a/test/compile-test.cc b/test/compile-test.cc index 5e381ada..9975b441 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -75,9 +75,6 @@ TEST(compile_test, format_default) { EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), test_formattable())); auto t = std::chrono::system_clock::now(); EXPECT_EQ(fmt::format("{}", t), fmt::format(FMT_COMPILE("{}"), t)); -# ifdef __cpp_lib_byte - EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), std::byte{42})); -# endif } TEST(compile_test, format_escape) { diff --git a/test/format-test.cc b/test/format-test.cc index 3c4a3964..c649aa4d 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2611,14 +2611,6 @@ TEST(format_test, invalid_glibc_buffer) { } #endif // FMT_USE_FCNTL -#ifdef __cpp_lib_byte -TEST(base_test, format_byte) { - auto s = std::string(); - fmt::format_to(std::back_inserter(s), "{}", std::byte(42)); - EXPECT_EQ(s, "42"); -} -#endif - // Only defined after the test case. struct incomplete_type; extern const incomplete_type& external_instance; diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 2d84840d..9ff6b9b1 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -395,13 +395,6 @@ TEST(ranges_test, join) { EXPECT_EQ(fmt::format("{}", join(v4, " ")), "0 1 0"); } -#ifdef __cpp_lib_byte -TEST(ranges_test, join_bytes) { - auto v = std::vector{std::byte(1), std::byte(2), std::byte(3)}; - EXPECT_EQ(fmt::format("{}", fmt::join(v, ", ")), "1, 2, 3"); -} -#endif - TEST(ranges_test, join_tuple) { // Value tuple args. auto t1 = std::tuple('a', 1, 2.0f); diff --git a/test/std-test.cc b/test/std-test.cc index b3ba57c3..a3c54dc8 100644 --- a/test/std-test.cc +++ b/test/std-test.cc @@ -460,6 +460,14 @@ TEST(std_test, format_bitset) { EXPECT_EQ(fmt::format("{:-^12}", bs), "---101010---"); } +#ifdef __cpp_lib_byte +TEST(base_test, format_byte) { + auto s = std::string(); + fmt::format_to(std::back_inserter(s), "{}", std::byte(42)); + EXPECT_EQ(s, "42"); +} +#endif + TEST(std_test, format_atomic) { std::atomic b(false); EXPECT_EQ(fmt::format("{}", b), "false");