From e5bbf88ddea3db477c2f677ec6ddb9de1cec9adf Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Mon, 21 Oct 2024 20:14:21 +0500 Subject: [PATCH] Implement fmt::format_to into std::vector Signed-off-by: Vladislav Shchapov --- include/fmt/base.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index e0baae256347..511d718e8d54 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -1971,12 +1971,26 @@ template class counting_buffer : public buffer { template struct is_back_insert_iterator> : std::true_type {}; + +template +struct has_container_append : std::false_type {}; +template +struct has_container_append().append(std::declval(), std::declval()) )>> + : std::true_type {}; + + // An optimized version of std::copy with the output value type (T). +template ::value)> +FMT_CONSTEXPR20 void copy_container_append(T& container, It begin, It end) { + container.append(begin, end); +} + template ::value)> FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt { - get_container(out).append(begin, end); + copy_container_append(get_container(out), begin, end); return out; }