s/requires/REQUIRES to fix the test on release build
[llvm-project.git] / libcxx / test / std / algorithms / alg.nonmodifying / alg.find / pstl.find_if_not.pass.cpp
blobe5a242c57a2c4a08718b81d09c31bc4df7e73190
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 // ForwardIterator find_if_not(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(find_if_not);
29 static_assert(sfinae_test_find_if_not<int, int*, int*, bool (*)(int)>);
30 static_assert(!sfinae_test_find_if_not<std::execution::parallel_policy, int*, int*, 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};
38 // simple test
39 assert(base(std::find_if_not(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i != 3; })) ==
40 a + 2);
42 // check that last is returned if no element matches
43 assert(base(std::find_if_not(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i != 0; })) ==
44 std::end(a));
46 // check that the first element is returned
47 assert(base(std::find_if_not(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i != 1; })) ==
48 std::begin(a));
50 // check that an empty range works
51 assert(base(std::find_if_not(policy, Iter(std::begin(a)), Iter(std::begin(a)), [](int i) { return i != 1; })) ==
52 std::begin(a));
54 // check that a one-element range works
55 assert(base(std::find_if_not(policy, Iter(std::begin(a)), Iter(std::begin(a) + 1), [](int i) { return i != 1; })) ==
56 std::begin(a));
58 // check that a two-element range works
59 assert(base(std::find_if_not(policy, Iter(std::begin(a)), Iter(std::begin(a) + 2), [](int i) { return i != 2; })) ==
60 std::begin(a) + 1);
62 // check that a large number of elements works
63 std::vector<int> vec(200, 4);
64 vec[176] = 5;
65 assert(base(std::find_if_not(policy, Iter(std::data(vec)), Iter(std::data(vec) + std::size(vec)), [](int i) {
66 return i != 5;
67 })) == std::data(vec) + 176);
71 int main(int, char**) {
72 types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{});
74 return 0;