[libcxx-commits] [PATCH] D96084: Revert "Revert "[libc++] [P0879] constexpr std::nth_element, and rewrite its tests.""
Jordan Rupprecht via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 5 09:34:58 PST 2021
rupprecht added a comment.
FWIW, I applied this patch and was able to make it pass this pretty exhaustive test:
{
constexpr int kMaxLen = 64;
for (int len = 1; len < kMaxLen; ++len) {
int v[kMaxLen];
for (int i = 0; i < len; ++i)
v[i] = i;
T v2[kMaxLen];
std::copy(v, v + len, v2);
do {
for (int n = 0; n < len; ++n) {
for (int m = 0; m < n; ++m) {
std::nth_element(Iter(v2), Iter(v2 + m), Iter(v2 + n),
std::greater<T>());
assert(std::is_permutation(v2, v2 + len, v));
// No element to m's left is less than m.
for (int i = 0; i < m; ++i) {
assert(!(v2[i] < v2[m]));
}
// No element to m's right is greater than m.
for (int i = m; i < n; ++i) {
assert(!(v2[i] > v2[m]));
}
}
}
} while (std::next_permutation(Iter(v2), Iter(v2 + len)));
}
}
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96084/new/
https://reviews.llvm.org/D96084
More information about the libcxx-commits
mailing list