[RISCV] Add a default assignment of Inst{12-7} to RVInst16CSS. NFC
[llvm-project.git] / libcxx / test / std / containers / associative / multimap / multimap.erasure / erase_if.pass.cpp
blob89ab932f47b00c8001371c3f0ca170bb05cc716f
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++03, c++11, c++14, c++17
10 // <map>
12 // template <class Key, class T, class Compare, class Allocator, class Predicate>
13 // typename multimap<Key, T, Compare, Allocator>::size_type
14 // erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);
16 #include <map>
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
22 using Init = std::initializer_list<int>;
23 template <typename M>
24 M make (Init vals)
26 M ret;
27 for (int v : vals)
28 ret.emplace(static_cast<typename M::key_type>(v), static_cast<typename M::mapped_type>(v + 10));
29 return ret;
32 template <typename M, typename Pred>
33 void test0(Init vals, Pred p, Init expected, std::size_t expected_erased_count) {
34 M s = make<M>(vals);
35 ASSERT_SAME_TYPE(typename M::size_type, decltype(std::erase_if(s, p)));
36 assert(expected_erased_count == std::erase_if(s, p));
37 assert(s == make<M>(expected));
40 template <typename S>
41 void test()
43 auto is1 = [](auto v) { return v.first == 1;};
44 auto is2 = [](auto v) { return v.first == 2;};
45 auto is3 = [](auto v) { return v.first == 3;};
46 auto is4 = [](auto v) { return v.first == 4;};
47 auto True = [](auto) { return true; };
48 auto False = [](auto) { return false; };
50 test0<S>({}, is1, {}, 0);
52 test0<S>({1}, is1, {}, 1);
53 test0<S>({1}, is2, {1}, 0);
55 test0<S>({1, 2}, is1, {2}, 1);
56 test0<S>({1, 2}, is2, {1}, 1);
57 test0<S>({1, 2}, is3, {1, 2}, 0);
58 test0<S>({1, 1}, is1, {}, 2);
59 test0<S>({1, 1}, is3, {1, 1}, 0);
61 test0<S>({1, 2, 3}, is1, {2, 3}, 1);
62 test0<S>({1, 2, 3}, is2, {1, 3}, 1);
63 test0<S>({1, 2, 3}, is3, {1, 2}, 1);
64 test0<S>({1, 2, 3}, is4, {1, 2, 3}, 0);
66 test0<S>({1, 1, 1}, is1, {}, 3);
67 test0<S>({1, 1, 1}, is2, {1, 1, 1}, 0);
68 test0<S>({1, 1, 2}, is1, {2}, 2);
69 test0<S>({1, 1, 2}, is2, {1, 1}, 1);
70 test0<S>({1, 1, 2}, is3, {1, 1, 2}, 0);
71 test0<S>({1, 2, 2}, is1, {2, 2}, 1);
72 test0<S>({1, 2, 2}, is2, {1}, 2);
73 test0<S>({1, 2, 2}, is3, {1, 2, 2}, 0);
75 test0<S>({1, 2, 3}, True, {}, 3);
76 test0<S>({1, 2, 3}, False, {1, 2, 3}, 0);
79 int main(int, char**)
81 test<std::multimap<int, int>>();
82 test<std::multimap<int, int, std::less<int>, min_allocator<std::pair<const int, int>>>> ();
83 test<std::multimap<int, int, std::less<int>, test_allocator<std::pair<const int, int>>>> ();
85 test<std::multimap<long, short>>();
86 test<std::multimap<short, double>>();
88 return 0;