std::ranges::copy_n
cppreference.com
Example
main: () = {
src: const std::string_view = "ABCDEFGH";
dst: std::string = ();
std::ranges::copy_n(src.begin(), 4, std::back_inserter(dst));
std::cout << std::quoted(dst) << '\n';
dst = "abcdefgh";
res:= std::ranges::copy_n(src.begin(), 5, dst.begin());
std::cout
<< "res.in: '" << (res.in)* << "', distance: "
<< std::distance(std::begin(src), res.in) << '\n'
<< "res.out: '" << (res.out)* << "', distance: "
<< std::distance(std::begin(dst), res.out) << '\n';
_ = src;
_ = dst;
}
Output
"ABCD"
res.in: 'F', distance: 5
res.out: 'f', distance: 5