Using std::ranges::copy from the C++ standard library has a few benefits here:
- It has the additional benefit of being a bit more type safe and document any needed cast explicitly. (No cast is needed here)
- It has defined semantics for empty source ranges.
This should also fix https://github.com/bitcoin/bitcoin/pull/35118#discussion_r3506566815