diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 3b3f166e..b4767b58 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -8,6 +8,8 @@ #ifndef FMT_COMPILE_H_ #define FMT_COMPILE_H_ +#include // std::back_inserter + #include "format.h" FMT_BEGIN_NAMESPACE diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 48a240c2..15649194 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1411,7 +1411,7 @@ FMT_FUNC void format_system_error(detail::buffer& out, int error_code, const char* message) noexcept { FMT_TRY { auto ec = std::error_code(error_code, std::generic_category()); - write(std::back_inserter(out), std::system_error(ec, message).what()); + detail::write(appender(out), std::system_error(ec, message).what()); return; } FMT_CATCH(...) {} diff --git a/include/fmt/format.h b/include/fmt/format.h index f380d563..37508fb1 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -42,12 +42,11 @@ #include // uint32_t #include // std::memcpy #include // std::initializer_list -#include -#include // std::numeric_limits -#include // std::uninitialized_copy -#include // std::runtime_error -#include // std::basic_string -#include // std::system_error +#include // std::numeric_limits +#include // std::uninitialized_copy_n +#include // std::runtime_error +#include // std::basic_string +#include // std::system_error #ifdef __cpp_lib_bit_cast # include // std::bit_cast @@ -515,7 +514,21 @@ FMT_INLINE void assume(bool condition) { #endif } -template +template +auto copy_str(InputIt begin, InputIt end, appender out) -> appender { + get_container(out).append(begin, end); + return out; +} + +template ::value)> +auto copy_str(InputIt begin, InputIt end, OutputIt out) -> OutputIt { + get_container(out).append(begin, end); + return out; +} + +template ::value)> FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out) -> OutputIt { while (begin != end) *out++ = static_cast(*begin++); @@ -532,19 +545,6 @@ FMT_CONSTEXPR auto copy_str(T* begin, T* end, U* out) -> U* { return out + size; } -template -auto copy_str(InputIt begin, InputIt end, appender out) -> appender { - get_container(out).append(begin, end); - return out; -} -template -auto copy_str(InputIt begin, InputIt end, - std::back_insert_iterator out) - -> std::back_insert_iterator { - get_container(out).append(begin, end); - return out; -} - template FMT_CONSTEXPR auto copy_str(R&& rng, OutputIt out) -> OutputIt { return detail::copy_str(rng.begin(), rng.end(), out); @@ -567,14 +567,15 @@ inline auto get_data(Container& c) -> typename Container::value_type* { // Attempts to reserve space for n extra characters in the output range. // Returns a pointer to the reserved range or a reference to it. -template ::value)> +template ::value&& + is_contiguous::value)> #if FMT_CLANG_VERSION >= 307 && !FMT_ICC_VERSION __attribute__((no_sanitize("undefined"))) #endif inline auto -reserve(std::back_insert_iterator it, size_t n) -> - typename Container::value_type* { - Container& c = get_container(it); +reserve(OutputIt it, size_t n) -> typename OutputIt::value_type* { + auto& c = get_container(it); size_t size = c.size(); c.resize(size + n); return get_data(c) + size; @@ -608,10 +609,12 @@ template auto to_pointer(basic_appender it, size_t n) -> T* { return buf.data() + size; } -template ::value)> -inline auto base_iterator(std::back_insert_iterator it, - typename Container::value_type*) - -> std::back_insert_iterator { +template ::value&& + is_contiguous::value)> +inline auto base_iterator(OutputIt it, + typename OutputIt::containter_type::value_type*) + -> OutputIt { return it; } @@ -4282,7 +4285,7 @@ template struct nested_formatter { auto write_padded(format_context& ctx, F write) const -> decltype(ctx.out()) { if (width_ == 0) return write(ctx.out()); auto buf = memory_buffer(); - write(std::back_inserter(buf)); + write(appender(buf)); auto specs = format_specs<>(); specs.width = width_; specs.fill = fill_; diff --git a/include/fmt/os.h b/include/fmt/os.h index 6009ccc1..96a9b93c 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -431,8 +431,7 @@ class FMT_API ostream { output to the file. */ template void print(format_string fmt, T&&... args) { - vformat_to(std::back_inserter(buffer_), fmt, - fmt::make_format_args(args...)); + vformat_to(appender(buffer_), fmt, fmt::make_format_args(args...)); } };