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 // remove_copy_if(InIter first, InIter last, OutIter result, Pred pred);
21 #include "test_macros.h"
22 #include "test_iterators.h"
24 TEST_CONSTEXPR
bool equalToTwo(int v
) { return v
== 2; }
27 TEST_CONSTEXPR
bool test_constexpr() {
28 int ia
[] = {1, 3, 5, 2, 5, 6};
29 int ib
[std::size(ia
)] = {0};
31 auto it
= std::remove_copy_if(std::begin(ia
), std::end(ia
), std::begin(ib
), equalToTwo
);
33 return std::distance(std::begin(ib
), it
) == static_cast<int>(std::size(ia
) - 1) // we removed one element
34 && std::none_of(std::begin(ib
), it
, equalToTwo
)
35 && std::all_of (it
, std::end(ib
), [](int a
) {return a
== 0;})
40 template <class InIter
, class OutIter
>
44 int ia
[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
45 const unsigned sa
= sizeof(ia
)/sizeof(ia
[0]);
47 OutIter r
= std::remove_copy_if(InIter(ia
), InIter(ia
+sa
),
48 OutIter(ib
), equalToTwo
);
49 assert(base(r
) == ib
+ sa
-3);
60 test
<input_iterator
<const int*>, output_iterator
<int*> >();
61 test
<input_iterator
<const int*>, forward_iterator
<int*> >();
62 test
<input_iterator
<const int*>, bidirectional_iterator
<int*> >();
63 test
<input_iterator
<const int*>, random_access_iterator
<int*> >();
64 test
<input_iterator
<const int*>, int*>();
66 test
<forward_iterator
<const int*>, output_iterator
<int*> >();
67 test
<forward_iterator
<const int*>, forward_iterator
<int*> >();
68 test
<forward_iterator
<const int*>, bidirectional_iterator
<int*> >();
69 test
<forward_iterator
<const int*>, random_access_iterator
<int*> >();
70 test
<forward_iterator
<const int*>, int*>();
72 test
<bidirectional_iterator
<const int*>, output_iterator
<int*> >();
73 test
<bidirectional_iterator
<const int*>, forward_iterator
<int*> >();
74 test
<bidirectional_iterator
<const int*>, bidirectional_iterator
<int*> >();
75 test
<bidirectional_iterator
<const int*>, random_access_iterator
<int*> >();
76 test
<bidirectional_iterator
<const int*>, int*>();
78 test
<random_access_iterator
<const int*>, output_iterator
<int*> >();
79 test
<random_access_iterator
<const int*>, forward_iterator
<int*> >();
80 test
<random_access_iterator
<const int*>, bidirectional_iterator
<int*> >();
81 test
<random_access_iterator
<const int*>, random_access_iterator
<int*> >();
82 test
<random_access_iterator
<const int*>, int*>();
84 test
<const int*, output_iterator
<int*> >();
85 test
<const int*, forward_iterator
<int*> >();
86 test
<const int*, bidirectional_iterator
<int*> >();
87 test
<const int*, random_access_iterator
<int*> >();
88 test
<const int*, int*>();
91 static_assert(test_constexpr());