From 556e412d3ce8ac9d309062f381787f6251819d4a Mon Sep 17 00:00:00 2001 From: Jin S Date: Mon, 26 Feb 2024 21:00:34 -0500 Subject: [PATCH] clean up --- include/fmt/ranges.h | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index fc1d58f5..38a78be6 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -13,7 +13,6 @@ #include #include -#include "base.h" #include "format.h" FMT_BEGIN_NAMESPACE @@ -455,17 +454,14 @@ struct range_formatter< return underlying_.parse(ctx); } - template ::value, bool> = true> + template auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) { detail::range_mapper> mapper; auto out = ctx.out(); - out = detail::copy(opening_bracket_, out); - int i = 0; auto it = detail::range_begin(range); auto end = detail::range_end(range); - if (is_string_format) { - if (is_debug) { + if constexpr (std::is_same::value) { + if (is_string_format && is_debug) { auto buf = basic_memory_buffer(); for (; it != end; ++it) { auto&& item = *it; @@ -473,39 +469,15 @@ struct range_formatter< } format_specs spec_str{}; spec_str.type = presentation_type::debug; - detail::write( + return detail::write( out, basic_string_view(buf.data(), buf.size()), spec_str); - } else { - for (; it != end; ++it) { - ctx.advance_to(out); - auto&& item = *it; - out = underlying_.format(mapper.map(item), ctx); - } - } - } else { - for (; it != end; ++it) { - if (i > 0) out = detail::copy(separator_, out); - ctx.advance_to(out); - auto&& item = *it; - out = underlying_.format(mapper.map(item), ctx); - ++i; } } - out = detail::copy(closing_bracket_, out); - return out; - } - template ::value), bool> = true> - auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) { - detail::range_mapper> mapper; - auto out = ctx.out(); out = detail::copy(opening_bracket_, out); int i = 0; - auto it = detail::range_begin(range); - auto end = detail::range_end(range); for (; it != end; ++it) { - if (i > 0) out = detail::copy(separator_, out); + if (i > 0 && !is_string_format) out = detail::copy(separator_, out); ctx.advance_to(out); auto&& item = *it; out = underlying_.format(mapper.map(item), ctx);