On 2 October 2022 12:32:54 BST, Marcin Jaczewski via Std-Discussion <std-discussion@lists.isocpp.org> wrote:
niedz., 2 paź 2022 o 10:35 Olaf van der Spek via Std-Discussion
<std-discussion@lists.isocpp.org> napisał(a):
Hi,
This snippet overflows the destination buffer. Is format_to too easy to misuse?
Shouldn't it requires an iterator to the end so it could avoid this issue?
It seems like a modern equivalent of fgets()
#include <format>
#include <iostream>
int main()
{
char d[10] = {};
std::format_to(d, "0123456789 {}", 42);
std::cout << std::string_view(d, 10) << std::endl;
}
This is more of a problem with raw pointers than this function.
Example on https://en.cppreference.com/w/cpp/utility/format/format_to
show `std::back_inserter(buffer)`.
There are multiple algorithms that work only with a single output iterator.
Question is should standard add a new adapter for input iterator for
filling bound ranges?
Something like `std::range_fill(std::ranges::range auto& x)` that
returns an output iterator that thrown when you try
write past the end.
--
Std-Discussion mailing list
Std-Discussion@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion