Add 'n' specifier for tuple and pair (#4107)

This commit is contained in:
Hugo Sales
2024-08-05 22:56:44 +01:00
committed by GitHub
parent 9f269062a7
commit 9f0c0c468b
2 changed files with 11 additions and 1 deletions

View File

@@ -170,6 +170,8 @@ TEST(ranges_test, format_adl_begin_end) {
TEST(ranges_test, format_pair) {
auto p = std::pair<int, float>(42, 1.5f);
EXPECT_EQ(fmt::format("{}", p), "(42, 1.5)");
EXPECT_EQ(fmt::format("{:}", p), "(42, 1.5)");
EXPECT_EQ(fmt::format("{:n}", p), "421.5");
}
struct unformattable {};
@@ -178,6 +180,7 @@ TEST(ranges_test, format_tuple) {
auto t =
std::tuple<int, float, std::string, char>(42, 1.5f, "this is tuple", 'i');
EXPECT_EQ(fmt::format("{}", t), "(42, 1.5, \"this is tuple\", 'i')");
EXPECT_EQ(fmt::format("{:n}", t), "421.5\"this is tuple\"'i'");
EXPECT_EQ(fmt::format("{}", std::tuple<>()), "()");