Implement ranges::max_element
Details
- Reviewers
• Quuxplusone ldionne Mordante - Group Reviewers
Restricted Project - Commits
- rG205557c908ff: [libc++][ranges] Implement ranges::max_element
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
In general looks good, but I'd like a bit more test coverage.
libcxx/test/std/algorithms/alg.sorting/alg.min.max/ranges.max_element.pass.cpp | ||
---|---|---|
28 | Would it be possible to use special comparison and projection to validate the complexity? | |
83 | I would like a test where the maximum value occurs twice to validate whether it returns the first, per Returns: The first iterator i in the range…. | |
89 | For reviewing it would be nice to also validate the value assert(*ret == x); in all these tests. |
Please git grep ranges::max_element and fix what you find. std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp needs updating at least.
LGTM % comments, and the only significant comment affects the already-committed test for ranges::min_element. I think this is good to go, to get min and max back into parity; but then after that, they should both get some improved tests.
Also, before landing, please run a diff <(sed s/min/foo/g ranges_min_element.h) <(sed s/max/foo/g ranges_max_element.h) and make sure there are no extraneous differences between the two source files. If I understand correctly, there should only be one diff: the order of the arguments to __comp!
libcxx/include/__algorithm/ranges_max_element.h | ||
---|---|---|
35 | Nit: static constexpr | |
libcxx/test/std/algorithms/alg.sorting/alg.min.max/ranges.max_element.pass.cpp | ||
58–67 | test_range is called only once — both here and in ranges.min_element.pass.cpp, although I feel sure I commented multiple times about this kind of thing. Replace its call-site there with int a2[] = {7, 6, 5, 3, 4, 2, 1, 8}; assert(std::ranges::min_element(a) == a + 6); and here with int a2[] = {7, 6, 5, 3, 4, 2, 1, 8}; assert(std::ranges::max_element(a) == a + 7); After that, think about whether there's any test coverage missing. (Hint: probably.) |
Nit: static constexpr
https://quuxplusone.github.io/blog/2021/04/03/static-constexpr-whittling-knife/