[libcxx-commits] [PATCH] D152853: [libc++][PSTL] Implement std::is_partitioned

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 15 09:41:50 PDT 2023


ldionne accepted this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

LGTM w/ fix and test



================
Comment at: libcxx/include/__algorithm/pstl_is_partitioned.h:41-42
+      [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
+        __g_first = std::find_if_not(__policy, __g_first, __g_last, __g_pred);
+        return std::none_of(__policy, __g_first, __g_last, __g_pred);
+      },
----------------
Technically, I think we could implement it this way instead:

```
__g_first = std::find_if_not(__policy, __g_first, __g_last, __g_pred);
if (__g_first == __g_last)
  return true;
++__g_first;
return std::none_of(__policy, __g_first, __g_last, __g_pred);
```

This way, we avoid running the predicate twice on the first element that doesn't satisfy the predicate (which we do right now). This also mirrors what we do for the serial version of the algorithm. If you agree, I think it might be useful to add a test for this. In particular, we could have a libc++ specific test that ensures that we satisfy this complexity guarantee (from the serial version):

> At most `std::distance(first, last)` applications of `p`.

Could you also take a look at whether this is tested in the serial version, where that's definitely a requirement?



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152853/new/

https://reviews.llvm.org/D152853



More information about the libcxx-commits mailing list