1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
9
10 // <vector>
11
12 // template <class T, class Allocator, class Predicate>
13 // void erase_if(vector<T, Allocator>& c, Predicate pred);
14
15 #include <vector>
16
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "min_allocator.h"
20
21 template <class S, class Pred>
22 void
test0(S s,Pred p,S expected)23 test0(S s, Pred p, S expected)
24 {
25 ASSERT_SAME_TYPE(void, decltype(std::erase_if(s, p)));
26 std::erase_if(s, p);
27 assert(s == expected);
28 }
29
30 template <typename S>
test()31 void test()
32 {
33 auto is1 = [](auto v) { return v == 1;};
34 auto is2 = [](auto v) { return v == 2;};
35 auto is3 = [](auto v) { return v == 3;};
36 auto is4 = [](auto v) { return v == 4;};
37 auto True = [](auto) { return true; };
38 auto False = [](auto) { return false; };
39
40 test0(S(), is1, S());
41
42 test0(S({1}), is1, S());
43 test0(S({1}), is2, S({1}));
44
45 test0(S({1,2}), is1, S({2}));
46 test0(S({1,2}), is2, S({1}));
47 test0(S({1,2}), is3, S({1,2}));
48 test0(S({1,1}), is1, S());
49 test0(S({1,1}), is3, S({1,1}));
50
51 test0(S({1,2,3}), is1, S({2,3}));
52 test0(S({1,2,3}), is2, S({1,3}));
53 test0(S({1,2,3}), is3, S({1,2}));
54 test0(S({1,2,3}), is4, S({1,2,3}));
55
56 test0(S({1,1,1}), is1, S());
57 test0(S({1,1,1}), is2, S({1,1,1}));
58 test0(S({1,1,2}), is1, S({2}));
59 test0(S({1,1,2}), is2, S({1,1}));
60 test0(S({1,1,2}), is3, S({1,1,2}));
61 test0(S({1,2,2}), is1, S({2,2}));
62 test0(S({1,2,2}), is2, S({1}));
63 test0(S({1,2,2}), is3, S({1,2,2}));
64
65 test0(S({1,2,3}), True, S());
66 test0(S({1,2,3}), False, S({1,2,3}));
67 }
68
main(int,char **)69 int main(int, char**)
70 {
71 test<std::vector<int>>();
72 test<std::vector<int, min_allocator<int>>> ();
73 test<std::vector<int, test_allocator<int>>> ();
74
75 test<std::vector<long>>();
76 test<std::vector<double>>();
77
78 return 0;
79 }
80