blob: 89121cb2d27ffb3ecc82059d36c0cd1d45dc53c1 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <algorithm>
11
Howard Hinnanteb564e72010-08-22 00:08:10 +000012// template<ForwardIterator Iter, class T>
13// requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
14// && HasEqualTo<Iter::value_type, T>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000015// Iter
16// remove(Iter first, Iter last, const T& value);
17
18#include <algorithm>
19#include <cassert>
Howard Hinnant73d21a42010-09-04 23:28:19 +000020#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021#include <memory>
22#endif
23
24#include "../../iterators.h"
25
26template <class Iter>
27void
28test()
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
Howard Hinnant73d21a42010-09-04 23:28:19 +000042#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043
44template <class Iter>
45void
46test1()
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
Howard Hinnant73d21a42010-09-04 23:28:19 +000066#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067
68int main()
69{
70 test<forward_iterator<int*> >();
71 test<bidirectional_iterator<int*> >();
72 test<random_access_iterator<int*> >();
73 test<int*>();
74
Howard Hinnant73d21a42010-09-04 23:28:19 +000075#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000076
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
Howard Hinnant73d21a42010-09-04 23:28:19 +000082#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083}