15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // <algorithm>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter,
125a83710eSEric Fiselier //          Predicate<auto, InIter::value_type> Pred>
135a83710eSEric Fiselier //   requires CopyConstructible<Pred>
14e8ea8296SMarshall Clow //   constexpr OutIter         // constexpr after C++17
155a83710eSEric Fiselier //   remove_copy_if(InIter first, InIter last, OutIter result, Pred pred);
165a83710eSEric Fiselier 
175a83710eSEric Fiselier #include <algorithm>
185a83710eSEric Fiselier #include <functional>
195a83710eSEric Fiselier #include <cassert>
205a83710eSEric Fiselier 
21e8ea8296SMarshall Clow #include "test_macros.h"
225a83710eSEric Fiselier #include "test_iterators.h"
235a83710eSEric Fiselier 
equalToTwo(int v)24e8ea8296SMarshall Clow TEST_CONSTEXPR bool equalToTwo(int v) { return v == 2; }
25e8ea8296SMarshall Clow 
26e8ea8296SMarshall Clow #if TEST_STD_VER > 17
test_constexpr()27e8ea8296SMarshall Clow TEST_CONSTEXPR bool test_constexpr() {
28e8ea8296SMarshall Clow     int ia[] = {1, 3, 5, 2, 5, 6};
29e8ea8296SMarshall Clow     int ib[std::size(ia)] = {0};
30e8ea8296SMarshall Clow 
31e8ea8296SMarshall Clow     auto it = std::remove_copy_if(std::begin(ia), std::end(ia), std::begin(ib), equalToTwo);
32e8ea8296SMarshall Clow 
336d8abe42SBilly Robert O'Neal III     return std::distance(std::begin(ib), it) == static_cast<int>(std::size(ia) - 1)   // we removed one element
34e8ea8296SMarshall Clow         && std::none_of(std::begin(ib), it, equalToTwo)
35e8ea8296SMarshall Clow         && std::all_of (it, std::end(ib), [](int a) {return a == 0;})
36e8ea8296SMarshall Clow            ;
37e8ea8296SMarshall Clow     }
38e8ea8296SMarshall Clow #endif
39315cd1feSMarshall Clow 
405a83710eSEric Fiselier template <class InIter, class OutIter>
415a83710eSEric Fiselier void
test()425a83710eSEric Fiselier test()
435a83710eSEric Fiselier {
445a83710eSEric Fiselier     int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
455a83710eSEric Fiselier     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
465a83710eSEric Fiselier     int ib[sa];
47315cd1feSMarshall Clow     OutIter r = std::remove_copy_if(InIter(ia), InIter(ia+sa),
48315cd1feSMarshall Clow                                     OutIter(ib), equalToTwo);
495a83710eSEric Fiselier     assert(base(r) == ib + sa-3);
505a83710eSEric Fiselier     assert(ib[0] == 0);
515a83710eSEric Fiselier     assert(ib[1] == 1);
525a83710eSEric Fiselier     assert(ib[2] == 3);
535a83710eSEric Fiselier     assert(ib[3] == 4);
545a83710eSEric Fiselier     assert(ib[4] == 3);
555a83710eSEric Fiselier     assert(ib[5] == 4);
565a83710eSEric Fiselier }
575a83710eSEric Fiselier 
main(int,char **)582df59c50SJF Bastien int main(int, char**)
595a83710eSEric Fiselier {
60*5e97d37bSMark de Wever     test<cpp17_input_iterator<const int*>, cpp17_output_iterator<int*> >();
61773ae441SChristopher Di Bella     test<cpp17_input_iterator<const int*>, forward_iterator<int*> >();
62773ae441SChristopher Di Bella     test<cpp17_input_iterator<const int*>, bidirectional_iterator<int*> >();
63773ae441SChristopher Di Bella     test<cpp17_input_iterator<const int*>, random_access_iterator<int*> >();
64773ae441SChristopher Di Bella     test<cpp17_input_iterator<const int*>, int*>();
655a83710eSEric Fiselier 
66*5e97d37bSMark de Wever     test<forward_iterator<const int*>, cpp17_output_iterator<int*> >();
675a83710eSEric Fiselier     test<forward_iterator<const int*>, forward_iterator<int*> >();
685a83710eSEric Fiselier     test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
695a83710eSEric Fiselier     test<forward_iterator<const int*>, random_access_iterator<int*> >();
705a83710eSEric Fiselier     test<forward_iterator<const int*>, int*>();
715a83710eSEric Fiselier 
72*5e97d37bSMark de Wever     test<bidirectional_iterator<const int*>, cpp17_output_iterator<int*> >();
735a83710eSEric Fiselier     test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
745a83710eSEric Fiselier     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
755a83710eSEric Fiselier     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
765a83710eSEric Fiselier     test<bidirectional_iterator<const int*>, int*>();
775a83710eSEric Fiselier 
78*5e97d37bSMark de Wever     test<random_access_iterator<const int*>, cpp17_output_iterator<int*> >();
795a83710eSEric Fiselier     test<random_access_iterator<const int*>, forward_iterator<int*> >();
805a83710eSEric Fiselier     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
815a83710eSEric Fiselier     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
825a83710eSEric Fiselier     test<random_access_iterator<const int*>, int*>();
835a83710eSEric Fiselier 
84*5e97d37bSMark de Wever     test<const int*, cpp17_output_iterator<int*> >();
855a83710eSEric Fiselier     test<const int*, forward_iterator<int*> >();
865a83710eSEric Fiselier     test<const int*, bidirectional_iterator<int*> >();
875a83710eSEric Fiselier     test<const int*, random_access_iterator<int*> >();
885a83710eSEric Fiselier     test<const int*, int*>();
89e8ea8296SMarshall Clow 
90e8ea8296SMarshall Clow #if TEST_STD_VER > 17
91e8ea8296SMarshall Clow     static_assert(test_constexpr());
92e8ea8296SMarshall Clow #endif
932df59c50SJF Bastien 
942df59c50SJF Bastien   return 0;
955a83710eSEric Fiselier }
96