| 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 |
{ |
| 24 |
typedef std::multiset<int> M; |
| 25 |
typedef int V; |
| 26 |
typedef M::size_type I; |
| 27 |
V ar[] = |
| 28 |
{ |
| 29 |
3, |
| 30 |
3, |
| 31 |
3, |
| 32 |
5, |
| 33 |
5, |
| 34 |
5, |
| 35 |
7, |
| 36 |
7, |
| 37 |
7 |
| 38 |
}; |
| 39 |
M m(ar, ar + sizeof(ar)/sizeof(ar[0])); |
| 40 |
assert(m.size() == 9); |
| 41 |
I i = m.erase(6); |
| 42 |
assert(m.size() == 9); |
| 43 |
assert(i == 0); |
| 44 |
assert(*std::next(m.begin(), 0) == 3); |
| 45 |
assert(*std::next(m.begin(), 1) == 3); |
| 46 |
assert(*std::next(m.begin(), 2) == 3); |
| 47 |
assert(*std::next(m.begin(), 3) == 5); |
| 48 |
assert(*std::next(m.begin(), 4) == 5); |
| 49 |
assert(*std::next(m.begin(), 5) == 5); |
| 50 |
assert(*std::next(m.begin(), 6) == 7); |
| 51 |
assert(*std::next(m.begin(), 7) == 7); |
| 52 |
assert(*std::next(m.begin(), 8) == 7); |
| 53 |
|
| 54 |
i = m.erase(5); |
| 55 |
assert(m.size() == 6); |
| 56 |
assert(i == 3); |
| 57 |
assert(*std::next(m.begin(), 0) == 3); |
| 58 |
assert(*std::next(m.begin(), 1) == 3); |
| 59 |
assert(*std::next(m.begin(), 2) == 3); |
| 60 |
assert(*std::next(m.begin(), 3) == 7); |
| 61 |
assert(*std::next(m.begin(), 4) == 7); |
| 62 |
assert(*std::next(m.begin(), 5) == 7); |
| 63 |
|
| 64 |
i = m.erase(3); |
| 65 |
assert(m.size() == 3); |
| 66 |
assert(i == 3); |
| 67 |
assert(*std::next(m.begin(), 0) == 7); |
| 68 |
assert(*std::next(m.begin(), 1) == 7); |
| 69 |
assert(*std::next(m.begin(), 2) == 7); |
| 70 |
|
| 71 |
i = m.erase(7); |
| 72 |
assert(m.size() == 0); |
| 73 |
assert(i == 3); |
| 74 |
} |
| 75 |
#if TEST_STD_VER >= 11 |
| 76 |
{ |
| 77 |
typedef std::multiset<int, std::less<int>, min_allocator<int>> M; |
| 78 |
typedef int V; |
| 79 |
typedef M::size_type I; |
| 80 |
V ar[] = |
| 81 |
{ |
| 82 |
3, |
| 83 |
3, |
| 84 |
3, |
| 85 |
5, |
| 86 |
5, |
| 87 |
5, |
| 88 |
7, |
| 89 |
7, |
| 90 |
7 |
| 91 |
}; |
| 92 |
M m(ar, ar + sizeof(ar)/sizeof(ar[0])); |
| 93 |
assert(m.size() == 9); |
| 94 |
I i = m.erase(6); |
| 95 |
assert(m.size() == 9); |
| 96 |
assert(i == 0); |
| 97 |
assert(*std::next(m.begin(), 0) == 3); |
| 98 |
assert(*std::next(m.begin(), 1) == 3); |
| 99 |
assert(*std::next(m.begin(), 2) == 3); |
| 100 |
assert(*std::next(m.begin(), 3) == 5); |
| 101 |
assert(*std::next(m.begin(), 4) == 5); |
| 102 |
assert(*std::next(m.begin(), 5) == 5); |
| 103 |
assert(*std::next(m.begin(), 6) == 7); |
| 104 |
assert(*std::next(m.begin(), 7) == 7); |
| 105 |
assert(*std::next(m.begin(), 8) == 7); |
| 106 |
|
| 107 |
i = m.erase(5); |
| 108 |
assert(m.size() == 6); |
| 109 |
assert(i == 3); |
| 110 |
assert(*std::next(m.begin(), 0) == 3); |
| 111 |
assert(*std::next(m.begin(), 1) == 3); |
| 112 |
assert(*std::next(m.begin(), 2) == 3); |
| 113 |
assert(*std::next(m.begin(), 3) == 7); |
| 114 |
assert(*std::next(m.begin(), 4) == 7); |
| 115 |
assert(*std::next(m.begin(), 5) == 7); |
| 116 |
|
| 117 |
i = m.erase(3); |
| 118 |
assert(m.size() == 3); |
| 119 |
assert(i == 3); |
| 120 |
assert(*std::next(m.begin(), 0) == 7); |
| 121 |
assert(*std::next(m.begin(), 1) == 7); |
| 122 |
assert(*std::next(m.begin(), 2) == 7); |
| 123 |
|
| 124 |
i = m.erase(7); |
| 125 |
assert(m.size() == 0); |
| 126 |
assert(i == 3); |
| 127 |
} |
| 128 |
#endif |
| 129 |
|
| 130 |
return 0; |
| 131 |
} |