diff --git a/include/fmt/format.h b/include/fmt/format.h index 46f58a30438ff..80c0127b01c71 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3633,9 +3633,11 @@ template struct formatter, Char> { private: using value_type = typename std::iterator_traits::value_type; + using mapper = detail::arg_mapper>; + using mapped_type = decltype(mapper().map(std::declval())); using formatter_type = - conditional_t>::value, - formatter, + conditional_t::value, + formatter, detail::fallback_formatter>; formatter_type value_formatter_; @@ -3652,11 +3654,11 @@ struct formatter, Char> { auto it = value.begin; auto out = ctx.out(); if (it != value.end) { - out = value_formatter_.format(*it++, ctx); + out = value_formatter_.format(mapper().map(*it++), ctx); while (it != value.end) { out = detail::copy_str(value.sep.begin(), value.sep.end(), out); ctx.advance_to(out); - out = value_formatter_.format(*it++, ctx); + out = value_formatter_.format(mapper().map(*it++), ctx); } } return out; diff --git a/test/format-test.cc b/test/format-test.cc index b3b3db05e5733..be8763a8bcfbb 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1609,6 +1609,8 @@ TEST(format_test, bytes) { EXPECT_EQ(10, s.size()); } +enum test_enum { zero, one }; + TEST(format_test, join) { using fmt::join; int v1[3] = {1, 2, 3}; @@ -1632,6 +1634,9 @@ TEST(format_test, join) { EXPECT_EQ("(1, 2, 3)", fmt::format("({})", join(v1, ", "))); EXPECT_EQ("(+01.20, +03.40)", fmt::format("({:+06.2f})", join(v2, ", "))); + + auto v4 = std::vector{zero, one, zero}; + EXPECT_EQ("0 1 0", fmt::format("{}", join(v4, " "))); } #ifdef __cpp_lib_byte @@ -1763,9 +1768,7 @@ TEST(format_test, udl_pass_user_defined_object_as_lvalue) { } #endif // FMT_USE_USER_DEFINED_LITERALS -enum test_enum { A }; - -TEST(format_test, enum) { EXPECT_EQ("0", fmt::format("{}", A)); } +TEST(format_test, enum) { EXPECT_EQ("0", fmt::format("{}", zero)); } TEST(format_test, formatter_not_specialized) { static_assert(!fmt::has_formatter,