As the comment notes, now that we have implemented std::ranges::swap_ranges,
we can apply it when swapping C-style arrays in the swap CPO when there is
support for ranges.
Details
- Reviewers
ldionne • Quuxplusone Mordante philnik var-const - Group Reviewers
Restricted Project
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libcxx/include/__concepts/swappable.h | ||
---|---|---|
82–85 | I think this is what you want? |
libcxx/include/__concepts/swappable.h | ||
---|---|---|
82–85 |
Actually use std::ranges::swap_ranges instead of std::swap_ranges.
libcxx/include/__concepts/swappable.h | ||
---|---|---|
82–85 | Oops, yes. Fixed - thanks! |
LGTM if CI is happy. I skimmed the existing tests for ranges::swap and it looks like arrays are covered decently well; but have you also looked at the tests? Do we need any more coverage for this?
Looks like CI isn't happy as this introduces a header cycle as shown by https://buildkite.com/llvm-project/libcxx-ci/builds/8635#9ef9a18c-716c-4962-9f54-27108fa79d51. We'll need to fix that.
As for the tests, I briefly looked at the array tests and they seemed OK - nothing immediately came to mind that I'd like to add (at least as a result of us using ranges::swap_ranges for swappable arrays).
This LGTM, however I would like to see this again after rebasing on top of D118736. D118736 is a must-have, and I think both are going to be in conflict, so we might have to postpone doing this. Or we could do something like:
#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) // use for loop #else // use ranges::swap_ranges #endif
Once we stop using _LIBCPP_HAS_NO_INCOMPLETE_RANGES, we can refactor this into only the #else branch.
The #ifdef dance you proposed seems reasonable, and then can clean it up once we stop using _LIBCPP_HAS_NO_INCOMPLETE_RANGES. I haven't had a chance yet to look into fixing the header cycle issue this exposes when including #include <__algorithm/ranges_swap_ranges.h> from <__concepts/swappable.h>. I'll rebase and fix the cycle sometime this week.
Rebase and add #ifdef.
There isn't a "straightforward" way to fix the header cycle since __concepts/movable.h depends on __concepts/swappable.h