Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame^] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 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 | |
| 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 | #ifdef _LIBCPP_MOVE |
| 21 | #include <memory> |
| 22 | #endif |
| 23 | |
| 24 | #include "../../iterators.h" |
| 25 | |
| 26 | template <class Iter> |
| 27 | void |
| 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 | #ifdef _LIBCPP_MOVE |
| 43 | |
| 44 | template <class Iter> |
| 45 | void |
| 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 |
| 67 | |
| 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 | #ifdef _LIBCPP_MOVE |
| 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 |
| 83 | } |