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(multimap<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.insert(typename M::value_type(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 test0<S>({1,1}, is1, {});
61 test0<S>({1,1}, is3, {1,1});
62
63 test0<S>({1,2,3}, is1, {2,3});
64 test0<S>({1,2,3}, is2, {1,3});
65 test0<S>({1,2,3}, is3, {1,2});
66 test0<S>({1,2,3}, is4, {1,2,3});
67
68 test0<S>({1,1,1}, is1, {});
69 test0<S>({1,1,1}, is2, {1,1,1});
70 test0<S>({1,1,2}, is1, {2});
71 test0<S>({1,1,2}, is2, {1,1});
72 test0<S>({1,1,2}, is3, {1,1,2});
73 test0<S>({1,2,2}, is1, {2,2});
74 test0<S>({1,2,2}, is2, {1});
75 test0<S>({1,2,2}, is3, {1,2,2});
76
77 test0<S>({1,2,3}, True, {});
78 test0<S>({1,2,3}, False, {1,2,3});
79 }
80
main()81 int main()
82 {
83 test<std::multimap<int, int>>();
84 test<std::multimap<int, int, std::less<int>, min_allocator<std::pair<const int, int>>>> ();
85 test<std::multimap<int, int, std::less<int>, test_allocator<std::pair<const int, int>>>> ();
86
87 test<std::multimap<long, short>>();
88 test<std::multimap<short, double>>();
89 }
90