diff --git a/include/fmt/format.h b/include/fmt/format.h index 8030e9a5..a98e41d9 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3751,8 +3751,11 @@ template enable_if_t::value == type::custom_type, OutputIt> { + auto formatter = typename Context::template formatter_type(); + auto parse_ctx = typename Context::parse_context_type({}); + formatter.parse(parse_ctx); auto ctx = Context(out, {}, {}); - return typename Context::template formatter_type().format(value, ctx); + return formatter.format(value, ctx); } // An argument visitor that formats the argument and writes it via the output diff --git a/test/ranges-test.cc b/test/ranges-test.cc index caf42758..ba5c464d 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -59,13 +59,18 @@ TEST(ranges_test, format_vector) { EXPECT_EQ(fmt::format("{:n:n:}", vvc), "a, b, c, a, b, c"); } -TEST(ranges_test, format_vector2) { +TEST(ranges_test, format_nested_vector) { auto v = std::vector>{{1, 2}, {3, 5}, {7, 11}}; EXPECT_EQ(fmt::format("{}", v), "[[1, 2], [3, 5], [7, 11]]"); EXPECT_EQ(fmt::format("{:::#x}", v), "[[0x1, 0x2], [0x3, 0x5], [0x7, 0xb]]"); EXPECT_EQ(fmt::format("{:n:n:#x}", v), "0x1, 0x2, 0x3, 0x5, 0x7, 0xb"); } +TEST(ranges_test, to_string_vector) { + auto v = std::vector{"a", "b", "c"}; + EXPECT_EQ(fmt::to_string(v), "[\"a\", \"b\", \"c\"]"); +} + TEST(ranges_test, format_map) { auto m = std::map{{"one", 1}, {"two", 2}}; EXPECT_EQ(fmt::format("{}", m), "{\"one\": 1, \"two\": 2}");