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 p)
16
17#include <unordered_set>
18#include <cassert>
19
20#include "test_macros.h"
21#include "min_allocator.h"
22
23struct TemplateConstructor {
24 template <typename T>
25 TemplateConstructor(const T&) {}
26};
27
28bool operator==(const TemplateConstructor&, const TemplateConstructor&) { return false; }
29struct Hash {
30 std::size_t operator()(const TemplateConstructor&) const { return 0; }
31};
32
33int main(int, char**) {
34 {
35 typedef std::unordered_multiset<int> C;
36 typedef int P;
37 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
38 C c(a, a + sizeof(a) / sizeof(a[0]));
39 C::const_iterator i = c.find(x: 2);
40 C::const_iterator i_next = i;
41 ++i_next;
42 C::iterator j = c.erase(position: i);
43 assert(j == i_next);
44
45 assert(c.size() == 5);
46 assert(c.count(1) == 2);
47 assert(c.count(2) == 1);
48 assert(c.count(3) == 1);
49 assert(c.count(4) == 1);
50 }
51#if TEST_STD_VER >= 11
52 {
53 typedef std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;
54 typedef int P;
55 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
56 C c(a, a + sizeof(a) / sizeof(a[0]));
57 C::const_iterator i = c.find(2);
58 C::const_iterator i_next = i;
59 ++i_next;
60 C::iterator j = c.erase(i);
61 assert(j == i_next);
62 assert(c.size() == 5);
63 assert(c.count(1) == 2);
64 assert(c.count(2) == 1);
65 assert(c.count(3) == 1);
66 assert(c.count(4) == 1);
67 }
68#endif
69#if TEST_STD_VER >= 14
70 {
71 // This is LWG #2059
72 typedef TemplateConstructor T;
73 typedef std::unordered_set<T, Hash> C;
74 typedef C::iterator I;
75
76 C m;
77 T a{0};
78 I it = m.find(a);
79 if (it != m.end())
80 m.erase(it);
81 }
82#endif
83
84 return 0;
85}
86

source code of libcxx/test/std/containers/unord/unord.multiset/erase_const_iter.pass.cpp