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