| 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 |
{ |
| 26 |
typedef std::unordered_multiset<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(a), std::end(a)); |
| 43 |
std::pair<I, I> r = c.equal_range(30); |
| 44 |
assert(std::distance(r.first, r.second) == 1); |
| 45 |
assert(*r.first == 30); |
| 46 |
r = c.equal_range(5); |
| 47 |
assert(std::distance(r.first, r.second) == 0); |
| 48 |
r = c.equal_range(50); |
| 49 |
assert(std::distance(r.first, r.second) == 3); |
| 50 |
assert(*r.first == 50); |
| 51 |
++r.first; |
| 52 |
assert(*r.first == 50); |
| 53 |
++r.first; |
| 54 |
assert(*r.first == 50); |
| 55 |
} |
| 56 |
#if TEST_STD_VER >= 11 |
| 57 |
{ |
| 58 |
typedef std::unordered_multiset<int, std::hash<int>, |
| 59 |
std::equal_to<int>, min_allocator<int>> C; |
| 60 |
typedef C::iterator I; |
| 61 |
typedef int P; |
| 62 |
P a[] = |
| 63 |
{ |
| 64 |
P(10), |
| 65 |
P(20), |
| 66 |
P(30), |
| 67 |
P(40), |
| 68 |
P(50), |
| 69 |
P(50), |
| 70 |
P(50), |
| 71 |
P(60), |
| 72 |
P(70), |
| 73 |
P(80) |
| 74 |
}; |
| 75 |
C c(std::begin(a), std::end(a)); |
| 76 |
std::pair<I, I> r = c.equal_range(30); |
| 77 |
assert(std::distance(r.first, r.second) == 1); |
| 78 |
assert(*r.first == 30); |
| 79 |
r = c.equal_range(5); |
| 80 |
assert(std::distance(r.first, r.second) == 0); |
| 81 |
r = c.equal_range(50); |
| 82 |
assert(std::distance(r.first, r.second) == 3); |
| 83 |
assert(*r.first == 50); |
| 84 |
++r.first; |
| 85 |
assert(*r.first == 50); |
| 86 |
++r.first; |
| 87 |
assert(*r.first == 50); |
| 88 |
} |
| 89 |
#endif |
| 90 |
|
| 91 |
return 0; |
| 92 |
} |