xref: /llvm-project/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp (revision 5e97d37b960840cabf32dfef3503b28ba5d21dc2)
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, class T>
125a83710eSEric Fiselier //   requires HasEqualTo<InIter::value_type, T>
13e8ea8296SMarshall Clow //   constexpr OutIter         // constexpr after C++17
145a83710eSEric Fiselier //   remove_copy(InIter first, InIter last, OutIter result, const T& value);
155a83710eSEric Fiselier 
165a83710eSEric Fiselier #include <algorithm>
175a83710eSEric Fiselier #include <cassert>
185a83710eSEric Fiselier 
19e8ea8296SMarshall Clow #include "test_macros.h"
205a83710eSEric Fiselier #include "test_iterators.h"
215a83710eSEric Fiselier 
22e8ea8296SMarshall Clow #if TEST_STD_VER > 17
test_constexpr()23e8ea8296SMarshall Clow TEST_CONSTEXPR bool test_constexpr() {
24e8ea8296SMarshall Clow     int ia[] = {1, 3, 5, 2, 5, 6};
25e8ea8296SMarshall Clow     int ib[std::size(ia)] = {0};
26e8ea8296SMarshall Clow 
27e8ea8296SMarshall Clow     auto it = std::remove_copy(std::begin(ia), std::end(ia), std::begin(ib), 5);
28e8ea8296SMarshall Clow 
296d8abe42SBilly Robert O'Neal III     return std::distance(std::begin(ib), it) == static_cast<int>(std::size(ia) - 2)   // we removed two elements
30e8ea8296SMarshall Clow         && std::none_of(std::begin(ib), it, [](int a) {return a == 5;})
31e8ea8296SMarshall Clow         && std::all_of (it, std::end(ib),   [](int a) {return a == 0;})
32e8ea8296SMarshall Clow            ;
33e8ea8296SMarshall Clow     }
34e8ea8296SMarshall Clow #endif
35e8ea8296SMarshall Clow 
365a83710eSEric Fiselier template <class InIter, class OutIter>
375a83710eSEric Fiselier void
test()385a83710eSEric Fiselier test()
395a83710eSEric Fiselier {
405a83710eSEric Fiselier     int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
415a83710eSEric Fiselier     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
425a83710eSEric Fiselier     int ib[sa];
435a83710eSEric Fiselier     OutIter r = std::remove_copy(InIter(ia), InIter(ia+sa), OutIter(ib), 2);
445a83710eSEric Fiselier     assert(base(r) == ib + sa-3);
455a83710eSEric Fiselier     assert(ib[0] == 0);
465a83710eSEric Fiselier     assert(ib[1] == 1);
475a83710eSEric Fiselier     assert(ib[2] == 3);
485a83710eSEric Fiselier     assert(ib[3] == 4);
495a83710eSEric Fiselier     assert(ib[4] == 3);
505a83710eSEric Fiselier     assert(ib[5] == 4);
515a83710eSEric Fiselier }
525a83710eSEric Fiselier 
main(int,char **)532df59c50SJF Bastien int main(int, char**)
545a83710eSEric Fiselier {
55*5e97d37bSMark de Wever     test<cpp17_input_iterator<const int*>, cpp17_output_iterator<int*> >();
56773ae441SChristopher Di Bella     test<cpp17_input_iterator<const int*>, forward_iterator<int*> >();
57773ae441SChristopher Di Bella     test<cpp17_input_iterator<const int*>, bidirectional_iterator<int*> >();
58773ae441SChristopher Di Bella     test<cpp17_input_iterator<const int*>, random_access_iterator<int*> >();
59773ae441SChristopher Di Bella     test<cpp17_input_iterator<const int*>, int*>();
605a83710eSEric Fiselier 
61*5e97d37bSMark de Wever     test<forward_iterator<const int*>, cpp17_output_iterator<int*> >();
625a83710eSEric Fiselier     test<forward_iterator<const int*>, forward_iterator<int*> >();
635a83710eSEric Fiselier     test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
645a83710eSEric Fiselier     test<forward_iterator<const int*>, random_access_iterator<int*> >();
655a83710eSEric Fiselier     test<forward_iterator<const int*>, int*>();
665a83710eSEric Fiselier 
67*5e97d37bSMark de Wever     test<bidirectional_iterator<const int*>, cpp17_output_iterator<int*> >();
685a83710eSEric Fiselier     test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
695a83710eSEric Fiselier     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
705a83710eSEric Fiselier     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
715a83710eSEric Fiselier     test<bidirectional_iterator<const int*>, int*>();
725a83710eSEric Fiselier 
73*5e97d37bSMark de Wever     test<random_access_iterator<const int*>, cpp17_output_iterator<int*> >();
745a83710eSEric Fiselier     test<random_access_iterator<const int*>, forward_iterator<int*> >();
755a83710eSEric Fiselier     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
765a83710eSEric Fiselier     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
775a83710eSEric Fiselier     test<random_access_iterator<const int*>, int*>();
785a83710eSEric Fiselier 
79*5e97d37bSMark de Wever     test<const int*, cpp17_output_iterator<int*> >();
805a83710eSEric Fiselier     test<const int*, forward_iterator<int*> >();
815a83710eSEric Fiselier     test<const int*, bidirectional_iterator<int*> >();
825a83710eSEric Fiselier     test<const int*, random_access_iterator<int*> >();
835a83710eSEric Fiselier     test<const int*, int*>();
84e8ea8296SMarshall Clow 
85e8ea8296SMarshall Clow #if TEST_STD_VER > 17
86e8ea8296SMarshall Clow     static_assert(test_constexpr());
87e8ea8296SMarshall Clow #endif
882df59c50SJF Bastien 
892df59c50SJF Bastien   return 0;
905a83710eSEric Fiselier }
91