[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / unord / unord.multiset / erase_if.pass.cpp
blob7bdc4f871571fa72937c1888b25eb40534bf3ae4
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 // <set>
12 // template <class T, class Hash, class Compare, class Allocator, class Predicate>
13 // typename unordered_multiset<T, Hash, Compare, Allocator>::size_type
14 // erase_if(unordered_multiset<T, Hash, Compare, Allocator>& c, Predicate pred);
16 #include <unordered_set>
17 #include <algorithm>
19 #include "test_macros.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
23 using Init = std::initializer_list<int>;
25 template <typename M>
26 M make (Init vals)
28 M ret;
29 for (int v : vals)
30 ret.insert(v);
31 return ret;
34 template <typename M, typename Pred>
35 void test0(Init vals, Pred p, Init expected, std::size_t expected_erased_count) {
36 M s = make<M>(vals);
37 ASSERT_SAME_TYPE(typename M::size_type, decltype(std::erase_if(s, p)));
38 assert(expected_erased_count == std::erase_if(s, p));
39 M e = make<M>(expected);
40 assert((std::is_permutation(s.begin(), s.end(), e.begin(), e.end())));
43 template <typename S>
44 void test()
46 auto is1 = [](auto v) { return v == 1;};
47 auto is2 = [](auto v) { return v == 2;};
48 auto is3 = [](auto v) { return v == 3;};
49 auto is4 = [](auto v) { return v == 4;};
50 auto True = [](auto) { return true; };
51 auto False = [](auto) { return false; };
53 test0<S>({}, is1, {}, 0);
55 test0<S>({1}, is1, {}, 1);
56 test0<S>({1}, is2, {1}, 0);
58 test0<S>({1, 2}, is1, {2}, 1);
59 test0<S>({1, 2}, is2, {1}, 1);
60 test0<S>({1, 2}, is3, {1, 2}, 0);
61 test0<S>({1, 1}, is1, {}, 2);
62 test0<S>({1, 1}, is3, {1, 1}, 0);
64 test0<S>({1, 2, 3}, is1, {2, 3}, 1);
65 test0<S>({1, 2, 3}, is2, {1, 3}, 1);
66 test0<S>({1, 2, 3}, is3, {1, 2}, 1);
67 test0<S>({1, 2, 3}, is4, {1, 2, 3}, 0);
69 test0<S>({1, 1, 1}, is1, {}, 3);
70 test0<S>({1, 1, 1}, is2, {1, 1, 1}, 0);
71 test0<S>({1, 1, 2}, is1, {2}, 2);
72 test0<S>({1, 1, 2}, is2, {1, 1}, 1);
73 test0<S>({1, 1, 2}, is3, {1, 1, 2}, 0);
74 test0<S>({1, 2, 2}, is1, {2, 2}, 1);
75 test0<S>({1, 2, 2}, is2, {1}, 2);
76 test0<S>({1, 2, 2}, is3, {1, 2, 2}, 0);
78 test0<S>({1, 2, 3}, True, {}, 3);
79 test0<S>({1, 2, 3}, False, {1, 2, 3}, 0);
82 int main(int, char**)
84 test<std::unordered_multiset<int>>();
85 test<std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>> ();
86 test<std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, test_allocator<int>>> ();
88 test<std::unordered_multiset<long>>();
89 test<std::unordered_multiset<double>>();
91 return 0;