llvm-project
78 строк · 2.4 Кб
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
9
10// <set>
11
12// template <class T, class Compare, class Allocator, class Predicate>
13// typename multiset<T, Compare, Allocator>::size_type
14// erase_if(multiset<T, Compare, Allocator>& c, Predicate pred);
15
16#include <set>
17
18#include "test_macros.h"
19#include "test_allocator.h"
20#include "min_allocator.h"
21
22template <class S, class Pred>
23void test0(S s, Pred p, S expected, std::size_t expected_erased_count) {
24ASSERT_SAME_TYPE(typename S::size_type, decltype(std::erase_if(s, p)));
25assert(expected_erased_count == std::erase_if(s, p));
26assert(s == expected);
27}
28
29template <typename S>
30void test()
31{
32auto is1 = [](auto v) { return v == 1;};
33auto is2 = [](auto v) { return v == 2;};
34auto is3 = [](auto v) { return v == 3;};
35auto is4 = [](auto v) { return v == 4;};
36auto True = [](auto) { return true; };
37auto False = [](auto) { return false; };
38
39test0(S(), is1, S(), 0);
40
41test0(S({1}), is1, S(), 1);
42test0(S({1}), is2, S({1}), 0);
43
44test0(S({1, 2}), is1, S({2}), 1);
45test0(S({1, 2}), is2, S({1}), 1);
46test0(S({1, 2}), is3, S({1, 2}), 0);
47test0(S({1, 1}), is1, S(), 2);
48test0(S({1, 1}), is3, S({1, 1}), 0);
49
50test0(S({1, 2, 3}), is1, S({2, 3}), 1);
51test0(S({1, 2, 3}), is2, S({1, 3}), 1);
52test0(S({1, 2, 3}), is3, S({1, 2}), 1);
53test0(S({1, 2, 3}), is4, S({1, 2, 3}), 0);
54
55test0(S({1, 1, 1}), is1, S(), 3);
56test0(S({1, 1, 1}), is2, S({1, 1, 1}), 0);
57test0(S({1, 1, 2}), is1, S({2}), 2);
58test0(S({1, 1, 2}), is2, S({1, 1}), 1);
59test0(S({1, 1, 2}), is3, S({1, 1, 2}), 0);
60test0(S({1, 2, 2}), is1, S({2, 2}), 1);
61test0(S({1, 2, 2}), is2, S({1}), 2);
62test0(S({1, 2, 2}), is3, S({1, 2, 2}), 0);
63
64test0(S({1, 2, 3}), True, S(), 3);
65test0(S({1, 2, 3}), False, S({1, 2, 3}), 0);
66}
67
68int main(int, char**)
69{
70test<std::multiset<int>>();
71test<std::multiset<int, std::less<int>, min_allocator<int>>> ();
72test<std::multiset<int, std::less<int>, test_allocator<int>>> ();
73
74test<std::multiset<long>>();
75test<std::multiset<double>>();
76
77return 0;
78}
79