fix: make std::bitset formattable again (#3660)

* fix: make std::bitset formattable again

It used to be formattable via operator<<(ostream&) implicitly. Make it
formattable again, but this time via formatter specialization.

* fix: make nested_formatter constexpr default constructible
This commit is contained in:
Giel van Schijndel
2023-10-03 18:53:47 +02:00
committed by GitHub
parent f918289363
commit f76603f21e
3 changed files with 36 additions and 0 deletions

View File

@ -237,6 +237,14 @@ TEST(std_test, format_const_bit_reference) {
EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false");
}
TEST(std_test, format_bitset) {
const std::bitset<6> bs(42);
EXPECT_EQ(fmt::format("{}", bs), "101010");
EXPECT_EQ(fmt::format("{:.4}", bs), "101010");
EXPECT_EQ(fmt::format("{:0>8}", bs), "00101010");
EXPECT_EQ(fmt::format("{:-^12}", bs), "---101010---");
}
TEST(std_test, format_atomic) {
std::atomic<bool> b(false);
EXPECT_EQ(fmt::format("{}", b), "false");