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 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10
11 // <map>
12
13 // template <class Key, class T, class Compare, class Allocator, class Predicate>
14 // void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred);
15
16 #include <map>
17
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21
22 using Init = std::initializer_list<int>;
23 template <typename M>
make(Init vals)24 M make (Init vals)
25 {
26 M ret;
27 for (int v : vals)
28 ret[v] = v + 10;
29 return ret;
30 }
31
32 template <typename M, typename Pred>
33 void
test0(Init vals,Pred p,Init expected)34 test0(Init vals, Pred p, Init expected)
35 {
36 M s = make<M> (vals);
37 ASSERT_SAME_TYPE(void, decltype(std::erase_if(s, p)));
38 std::erase_if(s, p);
39 assert(s == make<M>(expected));
40 }
41
42 template <typename S>
test()43 void test()
44 {
45 auto is1 = [](auto v) { return v.first == 1;};
46 auto is2 = [](auto v) { return v.first == 2;};
47 auto is3 = [](auto v) { return v.first == 3;};
48 auto is4 = [](auto v) { return v.first == 4;};
49 auto True = [](auto) { return true; };
50 auto False = [](auto) { return false; };
51
52 test0<S>({}, is1, {});
53
54 test0<S>({1}, is1, {});
55 test0<S>({1}, is2, {1});
56
57 test0<S>({1,2}, is1, {2});
58 test0<S>({1,2}, is2, {1});
59 test0<S>({1,2}, is3, {1,2});
60
61 test0<S>({1,2,3}, is1, {2,3});
62 test0<S>({1,2,3}, is2, {1,3});
63 test0<S>({1,2,3}, is3, {1,2});
64 test0<S>({1,2,3}, is4, {1,2,3});
65
66 test0<S>({1,2,3}, True, {});
67 test0<S>({1,2,3}, False, {1,2,3});
68 }
69
main()70 int main()
71 {
72 test<std::map<int, int>>();
73 test<std::map<int, int, std::less<int>, min_allocator<std::pair<const int, int>>>> ();
74 test<std::map<int, int, std::less<int>, test_allocator<std::pair<const int, int>>>> ();
75
76 test<std::map<long, short>>();
77 test<std::map<short, double>>();
78 }
79
80