1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // template<ForwardIterator Iter, Predicate<auto, Iter::value_type> Pred>
13 // requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
14 // && CopyConstructible<Pred>
16 // remove_if(Iter first, Iter last, Pred pred);
21 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
25 #include "test_iterators.h"
26 #include "counting_predicates.hpp"
28 bool equal2 ( int i ) { return i == 2; }
34 int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
35 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
36 // int* r = std::remove_if(ia, ia+sa, std::bind2nd(std::equal_to<int>(), 2));
37 unary_counting_predicate<bool(*)(int), int> cp(equal2);
38 int* r = std::remove_if(ia, ia+sa, std::ref(cp));
39 assert(r == ia + sa-3);
46 assert(cp.count() == sa);
49 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
53 bool operator()(const std::unique_ptr<int>& i) {return *i == 2;}
60 const unsigned sa = 9;
61 std::unique_ptr<int> ia[sa];
62 ia[0].reset(new int(0));
63 ia[1].reset(new int(1));
64 ia[2].reset(new int(2));
65 ia[3].reset(new int(3));
66 ia[4].reset(new int(4));
67 ia[5].reset(new int(2));
68 ia[6].reset(new int(3));
69 ia[7].reset(new int(4));
70 ia[8].reset(new int(2));
71 Iter r = std::remove_if(Iter(ia), Iter(ia+sa), pred());
72 assert(base(r) == ia + sa-3);
81 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
85 test<forward_iterator<int*> >();
86 test<bidirectional_iterator<int*> >();
87 test<random_access_iterator<int*> >();
90 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
92 test1<forward_iterator<std::unique_ptr<int>*> >();
93 test1<bidirectional_iterator<std::unique_ptr<int>*> >();
94 test1<random_access_iterator<std::unique_ptr<int>*> >();
95 test1<std::unique_ptr<int>*>();
97 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES