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<ForwardIterator Iter, class T>
13 // requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
14 // && HasEqualTo<Iter::value_type, T>
15 // Iter
16 // remove(Iter first, Iter last, const T& value);
17
18 #include <algorithm>
19 #include <cassert>
20 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
21 #include <memory>
22 #endif
23
24 #include "test_iterators.h"
25
26 template <class Iter>
27 void
test()28 test()
29 {
30 int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
31 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
32 Iter r = std::remove(Iter(ia), Iter(ia+sa), 2);
33 assert(base(r) == ia + sa-3);
34 assert(ia[0] == 0);
35 assert(ia[1] == 1);
36 assert(ia[2] == 3);
37 assert(ia[3] == 4);
38 assert(ia[4] == 3);
39 assert(ia[5] == 4);
40 }
41
42 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
43
44 template <class Iter>
45 void
test1()46 test1()
47 {
48 const unsigned sa = 9;
49 std::unique_ptr<int> ia[sa];
50 ia[0].reset(new int(0));
51 ia[1].reset(new int(1));
52 ia[3].reset(new int(3));
53 ia[4].reset(new int(4));
54 ia[6].reset(new int(3));
55 ia[7].reset(new int(4));
56 Iter r = std::remove(Iter(ia), Iter(ia+sa), std::unique_ptr<int>());
57 assert(base(r) == ia + sa-3);
58 assert(*ia[0] == 0);
59 assert(*ia[1] == 1);
60 assert(*ia[2] == 3);
61 assert(*ia[3] == 4);
62 assert(*ia[4] == 3);
63 assert(*ia[5] == 4);
64 }
65
66 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
67
main()68 int main()
69 {
70 test<forward_iterator<int*> >();
71 test<bidirectional_iterator<int*> >();
72 test<random_access_iterator<int*> >();
73 test<int*>();
74
75 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
76
77 test1<forward_iterator<std::unique_ptr<int>*> >();
78 test1<bidirectional_iterator<std::unique_ptr<int>*> >();
79 test1<random_access_iterator<std::unique_ptr<int>*> >();
80 test1<std::unique_ptr<int>*>();
81
82 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
83 }
84