Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / algorithms / alg.nonmodifying / alg.none_of / pstl.none_of.pass.cpp
blobfb3e34a2bdec3d24034c6b95d42ac4ccffde87d7
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
13 // <algorithm>
15 // template<class ExecutionPolicy, class ForwardIterator, class Predicate>
16 // bool none_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
17 // Predicate pred);
19 #include <algorithm>
20 #include <cassert>
21 #include <vector>
23 #include "test_macros.h"
24 #include "test_execution_policies.h"
25 #include "test_iterators.h"
27 EXECUTION_POLICY_SFINAE_TEST(none_of);
29 static_assert(sfinae_test_none_of<int, int*, int*, bool (*)(int)>);
30 static_assert(!sfinae_test_none_of<std::execution::parallel_policy, int*, int*, bool (*)(int)>);
32 template <class Iter>
33 struct Test {
34 template <class Policy>
35 void operator()(Policy&& policy) {
36 int a[] = {1, 2, 3, 4, 5, 6, 7, 8};
37 // simple test
38 assert(std::none_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i > 9; }));
39 assert(!std::none_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i >= 8; }));
41 // check that an empty range works
42 assert(std::none_of(policy, Iter(std::begin(a)), Iter(std::begin(a)), [](int) { return false; }));
44 // check that true is returned if no element satisfies the condition
45 assert(std::none_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i == 9; }));
47 // check that false is returned if only one elements satisfies the condition
48 assert(!std::none_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i == 1; }));
50 // check that a one-element range works
51 assert(std::none_of(policy, Iter(std::begin(a)), Iter(std::begin(a) + 1), [](int i) { return i != 1; }));
53 // check that a two-element range works
54 assert(std::none_of(policy, Iter(std::begin(a)), Iter(std::begin(a) + 2), [](int i) { return i > 2; }));
56 // check that a large number of elements works
57 std::vector<int> vec(100);
58 std::fill(vec.begin(), vec.end(), 3);
59 assert(std::none_of(policy, Iter(vec.data()), Iter(vec.data() + vec.size()), [](int i) { return i != 3; }));
63 int main(int, char**) {
64 types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{});
66 return 0;