diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 38a78be603a3..7768c23454b8 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -454,24 +454,36 @@ struct range_formatter< return underlying_.parse(ctx); } + template ::value, bool> = true> + auto write_debug_string(Output& out, Iter& it, IterEnd& end) const { + auto buf = basic_memory_buffer(); + for (; it != end; ++it) { + auto&& item = *it; + buf.push_back(item); + } + format_specs spec_str{}; + spec_str.type = presentation_type::debug; + detail::write(out, basic_string_view(buf.data(), buf.size()), + spec_str); + } + template ::value), bool> = true> + auto write_debug_string(Output& out, Iter& it, IterEnd& end) const { + detail::ignore_unused(out); + detail::ignore_unused(it); + detail::ignore_unused(end); + } + template auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) { detail::range_mapper> mapper; auto out = ctx.out(); auto it = detail::range_begin(range); auto end = detail::range_end(range); - if constexpr (std::is_same::value) { - if (is_string_format && is_debug) { - auto buf = basic_memory_buffer(); - for (; it != end; ++it) { - auto&& item = *it; - buf.push_back(item); - } - format_specs spec_str{}; - spec_str.type = presentation_type::debug; - return detail::write( - out, basic_string_view(buf.data(), buf.size()), spec_str); - } + if (is_string_format && is_debug) { + write_debug_string(out, it, end); + return out; } out = detail::copy(opening_bracket_, out);