| 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 | // <set> |
| 10 | |
| 11 | // class multiset |
| 12 | |
| 13 | // size_type erase(const key_type& k); |
| 14 | |
| 15 | #include <set> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "min_allocator.h" |
| 20 | |
| 21 | int main(int, char**) { |
| 22 | { |
| 23 | typedef std::multiset<int> M; |
| 24 | typedef int V; |
| 25 | typedef M::size_type I; |
| 26 | V ar[] = {3, 3, 3, 5, 5, 5, 7, 7, 7}; |
| 27 | M m(ar, ar + sizeof(ar) / sizeof(ar[0])); |
| 28 | assert(m.size() == 9); |
| 29 | I i = m.erase(x: 6); |
| 30 | assert(m.size() == 9); |
| 31 | assert(i == 0); |
| 32 | assert(*std::next(m.begin(), 0) == 3); |
| 33 | assert(*std::next(m.begin(), 1) == 3); |
| 34 | assert(*std::next(m.begin(), 2) == 3); |
| 35 | assert(*std::next(m.begin(), 3) == 5); |
| 36 | assert(*std::next(m.begin(), 4) == 5); |
| 37 | assert(*std::next(m.begin(), 5) == 5); |
| 38 | assert(*std::next(m.begin(), 6) == 7); |
| 39 | assert(*std::next(m.begin(), 7) == 7); |
| 40 | assert(*std::next(m.begin(), 8) == 7); |
| 41 | |
| 42 | i = m.erase(x: 5); |
| 43 | assert(m.size() == 6); |
| 44 | assert(i == 3); |
| 45 | assert(*std::next(m.begin(), 0) == 3); |
| 46 | assert(*std::next(m.begin(), 1) == 3); |
| 47 | assert(*std::next(m.begin(), 2) == 3); |
| 48 | assert(*std::next(m.begin(), 3) == 7); |
| 49 | assert(*std::next(m.begin(), 4) == 7); |
| 50 | assert(*std::next(m.begin(), 5) == 7); |
| 51 | |
| 52 | i = m.erase(x: 3); |
| 53 | assert(m.size() == 3); |
| 54 | assert(i == 3); |
| 55 | assert(*std::next(m.begin(), 0) == 7); |
| 56 | assert(*std::next(m.begin(), 1) == 7); |
| 57 | assert(*std::next(m.begin(), 2) == 7); |
| 58 | |
| 59 | i = m.erase(x: 7); |
| 60 | assert(m.size() == 0); |
| 61 | assert(i == 3); |
| 62 | } |
| 63 | #if TEST_STD_VER >= 11 |
| 64 | { |
| 65 | typedef std::multiset<int, std::less<int>, min_allocator<int>> M; |
| 66 | typedef int V; |
| 67 | typedef M::size_type I; |
| 68 | V ar[] = {3, 3, 3, 5, 5, 5, 7, 7, 7}; |
| 69 | M m(ar, ar + sizeof(ar) / sizeof(ar[0])); |
| 70 | assert(m.size() == 9); |
| 71 | I i = m.erase(6); |
| 72 | assert(m.size() == 9); |
| 73 | assert(i == 0); |
| 74 | assert(*std::next(m.begin(), 0) == 3); |
| 75 | assert(*std::next(m.begin(), 1) == 3); |
| 76 | assert(*std::next(m.begin(), 2) == 3); |
| 77 | assert(*std::next(m.begin(), 3) == 5); |
| 78 | assert(*std::next(m.begin(), 4) == 5); |
| 79 | assert(*std::next(m.begin(), 5) == 5); |
| 80 | assert(*std::next(m.begin(), 6) == 7); |
| 81 | assert(*std::next(m.begin(), 7) == 7); |
| 82 | assert(*std::next(m.begin(), 8) == 7); |
| 83 | |
| 84 | i = m.erase(5); |
| 85 | assert(m.size() == 6); |
| 86 | assert(i == 3); |
| 87 | assert(*std::next(m.begin(), 0) == 3); |
| 88 | assert(*std::next(m.begin(), 1) == 3); |
| 89 | assert(*std::next(m.begin(), 2) == 3); |
| 90 | assert(*std::next(m.begin(), 3) == 7); |
| 91 | assert(*std::next(m.begin(), 4) == 7); |
| 92 | assert(*std::next(m.begin(), 5) == 7); |
| 93 | |
| 94 | i = m.erase(3); |
| 95 | assert(m.size() == 3); |
| 96 | assert(i == 3); |
| 97 | assert(*std::next(m.begin(), 0) == 7); |
| 98 | assert(*std::next(m.begin(), 1) == 7); |
| 99 | assert(*std::next(m.begin(), 2) == 7); |
| 100 | |
| 101 | i = m.erase(7); |
| 102 | assert(m.size() == 0); |
| 103 | assert(i == 3); |
| 104 | } |
| 105 | #endif |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |