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_set |
14 | |
15 | // pair<iterator, iterator> equal_range(const key_type& k); |
16 | |
17 | #include <unordered_set> |
18 | #include <cassert> |
19 | |
20 | #include "test_macros.h" |
21 | #include "min_allocator.h" |
22 | |
23 | int main(int, char**) |
24 | { |
25 | { |
26 | typedef std::unordered_set<int> C; |
27 | typedef C::iterator I; |
28 | typedef int P; |
29 | P a[] = |
30 | { |
31 | P(10), |
32 | P(20), |
33 | P(30), |
34 | P(40), |
35 | P(50), |
36 | P(50), |
37 | P(50), |
38 | P(60), |
39 | P(70), |
40 | P(80) |
41 | }; |
42 | C c(std::begin(arr&: a), std::end(arr&: a)); |
43 | std::pair<I, I> r = c.equal_range(x: 30); |
44 | assert(std::distance(r.first, r.second) == 1); |
45 | assert(*r.first == 30); |
46 | r = c.equal_range(x: 5); |
47 | assert(std::distance(r.first, r.second) == 0); |
48 | r = c.equal_range(x: 50); |
49 | assert(std::distance(r.first, r.second) == 1); |
50 | assert(*r.first == 50); |
51 | } |
52 | #if TEST_STD_VER >= 11 |
53 | { |
54 | typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; |
55 | typedef C::iterator I; |
56 | typedef int P; |
57 | P a[] = |
58 | { |
59 | P(10), |
60 | P(20), |
61 | P(30), |
62 | P(40), |
63 | P(50), |
64 | P(50), |
65 | P(50), |
66 | P(60), |
67 | P(70), |
68 | P(80) |
69 | }; |
70 | C c(std::begin(a), std::end(a)); |
71 | std::pair<I, I> r = c.equal_range(30); |
72 | assert(std::distance(r.first, r.second) == 1); |
73 | assert(*r.first == 30); |
74 | r = c.equal_range(5); |
75 | assert(std::distance(r.first, r.second) == 0); |
76 | r = c.equal_range(50); |
77 | assert(std::distance(r.first, r.second) == 1); |
78 | assert(*r.first == 50); |
79 | } |
80 | #endif |
81 | |
82 | return 0; |
83 | } |
84 | |