This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Implement ranges::is_partitioned
ClosedPublic

Authored by philnik on Apr 26 2022, 1:19 AM.

Details

Reviewers
ldionne
Mordante
var-const
Group Reviewers
Restricted Project
Commits
rG37ba1b9d1ac7: [libc++] Implement ranges::is_partitioned

Diff Detail

Event Timeline

philnik created this revision.Apr 26 2022, 1:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2022, 1:19 AM
Herald added a subscriber: mgorny. · View Herald Transcript
philnik requested review of this revision.Apr 26 2022, 1:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2022, 1:19 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
var-const requested changes to this revision.Apr 27 2022, 2:21 PM
var-const added inline comments.
libcxx/include/CMakeLists.txt
70

Please also update the Ranges status page to mark this algorithm as done.

libcxx/include/__algorithm/ranges_is_partitioned.h
2

I think you also need to update the synopsis in <algorithm>.

libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp
8

You also need to add the supported language versions/etc.

10

Please add synopsis.

19

Can you also check that this SFINAEs away if given something that isn't an indirect_unary_predicate?

20

Ultranit: indent 2 spaces? Or is there a reason to use 4 spaces here?

42

Optional: I think you could implement a helper function that takes care of both the iterator/sentinel and the ranges overloads. The main advantage would be more succinct callsites:

assert(test({1, 2, 3, 4, 5}, [](int i) { return i < 3; }));
assert(test({1, 2, 3, 4}, [](int i) { return true; }));
...
43

A few additional test cases:

  • empty range;
  • single-element range;
  • the partition point is the first/the last element (check for off-by-one errors).
57

Nit: s/partitoned/partitioned/.

This revision now requires changes to proceed.Apr 27 2022, 2:21 PM
philnik updated this revision to Diff 426639.May 3 2022, 4:10 AM
philnik marked 8 inline comments as done.
  • Address comments
libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp
42

I'll try it for the next algorithm I implement. Maybe I'll change it then for all of them.

var-const accepted this revision.May 3 2022, 1:52 PM
This revision is now accepted and ready to land.May 3 2022, 1:52 PM

LGTM when the CI is fixed.

philnik updated this revision to Diff 426969.May 4 2022, 5:19 AM
  • Try to fix the modules build
philnik updated this revision to Diff 427284.May 5 2022, 5:22 AM

Fix merge conflicts

This revision was automatically updated to reflect the committed changes.