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_set |
14 | |
15 | // iterator erase(const_iterator first, const_iterator last) |
16 | |
17 | #include <unordered_set> |
18 | #include <algorithm> |
19 | #include <cassert> |
20 | |
21 | #include "test_macros.h" |
22 | #include "min_allocator.h" |
23 | |
24 | int main(int, char**) |
25 | { |
26 | { |
27 | typedef std::unordered_set<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); |
41 | C::iterator k = c.erase(first: i, last: i); |
42 | assert(k == i); |
43 | assert(c.size() == 4); |
44 | assert(c.count(1) == 1); |
45 | assert(c.count(2) == 1); |
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() == 3); |
51 | assert(c.count(1) == 1); |
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_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; |
62 | typedef int P; |
63 | P a[] = |
64 | { |
65 | P(1), |
66 | P(2), |
67 | P(3), |
68 | P(4), |
69 | P(1), |
70 | P(2) |
71 | }; |
72 | C c(a, a + sizeof(a)/sizeof(a[0])); |
73 | C::const_iterator i = c.find(2); |
74 | C::const_iterator j = std::next(i); |
75 | C::iterator k = c.erase(i, i); |
76 | assert(k == i); |
77 | assert(c.size() == 4); |
78 | assert(c.count(1) == 1); |
79 | assert(c.count(2) == 1); |
80 | assert(c.count(3) == 1); |
81 | assert(c.count(4) == 1); |
82 | |
83 | k = c.erase(i, j); |
84 | assert(c.size() == 3); |
85 | assert(c.count(1) == 1); |
86 | assert(c.count(3) == 1); |
87 | assert(c.count(4) == 1); |
88 | |
89 | k = c.erase(c.cbegin(), c.cend()); |
90 | assert(c.size() == 0); |
91 | assert(k == c.end()); |
92 | } |
93 | #endif |
94 | |
95 | return 0; |
96 | } |
97 | |