Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.nonmodifying / alg.find / pstl.find.pass.cpp
blob8a9eee81d95c06f984443350619dc8f6f67921e1
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 T>
16 // ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
17 // const T& value);
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);
29 static_assert(sfinae_test_find<int, int*, int*, bool (*)(int)>);
30 static_assert(!sfinae_test_find<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(policy, Iter(std::begin(a)), Iter(std::end(a)), 3)) == a + 2);
41 // check that last is returned if no element matches
42 assert(base(std::find(policy, Iter(std::begin(a)), Iter(std::end(a)), 0)) == std::end(a));
44 // check that the first element is returned
45 assert(base(std::find(policy, Iter(std::begin(a)), Iter(std::end(a)), 1)) == std::begin(a));
47 // check that an empty range works
48 assert(base(std::find(policy, Iter(std::begin(a)), Iter(std::begin(a)), 1)) == std::begin(a));
50 // check that a one-element range works
51 assert(base(std::find(policy, Iter(std::begin(a)), Iter(std::begin(a) + 1), 1)) == std::begin(a));
53 // check that a two-element range works
54 assert(base(std::find(policy, Iter(std::begin(a)), Iter(std::begin(a) + 2), 2)) == std::begin(a) + 1);
56 // check that a large number of elements works
57 std::vector<int> vec(200, 4);
58 vec[176] = 5;
59 assert(base(std::find(policy, Iter(std::data(vec)), Iter(std::data(vec) + std::size(vec)), 5)) ==
60 std::data(vec) + 176);
64 int main(int, char**) {
65 types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{});
67 return 0;