| 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 |
// iterator begin() {return __table_.begin();} |
| 16 |
// iterator end() {return __table_.end();} |
| 17 |
// const_iterator begin() const {return __table_.begin();} |
| 18 |
// const_iterator end() const {return __table_.end();} |
| 19 |
// const_iterator cbegin() const {return __table_.begin();} |
| 20 |
// const_iterator cend() const {return __table_.end();} |
| 21 |
|
| 22 |
#include <unordered_set> |
| 23 |
#include <cassert> |
| 24 |
#include <cstddef> |
| 25 |
|
| 26 |
#include "test_macros.h" |
| 27 |
#include "min_allocator.h" |
| 28 |
|
| 29 |
int main(int, char**) |
| 30 |
{ |
| 31 |
{ |
| 32 |
typedef std::unordered_set<int> C; |
| 33 |
typedef int P; |
| 34 |
P a[] = |
| 35 |
{ |
| 36 |
P(1), |
| 37 |
P(2), |
| 38 |
P(3), |
| 39 |
P(4), |
| 40 |
P(1), |
| 41 |
P(2) |
| 42 |
}; |
| 43 |
C c(a, a + sizeof(a)/sizeof(a[0])); |
| 44 |
assert(c.bucket_count() >= 5); |
| 45 |
assert(c.size() == 4); |
| 46 |
assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); |
| 47 |
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); |
| 48 |
C::iterator i; |
| 49 |
} |
| 50 |
{ |
| 51 |
typedef std::unordered_set<int> C; |
| 52 |
typedef int P; |
| 53 |
P a[] = |
| 54 |
{ |
| 55 |
P(1), |
| 56 |
P(2), |
| 57 |
P(3), |
| 58 |
P(4), |
| 59 |
P(1), |
| 60 |
P(2) |
| 61 |
}; |
| 62 |
const C c(a, a + sizeof(a)/sizeof(a[0])); |
| 63 |
assert(c.bucket_count() >= 5); |
| 64 |
assert(c.size() == 4); |
| 65 |
assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); |
| 66 |
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); |
| 67 |
C::const_iterator i; |
| 68 |
} |
| 69 |
#if TEST_STD_VER >= 11 |
| 70 |
{ |
| 71 |
typedef std::unordered_set<int, std::hash<int>, |
| 72 |
std::equal_to<int>, min_allocator<int>> C; |
| 73 |
typedef int P; |
| 74 |
P a[] = |
| 75 |
{ |
| 76 |
P(1), |
| 77 |
P(2), |
| 78 |
P(3), |
| 79 |
P(4), |
| 80 |
P(1), |
| 81 |
P(2) |
| 82 |
}; |
| 83 |
C c(a, a + sizeof(a)/sizeof(a[0])); |
| 84 |
assert(c.bucket_count() >= 5); |
| 85 |
assert(c.size() == 4); |
| 86 |
assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); |
| 87 |
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); |
| 88 |
C::iterator i; |
| 89 |
} |
| 90 |
{ |
| 91 |
typedef std::unordered_set<int, std::hash<int>, |
| 92 |
std::equal_to<int>, min_allocator<int>> C; |
| 93 |
typedef int P; |
| 94 |
P a[] = |
| 95 |
{ |
| 96 |
P(1), |
| 97 |
P(2), |
| 98 |
P(3), |
| 99 |
P(4), |
| 100 |
P(1), |
| 101 |
P(2) |
| 102 |
}; |
| 103 |
const C c(a, a + sizeof(a)/sizeof(a[0])); |
| 104 |
assert(c.bucket_count() >= 5); |
| 105 |
assert(c.size() == 4); |
| 106 |
assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); |
| 107 |
assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); |
| 108 |
C::const_iterator i; |
| 109 |
} |
| 110 |
#endif |
| 111 |
#if TEST_STD_VER > 11 |
| 112 |
{ // N3644 testing |
| 113 |
typedef std::unordered_set<int> C; |
| 114 |
C::iterator ii1{}, ii2{}; |
| 115 |
C::iterator ii4 = ii1; |
| 116 |
C::const_iterator cii{}; |
| 117 |
assert ( ii1 == ii2 ); |
| 118 |
assert ( ii1 == ii4 ); |
| 119 |
|
| 120 |
assert (!(ii1 != ii2 )); |
| 121 |
|
| 122 |
assert ( (ii1 == cii )); |
| 123 |
assert ( (cii == ii1 )); |
| 124 |
assert (!(ii1 != cii )); |
| 125 |
assert (!(cii != ii1 )); |
| 126 |
} |
| 127 |
#endif |
| 128 |
|
| 129 |
return 0; |
| 130 |
} |