Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.copy / copy_if.pass.cpp
blob57214e65455b458eb7bd804d410b51510597a9ce
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 // <algorithm>
11 // template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter,
12 // Predicate<auto, InIter::value_type> Pred>
13 // requires CopyConstructible<Pred>
14 // constexpr OutIter // constexpr after C++17
15 // copy_if(InIter first, InIter last, OutIter result, Pred pred);
17 #include <algorithm>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "test_iterators.h"
23 struct Pred
25 TEST_CONSTEXPR_CXX14 bool operator()(int i) {return i % 3 == 0;}
28 template <class InIter, class OutIter>
29 TEST_CONSTEXPR_CXX20 void
30 test_copy_if()
32 const unsigned N = 1000;
33 int ia[N] = {};
34 for (unsigned i = 0; i < N; ++i)
35 ia[i] = i;
36 int ib[N] = {0};
38 OutIter r = std::copy_if(InIter(ia), InIter(ia+N), OutIter(ib), Pred());
39 assert(base(r) == ib+N/3+1);
40 for (unsigned i = 0; i < N/3+1; ++i)
41 assert(ib[i] % 3 == 0);
44 TEST_CONSTEXPR_CXX20 bool
45 test()
47 test_copy_if<cpp17_input_iterator<const int*>, cpp17_output_iterator<int*> >();
48 test_copy_if<cpp17_input_iterator<const int*>, cpp17_input_iterator<int*> >();
49 test_copy_if<cpp17_input_iterator<const int*>, forward_iterator<int*> >();
50 test_copy_if<cpp17_input_iterator<const int*>, bidirectional_iterator<int*> >();
51 test_copy_if<cpp17_input_iterator<const int*>, random_access_iterator<int*> >();
52 test_copy_if<cpp17_input_iterator<const int*>, int*>();
54 test_copy_if<forward_iterator<const int*>, cpp17_output_iterator<int*> >();
55 test_copy_if<forward_iterator<const int*>, cpp17_input_iterator<int*> >();
56 test_copy_if<forward_iterator<const int*>, forward_iterator<int*> >();
57 test_copy_if<forward_iterator<const int*>, bidirectional_iterator<int*> >();
58 test_copy_if<forward_iterator<const int*>, random_access_iterator<int*> >();
59 test_copy_if<forward_iterator<const int*>, int*>();
61 test_copy_if<bidirectional_iterator<const int*>, cpp17_output_iterator<int*> >();
62 test_copy_if<bidirectional_iterator<const int*>, cpp17_input_iterator<int*> >();
63 test_copy_if<bidirectional_iterator<const int*>, forward_iterator<int*> >();
64 test_copy_if<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
65 test_copy_if<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
66 test_copy_if<bidirectional_iterator<const int*>, int*>();
68 test_copy_if<random_access_iterator<const int*>, cpp17_output_iterator<int*> >();
69 test_copy_if<random_access_iterator<const int*>, cpp17_input_iterator<int*> >();
70 test_copy_if<random_access_iterator<const int*>, forward_iterator<int*> >();
71 test_copy_if<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
72 test_copy_if<random_access_iterator<const int*>, random_access_iterator<int*> >();
73 test_copy_if<random_access_iterator<const int*>, int*>();
75 test_copy_if<const int*, cpp17_output_iterator<int*> >();
76 test_copy_if<const int*, cpp17_input_iterator<int*> >();
77 test_copy_if<const int*, forward_iterator<int*> >();
78 test_copy_if<const int*, bidirectional_iterator<int*> >();
79 test_copy_if<const int*, random_access_iterator<int*> >();
80 test_copy_if<const int*, int*>();
82 return true;
85 int main(int, char**)
87 test();
89 #if TEST_STD_VER > 17
90 static_assert(test());
91 #endif
93 return 0;