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 | // 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 | typedef std::unordered_multiset<int> C; |
26 | typedef C::iterator I; |
27 | typedef int P; |
28 | P a[] = {P(10), P(20), P(30), P(40), P(50), P(50), P(50), P(60), P(70), P(80)}; |
29 | C c(std::begin(arr&: a), std::end(arr&: a)); |
30 | std::pair<I, I> r = c.equal_range(x: 30); |
31 | assert(std::distance(r.first, r.second) == 1); |
32 | assert(*r.first == 30); |
33 | r = c.equal_range(x: 5); |
34 | assert(std::distance(r.first, r.second) == 0); |
35 | r = c.equal_range(x: 50); |
36 | assert(std::distance(r.first, r.second) == 3); |
37 | assert(*r.first == 50); |
38 | ++r.first; |
39 | assert(*r.first == 50); |
40 | ++r.first; |
41 | assert(*r.first == 50); |
42 | } |
43 | #if TEST_STD_VER >= 11 |
44 | { |
45 | typedef std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; |
46 | typedef C::iterator I; |
47 | typedef int P; |
48 | P a[] = {P(10), P(20), P(30), P(40), P(50), P(50), P(50), P(60), P(70), P(80)}; |
49 | C c(std::begin(a), std::end(a)); |
50 | std::pair<I, I> r = c.equal_range(30); |
51 | assert(std::distance(r.first, r.second) == 1); |
52 | assert(*r.first == 30); |
53 | r = c.equal_range(5); |
54 | assert(std::distance(r.first, r.second) == 0); |
55 | r = c.equal_range(50); |
56 | assert(std::distance(r.first, r.second) == 3); |
57 | assert(*r.first == 50); |
58 | ++r.first; |
59 | assert(*r.first == 50); |
60 | ++r.first; |
61 | assert(*r.first == 50); |
62 | } |
63 | #endif |
64 | |
65 | return 0; |
66 | } |
67 | |