This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][ranges][nfc] Factor out common logic in the copy algorithms.

Authored by philnik on Jun 7 2021, 1:55 PM.


Group Reviewers
Restricted Project

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.

Diff Detail

Event Timeline

zoecarver created this revision.Jun 7 2021, 1:55 PM
zoecarver requested review of this revision.Jun 7 2021, 1:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2021, 1:55 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
cjdb added a comment.Jun 7 2021, 2:26 PM

We're going to need to hold off on this patch until we determine what's breaking Fuchsia.

cjdb requested changes to this revision.Jun 7 2021, 5:26 PM
This revision now requires changes to proceed.Jun 7 2021, 5:26 PM
Quuxplusone requested changes to this revision.Jun 8 2021, 5:27 AM
Quuxplusone added inline comments.

_VSTD:: — but also I worry a little bit about the codegen here. As you've written it so far, ranges::copy could just be

return __in_out_result{__last, _VSTD::copy(__first, __last, __result)};

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.


This is testing that your library code is robust against ADL.
I assume it's failing at the moment because you didn't ADL-proof your call to __copy above.
Remember, every time you call a function in namespace _VSTD that would be subject to ADL, you need to qualify it. (The one common exception we make is for declval, because it takes no arguments.)

cjdb resigned from this revision.Jan 18 2022, 1:38 PM
philnik commandeered this revision.Sep 12 2022, 12:55 AM
philnik added a reviewer: zoecarver.
philnik added a subscriber: philnik.

The ranges algorithms have been implemented and the code for copy etc. have been massively changed, so I'll abandon this patch.

Herald added a project: Restricted Project. · View Herald TranscriptSep 12 2022, 12:55 AM
philnik abandoned this revision.Sep 12 2022, 12:56 AM