diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 4c702c20..ed7f5f16 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -427,7 +427,7 @@ auto write(OutputIt out, const std::tm& time, const std::locale& loc, char format, char modifier = 0) -> OutputIt { auto&& buf = get_buffer(out); do_write(buf, time, loc, format, modifier); - return get_iterator(buf); + return get_iterator(buf, out); } template >> args) { auto&& buf = detail::get_buffer(out); detail::vformat_to(buf, ts, format_str, args); - return detail::get_iterator(buf); + return detail::get_iterator(buf, out); } /** diff --git a/include/fmt/core.h b/include/fmt/core.h index ed36a3f8..549f948f 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1123,13 +1123,19 @@ template auto get_buffer(OutputIt out) -> iterator_buffer { return iterator_buffer(out); } +template , Buf>::value)> +auto get_buffer(std::back_insert_iterator out) -> buffer& { + return get_container(out); +} -template -FMT_INLINE auto get_iterator(Buffer& buf) -> decltype(buf.out()) { +template +FMT_INLINE auto get_iterator(Buf& buf, OutputIt) -> decltype(buf.out()) { return buf.out(); } -template auto get_iterator(buffer& buf) -> buffer_appender { - return buffer_appender(buf); +template +auto get_iterator(buffer&, OutputIt out) -> OutputIt { + return out; } template @@ -1556,11 +1562,6 @@ FMT_END_DETAIL_NAMESPACE class appender : public std::back_insert_iterator> { using base = std::back_insert_iterator>; - template - friend auto get_buffer(appender out) -> detail::buffer& { - return detail::get_container(out); - } - public: using std::back_insert_iterator>::back_insert_iterator; appender(base it) noexcept : base(it) {} @@ -3224,10 +3225,9 @@ FMT_NODISCARD FMT_INLINE auto format(format_string fmt, T&&... args) template ::value)> auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt { - using detail::get_buffer; - auto&& buf = get_buffer(out); + auto&& buf = detail::get_buffer(out); detail::vformat_to(buf, fmt, args, {}); - return detail::get_iterator(buf); + return detail::get_iterator(buf, out); } /** diff --git a/include/fmt/format.h b/include/fmt/format.h index c62c883f..124f022b 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -4276,7 +4276,7 @@ auto vformat_to(OutputIt out, const Locale& loc, string_view fmt, using detail::get_buffer; auto&& buf = get_buffer(out); detail::vformat_to(buf, fmt, args, detail::locale_ref(loc)); - return detail::get_iterator(buf); + return detail::get_iterator(buf, out); } template OutputIt { auto&& buf = detail::get_buffer(out); detail::vformat_to(buf, detail::to_string_view(format_str), args); - return detail::get_iterator(buf); + return detail::get_iterator(buf, out); } template