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//===----------------------------------------------------------------------===//
8
9// <algorithm>
10
11// template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter, class T>
12// requires HasEqualTo<InIter::value_type, T>
13// constexpr OutIter // constexpr after C++17
14// remove_copy(InIter first, InIter last, OutIter result, const T& value);
15
16#include <algorithm>
17#include <cassert>
18
19#include "test_macros.h"
20#include "test_iterators.h"
21
22#if TEST_STD_VER > 17
23TEST_CONSTEXPR bool test_constexpr() {
24 int ia[] = {1, 3, 5, 2, 5, 6};
25 int ib[std::size(ia)] = {0};
26
27 auto it = std::remove_copy(std::begin(ia), std::end(ia), std::begin(ib), 5);
28
29 return std::distance(std::begin(ib), it) == static_cast<int>(std::size(ia) - 2) // we removed two elements
30 && std::none_of(std::begin(ib), it, [](int a) {return a == 5;})
31 && std::all_of (it, std::end(ib), [](int a) {return a == 0;})
32 ;
33 }
34#endif
35
36template <class InIter, class OutIter>
37void
38test()
39{
40 int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
41 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
42 int ib[sa];
43 OutIter r = std::remove_copy(InIter(ia), InIter(ia+sa), OutIter(ib), 2);
44 assert(base(r) == ib + sa-3);
45 assert(ib[0] == 0);
46 assert(ib[1] == 1);
47 assert(ib[2] == 3);
48 assert(ib[3] == 4);
49 assert(ib[4] == 3);
50 assert(ib[5] == 4);
51}
52
53int main(int, char**)
54{
55 test<cpp17_input_iterator<const int*>, cpp17_output_iterator<int*> >();
56 test<cpp17_input_iterator<const int*>, forward_iterator<int*> >();
57 test<cpp17_input_iterator<const int*>, bidirectional_iterator<int*> >();
58 test<cpp17_input_iterator<const int*>, random_access_iterator<int*> >();
59 test<cpp17_input_iterator<const int*>, int*>();
60
61 test<forward_iterator<const int*>, cpp17_output_iterator<int*> >();
62 test<forward_iterator<const int*>, forward_iterator<int*> >();
63 test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
64 test<forward_iterator<const int*>, random_access_iterator<int*> >();
65 test<forward_iterator<const int*>, int*>();
66
67 test<bidirectional_iterator<const int*>, cpp17_output_iterator<int*> >();
68 test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
69 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
70 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
71 test<bidirectional_iterator<const int*>, int*>();
72
73 test<random_access_iterator<const int*>, cpp17_output_iterator<int*> >();
74 test<random_access_iterator<const int*>, forward_iterator<int*> >();
75 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
76 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
77 test<random_access_iterator<const int*>, int*>();
78
79 test<const int*, cpp17_output_iterator<int*> >();
80 test<const int*, forward_iterator<int*> >();
81 test<const int*, bidirectional_iterator<int*> >();
82 test<const int*, random_access_iterator<int*> >();
83 test<const int*, int*>();
84
85#if TEST_STD_VER > 17
86 static_assert(test_constexpr());
87#endif
88
89 return 0;
90}
91

source code of libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp