Home | History | Annotate | Download | only in alg.remove
      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 #include <memory>
     21 
     22 #include "test_macros.h"
     23 #include "test_iterators.h"
     24 
     25 template <class Iter>
     26 void
     27 test()
     28 {
     29     int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
     30     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
     31     Iter r = std::remove(Iter(ia), Iter(ia+sa), 2);
     32     assert(base(r) == ia + sa-3);
     33     assert(ia[0] == 0);
     34     assert(ia[1] == 1);
     35     assert(ia[2] == 3);
     36     assert(ia[3] == 4);
     37     assert(ia[4] == 3);
     38     assert(ia[5] == 4);
     39 }
     40 
     41 #if TEST_STD_VER >= 11
     42 template <class Iter>
     43 void
     44 test1()
     45 {
     46     const unsigned sa = 9;
     47     std::unique_ptr<int> ia[sa];
     48     ia[0].reset(new int(0));
     49     ia[1].reset(new int(1));
     50     ia[3].reset(new int(3));
     51     ia[4].reset(new int(4));
     52     ia[6].reset(new int(3));
     53     ia[7].reset(new int(4));
     54     Iter r = std::remove(Iter(ia), Iter(ia+sa), std::unique_ptr<int>());
     55     assert(base(r) == ia + sa-3);
     56     assert(*ia[0] == 0);
     57     assert(*ia[1] == 1);
     58     assert(*ia[2] == 3);
     59     assert(*ia[3] == 4);
     60     assert(*ia[4] == 3);
     61     assert(*ia[5] == 4);
     62 }
     63 #endif // TEST_STD_VER >= 11
     64 
     65 int main()
     66 {
     67     test<forward_iterator<int*> >();
     68     test<bidirectional_iterator<int*> >();
     69     test<random_access_iterator<int*> >();
     70     test<int*>();
     71 
     72 #if TEST_STD_VER >= 11
     73     test1<forward_iterator<std::unique_ptr<int>*> >();
     74     test1<bidirectional_iterator<std::unique_ptr<int>*> >();
     75     test1<random_access_iterator<std::unique_ptr<int>*> >();
     76     test1<std::unique_ptr<int>*>();
     77 #endif // TEST_STD_VER >= 11
     78 }
     79