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 | |
9 | // <unordered_set> |
10 | |
11 | // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
12 | // class Alloc = allocator<Value>> |
13 | // class unordered_multiset |
14 | |
15 | // iterator erase(const_iterator first, const_iterator last) |
16 | |
17 | #include <unordered_set> |
18 | #include <cassert> |
19 | #include <iterator> |
20 | |
21 | #include "test_macros.h" |
22 | #include "min_allocator.h" |
23 | |
24 | int main(int, char**) |
25 | { |
26 | { |
27 | typedef std::unordered_multiset<int> C; |
28 | typedef int P; |
29 | P a[] = |
30 | { |
31 | P(1), |
32 | P(2), |
33 | P(3), |
34 | P(4), |
35 | P(1), |
36 | P(2) |
37 | }; |
38 | C c(a, a + sizeof(a)/sizeof(a[0])); |
39 | C::const_iterator i = c.find(x: 2); |
40 | C::const_iterator j = std::next(x: i, n: 2); |
41 | C::iterator k = c.erase(first: i, last: i); |
42 | assert(k == i); |
43 | assert(c.size() == 6); |
44 | assert(c.count(1) == 2); |
45 | assert(c.count(2) == 2); |
46 | assert(c.count(3) == 1); |
47 | assert(c.count(4) == 1); |
48 | |
49 | k = c.erase(first: i, last: j); |
50 | assert(c.size() == 4); |
51 | assert(c.count(1) == 2); |
52 | assert(c.count(3) == 1); |
53 | assert(c.count(4) == 1); |
54 | |
55 | k = c.erase(first: c.cbegin(), last: c.cend()); |
56 | assert(c.size() == 0); |
57 | assert(k == c.end()); |
58 | } |
59 | #if TEST_STD_VER >= 11 |
60 | { |
61 | typedef std::unordered_multiset<int, std::hash<int>, |
62 | std::equal_to<int>, min_allocator<int>> C; |
63 | typedef int P; |
64 | P a[] = |
65 | { |
66 | P(1), |
67 | P(2), |
68 | P(3), |
69 | P(4), |
70 | P(1), |
71 | P(2) |
72 | }; |
73 | C c(a, a + sizeof(a)/sizeof(a[0])); |
74 | C::const_iterator i = c.find(2); |
75 | C::const_iterator j = std::next(i, 2); |
76 | C::iterator k = c.erase(i, i); |
77 | assert(k == i); |
78 | assert(c.size() == 6); |
79 | assert(c.count(1) == 2); |
80 | assert(c.count(2) == 2); |
81 | assert(c.count(3) == 1); |
82 | assert(c.count(4) == 1); |
83 | |
84 | k = c.erase(i, j); |
85 | assert(c.size() == 4); |
86 | assert(c.count(1) == 2); |
87 | assert(c.count(3) == 1); |
88 | assert(c.count(4) == 1); |
89 | |
90 | k = c.erase(c.cbegin(), c.cend()); |
91 | assert(c.size() == 0); |
92 | assert(k == c.end()); |
93 | } |
94 | #endif |
95 | |
96 | return 0; |
97 | } |
98 | |