1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <unordered_set>
11
12// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
13//           class Alloc = allocator<Value>>
14// class unordered_set
15
16// iterator erase(const_iterator first, const_iterator last)
17
18#include <unordered_set>
19#include <cassert>
20
21#include "min_allocator.h"
22
23int main()
24{
25    {
26        typedef std::unordered_set<int> C;
27        typedef int P;
28        P a[] =
29        {
30            P(1),
31            P(2),
32            P(3),
33            P(4),
34            P(1),
35            P(2)
36        };
37        C c(a, a + sizeof(a)/sizeof(a[0]));
38        C::const_iterator i = c.find(2);
39        C::const_iterator j = next(i);
40        C::iterator k = c.erase(i, i);
41        assert(k == i);
42        assert(c.size() == 4);
43        assert(c.count(1) == 1);
44        assert(c.count(2) == 1);
45        assert(c.count(3) == 1);
46        assert(c.count(4) == 1);
47
48        k = c.erase(i, j);
49        assert(c.size() == 3);
50        assert(c.count(1) == 1);
51        assert(c.count(3) == 1);
52        assert(c.count(4) == 1);
53
54        k = c.erase(c.cbegin(), c.cend());
55        assert(c.size() == 0);
56        assert(k == c.end());
57    }
58#if __cplusplus >= 201103L
59    {
60        typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;
61        typedef int P;
62        P a[] =
63        {
64            P(1),
65            P(2),
66            P(3),
67            P(4),
68            P(1),
69            P(2)
70        };
71        C c(a, a + sizeof(a)/sizeof(a[0]));
72        C::const_iterator i = c.find(2);
73        C::const_iterator j = next(i);
74        C::iterator k = c.erase(i, i);
75        assert(k == i);
76        assert(c.size() == 4);
77        assert(c.count(1) == 1);
78        assert(c.count(2) == 1);
79        assert(c.count(3) == 1);
80        assert(c.count(4) == 1);
81
82        k = c.erase(i, j);
83        assert(c.size() == 3);
84        assert(c.count(1) == 1);
85        assert(c.count(3) == 1);
86        assert(c.count(4) == 1);
87
88        k = c.erase(c.cbegin(), c.cend());
89        assert(c.size() == 0);
90        assert(k == c.end());
91    }
92#endif
93}
94