Repository: fmtlib/fmt
File: include/fmt/ranges.h (C/C++)

Code before:
  auto write_debug_string(Output& out, Iter& it, IterEnd& end) const -> Output {
    auto buf = basic_memory_buffer<Char>();
    for (; it != end; ++it) {
      auto&& item = *it;
      buf.push_back(item);
    }
    format_specs spec_str{};
    spec_str.type = presentation_type::debug;
    return detail::write<Char>(
        out, basic_string_view<Char>(buf.data(), buf.size()), spec_str);
  }
  template <typename Output, typename Iter, typename IterEnd, typename U = T,
            enable_if_t<!(std::is_same<U, Char>::value), bool> = true>
  auto write_debug_string(Output& out, Iter& it, IterEnd& end) const -> Output {
    detail::ignore_unused(it);
    detail::ignore_unused(end);
    return out;
  }

  template <typename R, typename FormatContext>
  auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) {
    detail::range_mapper<buffered_context<Char>> mapper;
    auto out = ctx.out();
    auto it = detail::range_begin(range);
    auto end = detail::range_end(range);
    if (is_string_format && is_debug) {
      return write_debug_string(out, it, end);
    }

    out = detail::copy<Char>(opening_bracket_, out);
    int i = 0;
    for (; it != end; ++it) {
      if (i > 0 && !is_string_format) out = detail::copy<Char>(separator_, out);
      ctx.advance_to(out);
      auto&& item = *it;
      out = underlying_.format(mapper.map(item), ctx);
      ++i;
    }
    out = detail::copy<Char>(closing_bracket_, out);
    return out;
  }
};

enum class range_format { disabled, map, set, sequence, string, debug_string };

namespace detail {
template <typename T>
struct range_format_kind_
    : std::integral_constant<range_format,
                             std::is_same<uncvref_type<T>, T>::value
                                 ? range_format::disabled

Review comment (bug):
`is_string_format` check can be removed because `is_debug` currently implies it.

Code after:
            FMT_ENABLE_IF(std::is_same<U, Char>::value)>
  auto write_debug_string(Output& out, Iter& it, IterEnd& end) const -> Output {
    auto buf = basic_memory_buffer<Char>();
    for (; it != end; ++it) {
      buf.push_back(*it);
    }
    format_specs spec_str;
    spec_str.type = presentation_type::debug;
    return detail::write<Char>(
        out, basic_string_view<Char>(buf.data(), buf.size()), spec_str);
  }
  template <typename Output, typename Iter, typename IterEnd, typename U = T,
            FMT_ENABLE_IF(!std::is_same<U, Char>::value)>
  auto write_debug_string(Output& out, Iter&, IterEnd&) const -> Output {
    return out;
  }

  template <typename R, typename FormatContext>
  auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) {
    detail::range_mapper<buffered_context<Char>> mapper;
    auto out = ctx.out();
    auto it = detail::range_begin(range);
    auto end = detail::range_end(range);
    if (is_debug) {
      return write_debug_string(out, it, end);
    }

    out = detail::copy<Char>(opening_bracket_, out);
    int i = 0;
    for (; it != end; ++it) {
      if (i > 0) out = detail::copy<Char>(separator_, out);
      ctx.advance_to(out);
      auto&& item = *it;
      out = underlying_.format(mapper.map(item), ctx);
      ++i;
    }
    out = detail::copy<Char>(closing_bracket_, out);
    return out;
  }
};

enum class range_format { disabled, map, set, sequence, string, debug_string };

namespace detail {
template <typename T>
struct range_format_kind_
    : std::integral_constant<range_format,
                             std::is_same<uncvref_type<T>, T>::value
                                 ? range_format::disabled
                             : is_map<T>::value ? range_format::map
                             : is_set<T>::value ? range_format::set