• 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,
13 //          Predicate<auto, InIter::value_type> Pred>
14 //   requires CopyConstructible<Pred>
15 //   OutIter
16 //   remove_copy_if(InIter first, InIter last, OutIter result, Pred pred);
17 
18 #include <algorithm>
19 #include <functional>
20 #include <cassert>
21 
22 #include "test_iterators.h"
23 
24 template <class InIter, class OutIter>
25 void
test()26 test()
27 {
28     int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
29     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
30     int ib[sa];
31     OutIter r = std::remove_copy_if(InIter(ia), InIter(ia+sa), OutIter(ib),
32                                     std::bind2nd(std::equal_to<int>(), 2));
33     assert(base(r) == ib + sa-3);
34     assert(ib[0] == 0);
35     assert(ib[1] == 1);
36     assert(ib[2] == 3);
37     assert(ib[3] == 4);
38     assert(ib[4] == 3);
39     assert(ib[5] == 4);
40 }
41 
main()42 int main()
43 {
44     test<input_iterator<const int*>, output_iterator<int*> >();
45     test<input_iterator<const int*>, forward_iterator<int*> >();
46     test<input_iterator<const int*>, bidirectional_iterator<int*> >();
47     test<input_iterator<const int*>, random_access_iterator<int*> >();
48     test<input_iterator<const int*>, int*>();
49 
50     test<forward_iterator<const int*>, output_iterator<int*> >();
51     test<forward_iterator<const int*>, forward_iterator<int*> >();
52     test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
53     test<forward_iterator<const int*>, random_access_iterator<int*> >();
54     test<forward_iterator<const int*>, int*>();
55 
56     test<bidirectional_iterator<const int*>, output_iterator<int*> >();
57     test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
58     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
59     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
60     test<bidirectional_iterator<const int*>, int*>();
61 
62     test<random_access_iterator<const int*>, output_iterator<int*> >();
63     test<random_access_iterator<const int*>, forward_iterator<int*> >();
64     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
65     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
66     test<random_access_iterator<const int*>, int*>();
67 
68     test<const int*, output_iterator<int*> >();
69     test<const int*, forward_iterator<int*> >();
70     test<const int*, bidirectional_iterator<int*> >();
71     test<const int*, random_access_iterator<int*> >();
72     test<const int*, int*>();
73 }
74