diff --git a/include/fmt/core.h b/include/fmt/core.h index b4c511fe..2e9e8451 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1202,7 +1202,27 @@ FMT_CONSTEXPR_DECL FMT_INLINE auto visit_format_arg( return vis(monostate()); } +// Checks whether T is a container with contiguous storage. +template struct is_contiguous : std::false_type {}; +template +struct is_contiguous> : std::true_type {}; +template +struct is_contiguous> : std::true_type {}; + namespace detail { + +template +struct is_back_insert_iterator : std::false_type {}; +template +struct is_back_insert_iterator> + : std::true_type {}; + +template +struct is_contiguous_back_insert_iterator : std::false_type {}; +template +struct is_contiguous_back_insert_iterator> + : is_contiguous {}; + // A type-erased reference to an std::locale to avoid heavy include. class locale_ref { private: @@ -1329,7 +1349,9 @@ template class basic_format_context { iterator out() { return out_; } // Advances the begin iterator to ``it``. - void advance_to(iterator it) { out_ = it; } + void advance_to(iterator it) { + if (!detail::is_back_insert_iterator()) out_ = it; + } detail::locale_ref locale() { return loc_; } }; @@ -1715,22 +1737,8 @@ struct wformat_args : basic_format_args { using basic_format_args::basic_format_args; }; -template struct is_contiguous : std::false_type {}; - -template -struct is_contiguous> : std::true_type {}; - -template -struct is_contiguous> : std::true_type {}; - namespace detail { -template -struct is_contiguous_back_insert_iterator : std::false_type {}; -template -struct is_contiguous_back_insert_iterator> - : is_contiguous {}; - // Reports a compile-time error if S is not a valid format string. template ::value)> FMT_INLINE void check_format_string(const S&) {