1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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);
20 #include "test_macros.h"
21 #include "test_iterators.h"
25 TEST_CONSTEXPR_CXX14
bool operator()(int i
) {return i
% 3 == 0;}
28 template <class InIter
, class OutIter
>
29 TEST_CONSTEXPR_CXX20
void
32 const unsigned N
= 1000;
34 for (unsigned i
= 0; i
< N
; ++i
)
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
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*>();
90 static_assert(test());