| 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 | typedef std::unordered_multiset<int> C; |
| 27 | typedef int P; |
| 28 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
| 29 | C c(a, a + sizeof(a) / sizeof(a[0])); |
| 30 | C::const_iterator i = c.find(x: 2); |
| 31 | C::const_iterator j = std::next(x: i, n: 2); |
| 32 | C::iterator k = c.erase(first: i, last: i); |
| 33 | assert(k == i); |
| 34 | assert(c.size() == 6); |
| 35 | assert(c.count(1) == 2); |
| 36 | assert(c.count(2) == 2); |
| 37 | assert(c.count(3) == 1); |
| 38 | assert(c.count(4) == 1); |
| 39 | |
| 40 | k = c.erase(first: i, last: j); |
| 41 | assert(c.size() == 4); |
| 42 | assert(c.count(1) == 2); |
| 43 | assert(c.count(3) == 1); |
| 44 | assert(c.count(4) == 1); |
| 45 | |
| 46 | k = c.erase(first: c.cbegin(), last: c.cend()); |
| 47 | assert(c.size() == 0); |
| 48 | assert(k == c.end()); |
| 49 | } |
| 50 | #if TEST_STD_VER >= 11 |
| 51 | { |
| 52 | typedef std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; |
| 53 | typedef int P; |
| 54 | P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)}; |
| 55 | C c(a, a + sizeof(a) / sizeof(a[0])); |
| 56 | C::const_iterator i = c.find(2); |
| 57 | C::const_iterator j = std::next(i, 2); |
| 58 | C::iterator k = c.erase(i, i); |
| 59 | assert(k == i); |
| 60 | assert(c.size() == 6); |
| 61 | assert(c.count(1) == 2); |
| 62 | assert(c.count(2) == 2); |
| 63 | assert(c.count(3) == 1); |
| 64 | assert(c.count(4) == 1); |
| 65 | |
| 66 | k = c.erase(i, j); |
| 67 | assert(c.size() == 4); |
| 68 | assert(c.count(1) == 2); |
| 69 | assert(c.count(3) == 1); |
| 70 | assert(c.count(4) == 1); |
| 71 | |
| 72 | k = c.erase(c.cbegin(), c.cend()); |
| 73 | assert(c.size() == 0); |
| 74 | assert(k == c.end()); |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |