From 1c83a49be9fc42451884cf881294c441a8382f97 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 21 May 2021 20:15:56 -0700 Subject: [PATCH] Simplify buffer extraction --- include/fmt/color.h | 2 +- include/fmt/core.h | 14 ++++++-------- include/fmt/format.h | 2 +- include/fmt/locale.h | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index 62636dc9..4fadb596 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -594,7 +594,7 @@ template format_str, basic_format_args>> args) { - detail::get_buffer_t buf(detail::get_buffer(out)); + auto&& buf = detail::get_buffer(out); detail::vformat_to(buf, ts, format_str, args); return detail::get_iterator(buf); } diff --git a/include/fmt/core.h b/include/fmt/core.h index a176566f..dec1412b 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -763,6 +763,7 @@ template class buffer { buffer(const buffer&) = delete; void operator=(const buffer&) = delete; + buffer(buffer&&) = default; auto begin() FMT_NOEXCEPT -> T* { return ptr_; } auto end() FMT_NOEXCEPT -> T* { return ptr_ + size_; } @@ -924,13 +925,9 @@ using buffer_appender = conditional_t::value, appender, std::back_insert_iterator>>; // Maps an output iterator to a buffer. -template -using get_buffer_t = - conditional_t>::value, buffer&, - iterator_buffer>; - -template auto get_buffer(OutputIt out) -> OutputIt { - return out; +template +auto get_buffer(OutputIt out) -> iterator_buffer { + return iterator_buffer(out); } template @@ -1340,6 +1337,7 @@ 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); } @@ -2849,7 +2847,7 @@ template ::value)> auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt { using detail::get_buffer; - detail::get_buffer_t buf(get_buffer(out)); + auto&& buf = get_buffer(out); detail::vformat_to(buf, string_view(fmt), args); return detail::get_iterator(buf); } diff --git a/include/fmt/format.h b/include/fmt/format.h index d205e760..e67c22aa 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2695,7 +2695,7 @@ template , auto vformat_to(OutputIt out, const S& format_str, basic_format_args>> args) -> OutputIt { - detail::get_buffer_t buf(detail::get_buffer(out)); + auto&& buf = detail::get_buffer(out); detail::vformat_to(buf, to_string_view(format_str), args); return detail::get_iterator(buf); } diff --git a/include/fmt/locale.h b/include/fmt/locale.h index 8b62319e..9bf46d58 100644 --- a/include/fmt/locale.h +++ b/include/fmt/locale.h @@ -47,7 +47,7 @@ template >> args) { - detail::get_buffer_t buf(detail::get_buffer(out)); + auto&& buf = detail::get_buffer(out); vformat_to(buf, to_string_view(format_str), args, detail::locale_ref(loc)); return detail::get_iterator(buf); }