Factors out common logic from std::copy, std::copy_backward, std::copy_if, and std::copy_n into __copy_*_impl. Also adds __in_out_result which is the return type for the impl function. This will make adding support for the ranges overloads super easy.
This is an example of how this will be done for all algorithms. Once this lands, I'll update all the algorithms, so let's get this review right.
_VSTD:: — but also I worry a little bit about the codegen here. As you've written it so far, ranges::copy could just be
and save a lot of modifications. Which is obviously not C++20-compliant. So for C++20, we're going to have to write a new ranges::copy algorithm that returns the computed iterator, generated by incrementing __first, which ended up comparing equal to _Sentinel __last. That's a much different-looking algorithm from what we've got today for std::copy, and might not even be able to share any code with it.
I strongly strongly strongly ask that you continue working on this PR until it succeeds at implementing the C++20 ranges::copy semantics, and then see if you still think this is a good direction. I strongly strongly strongly oppose merging this PR in its current state.