Skip to content

Commit

Permalink
Simplify map formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed May 6, 2024
1 parent 10508a3 commit 57593a1
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,19 +582,16 @@ struct formatter<

template <typename FormatContext>
auto format(map_type& map, FormatContext& ctx) const -> decltype(ctx.out()) {
auto mapper = detail::range_mapper<buffered_context<Char>>();
auto out = ctx.out();
auto it = detail::range_begin(map);
auto end = detail::range_end(map);

basic_string_view<Char> open = detail::string_literal<Char, '{'>{};
if (!no_delimiters_) out = detail::copy<Char>(open, out);
int i = 0;
auto mapper = detail::range_mapper<buffered_context<Char>>();
basic_string_view<Char> sep = detail::string_literal<Char, ',', ' '>{};
for (; it != end; ++it) {
for (auto&& value : map) {
if (i > 0) out = detail::copy<Char>(sep, out);
ctx.advance_to(out);
detail::for_each2(formatters_, mapper.map(*it),
detail::for_each2(formatters_, mapper.map(value),
detail::format_tuple_element<FormatContext>{
0, ctx, detail::string_literal<Char, ':', ' '>{}});
++i;
Expand Down

0 comments on commit 57593a1

Please sign in to comment.