Example
int main() {
std::cout << std::format("{}", std::vector{1, 2, 3}); // [1, 2, 3]
std::cout << std::format("{:n}", std::vector{1, 2, 3}); // 1, 2, 3
std::cout << std::format("{}", std::tuple{'1', 2., 3}); // ('1', 2, 3)
std::cout << std::format("{}", std::vector{std::pair{'a',1}, std::pair{'b',2}}); // [(a, 1), (b, 2)]
std::cout << std::format("{:m}", std::vector{std::pair{'a',1}, std::pair{'b',2}}); // {(a, 1), (b, 2)}
}
Puzzle
Can you add required format strings to satisfy the formatted output?
int main() {
using namespace boost::ut;
using namespace std::literals::string_literals;
expect(R"(("hello", 42))"s == std::format("TODO", std::tuple{"hello", 42}));
expect("[0x1, 0x2, 0x3]"s == std::format("TODO", std::vector{1, 2, 3}));
expect("[*1*, *2*, *3*]"s == std::format("TODO", std::vector{1, 2, 3}));
expect("Q L"s == std::format("TODO", std::string{'Q', ' ', 'L'}));
expect(R"(["a", "bc"])"s == std::format("TODO", std::vector{std::vector{'a'}, std::vector{'b','c'}}));
expect("[[97], [98, 99]]"s == std::format("TODO", std::vector{std::vector{'a'}, std::vector{'b','c'}}));
}
Solutions
expect(R"(("hello", 42))"s == std::format("{}", std::tuple{"hello", 42}));
expect("[0x1, 0x2, 0x3]"s == std::format("{::#x}", std::vector{1, 2, 3}));
expect("[*1*, *2*, *3*]"s == std::format("{::*^3}", std::vector{1, 2, 3}));
expect("Q L"s == std::format("{}", std::string{'Q', ' ', 'L'}));
expect(R"(["a", "bc"])"s == std::format("{::?s}", std::vector{std::vector{'a'}, std::vector{'b','c'}}));
expect("[[97], [98, 99]]"s == std::format("{:::d}", std::vector{std::vector{'a'}, std::vector{'b','c'}}));
expect(R"(("hello", 42))"s == std::format("{}", std::tuple{"hello", 42}));
expect("[0x1, 0x2, 0x3]"s == std::format("{::#x}", std::vector{1, 2, 3}));
expect("[*1*, *2*, *3*]"s == std::format("{::*^3}", std::vector{1, 2, 3}));
expect("Q L"s == std::format("{:s}", std::string{'Q', ' ', 'L'}));
expect(R"(["a", "bc"])"s ==
std::format("{::?s}",
std::vector{std::vector{'a'}, std::vector{'b', 'c'}}));
expect("[[97], [98, 99]]"s ==
std::format("{:::d}",
std::vector{std::vector{'a'}, std::vector{'b', 'c'}}));
expect(R"(("hello", 42))"s == std::format("{}", std::tuple{"hello", 42}));
expect("[0x1, 0x2, 0x3]"s == std::format("{::#x}", std::vector{1, 2, 3}));
expect("[*1*, *2*, *3*]"s == std::format("{::*^3}", std::vector{1, 2, 3}));
expect("Q L"s == std::format("{}", std::string{'Q', ' ', 'L'}));
expect(R"(["a", "bc"])"s ==
std::format("{::?s}",
std::vector{std::vector{'a'}, std::vector{'b', 'c'}}));
expect("[[97], [98, 99]]"s ==
std::format("{:::d}",
std::vector{std::vector{'a'}, std::vector{'b', 'c'}}));
expect(R"(("hello", 42))"s == std::format("{}", std::tuple{"hello", 42}));
expect("[0x1, 0x2, 0x3]"s == std::format("{::#x}", std::vector{1, 2, 3}));
expect("[*1*, *2*, *3*]"s == std::format("{::*^3}", std::vector{1, 2, 3}));
expect("Q L"s == std::format("{:'^3}", std::string{'Q', ' ', 'L'}));
expect(R"(["a", "bc"])"s ==
std::format("{::?s}",
std::vector{std::vector{'a'}, std::vector{'b', 'c'}}));
expect("[[97], [98, 99]]"s ==
std::format("{:::d}",
std::vector{std::vector{'a'}, std::vector{'b', 'c'}}));
expect(R"(("hello", 42))"s == std::format("{}", std::tuple{"hello", 42}));
expect("[0x1, 0x2, 0x3]"s == std::format("{::#x}", std::vector{1, 2, 3}));
expect("[*1*, *2*, *3*]"s == std::format("{::*^3}", std::vector{1, 2, 3}));
expect("Q L"s == std::format("{}", std::string{'Q', ' ', 'L'}));
expect(R"(["a", "bc"])"s ==
std::format("{::?s}",
std::vector{std::vector{'a'}, std::vector{'b', 'c'}}));
expect("[[97], [98, 99]]"s ==
std::format("{:::d}",
std::vector{std::vector{'a'}, std::vector{'b', 'c'}}));