Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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_multiset |
| 15 | |
| 16 | // unordered_multiset(unordered_multiset&& u, const allocator_type& a); |
| 17 | |
| 18 | #include <unordered_set> |
| 19 | #include <cassert> |
Howard Hinnant | f836d53 | 2011-12-02 21:23:14 +0000 | [diff] [blame] | 20 | #include <cfloat> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
| 22 | #include "../../../test_compare.h" |
| 23 | #include "../../../test_hash.h" |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 24 | #include "test_allocator.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 25 | #include "min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | |
| 27 | int main() |
| 28 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 29 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | { |
| 31 | typedef int P; |
| 32 | typedef test_allocator<int> A; |
| 33 | typedef std::unordered_multiset<int, |
| 34 | test_hash<std::hash<int> >, |
| 35 | test_compare<std::equal_to<int> >, |
| 36 | A |
| 37 | > C; |
| 38 | P a[] = |
| 39 | { |
| 40 | P(1), |
| 41 | P(2), |
| 42 | P(3), |
| 43 | P(4), |
| 44 | P(1), |
| 45 | P(2) |
| 46 | }; |
| 47 | C c0(a, a + sizeof(a)/sizeof(a[0]), |
| 48 | 7, |
| 49 | test_hash<std::hash<int> >(8), |
| 50 | test_compare<std::equal_to<int> >(9), |
| 51 | A(10) |
| 52 | ); |
| 53 | C c(std::move(c0), A(12)); |
| 54 | assert(c.bucket_count() >= 7); |
| 55 | assert(c.size() == 6); |
| 56 | C::const_iterator i = c.cbegin(); |
| 57 | assert(*i == 1); |
| 58 | ++i; |
| 59 | assert(*i == 1); |
| 60 | ++i; |
| 61 | assert(*i == 2); |
| 62 | ++i; |
| 63 | assert(*i == 2); |
| 64 | ++i; |
| 65 | assert(*i == 3); |
| 66 | ++i; |
| 67 | assert(*i == 4); |
| 68 | assert(c.hash_function() == test_hash<std::hash<int> >(8)); |
| 69 | assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); |
| 70 | assert(c.get_allocator() == A(12)); |
| 71 | assert(!c.empty()); |
| 72 | assert(std::distance(c.begin(), c.end()) == c.size()); |
| 73 | assert(std::distance(c.cbegin(), c.cend()) == c.size()); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 74 | assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | assert(c.max_load_factor() == 1); |
| 76 | |
| 77 | assert(c0.empty()); |
| 78 | } |
| 79 | { |
| 80 | typedef int P; |
| 81 | typedef test_allocator<int> A; |
| 82 | typedef std::unordered_multiset<int, |
| 83 | test_hash<std::hash<int> >, |
| 84 | test_compare<std::equal_to<int> >, |
| 85 | A |
| 86 | > C; |
| 87 | P a[] = |
| 88 | { |
| 89 | P(1), |
| 90 | P(2), |
| 91 | P(3), |
| 92 | P(4), |
| 93 | P(1), |
| 94 | P(2) |
| 95 | }; |
| 96 | C c0(a, a + sizeof(a)/sizeof(a[0]), |
| 97 | 7, |
| 98 | test_hash<std::hash<int> >(8), |
| 99 | test_compare<std::equal_to<int> >(9), |
| 100 | A(10) |
| 101 | ); |
| 102 | C c(std::move(c0), A(10)); |
| 103 | assert(c.bucket_count() == 7); |
| 104 | assert(c.size() == 6); |
| 105 | assert(c.count(1) == 2); |
| 106 | assert(c.count(2) == 2); |
| 107 | assert(c.count(3) == 1); |
| 108 | assert(c.count(4) == 1); |
| 109 | assert(c.hash_function() == test_hash<std::hash<int> >(8)); |
| 110 | assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); |
| 111 | assert(c.get_allocator() == A(10)); |
| 112 | assert(!c.empty()); |
| 113 | assert(std::distance(c.begin(), c.end()) == c.size()); |
| 114 | assert(std::distance(c.cbegin(), c.cend()) == c.size()); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 115 | assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 116 | assert(c.max_load_factor() == 1); |
| 117 | |
| 118 | assert(c0.empty()); |
| 119 | } |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 120 | #if __cplusplus >= 201103L |
| 121 | { |
| 122 | typedef int P; |
| 123 | typedef min_allocator<int> A; |
| 124 | typedef std::unordered_multiset<int, |
| 125 | test_hash<std::hash<int> >, |
| 126 | test_compare<std::equal_to<int> >, |
| 127 | A |
| 128 | > C; |
| 129 | P a[] = |
| 130 | { |
| 131 | P(1), |
| 132 | P(2), |
| 133 | P(3), |
| 134 | P(4), |
| 135 | P(1), |
| 136 | P(2) |
| 137 | }; |
| 138 | C c0(a, a + sizeof(a)/sizeof(a[0]), |
| 139 | 7, |
| 140 | test_hash<std::hash<int> >(8), |
| 141 | test_compare<std::equal_to<int> >(9), |
| 142 | A() |
| 143 | ); |
| 144 | C c(std::move(c0), A()); |
| 145 | assert(c.bucket_count() >= 7); |
| 146 | assert(c.size() == 6); |
| 147 | C::const_iterator i = c.cbegin(); |
| 148 | assert(*i == 4); |
| 149 | ++i; |
| 150 | assert(*i == 3); |
| 151 | ++i; |
| 152 | assert(*i == 2); |
| 153 | ++i; |
| 154 | assert(*i == 2); |
| 155 | ++i; |
| 156 | assert(*i == 1); |
| 157 | ++i; |
| 158 | assert(*i == 1); |
| 159 | assert(c.hash_function() == test_hash<std::hash<int> >(8)); |
| 160 | assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); |
| 161 | assert(c.get_allocator() == A()); |
| 162 | assert(!c.empty()); |
| 163 | assert(std::distance(c.begin(), c.end()) == c.size()); |
| 164 | assert(std::distance(c.cbegin(), c.cend()) == c.size()); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 165 | assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 166 | assert(c.max_load_factor() == 1); |
| 167 | |
| 168 | assert(c0.empty()); |
| 169 | } |
| 170 | { |
| 171 | typedef int P; |
| 172 | typedef min_allocator<int> A; |
| 173 | typedef std::unordered_multiset<int, |
| 174 | test_hash<std::hash<int> >, |
| 175 | test_compare<std::equal_to<int> >, |
| 176 | A |
| 177 | > C; |
| 178 | P a[] = |
| 179 | { |
| 180 | P(1), |
| 181 | P(2), |
| 182 | P(3), |
| 183 | P(4), |
| 184 | P(1), |
| 185 | P(2) |
| 186 | }; |
| 187 | C c0(a, a + sizeof(a)/sizeof(a[0]), |
| 188 | 7, |
| 189 | test_hash<std::hash<int> >(8), |
| 190 | test_compare<std::equal_to<int> >(9), |
| 191 | A() |
| 192 | ); |
| 193 | C c(std::move(c0), A()); |
| 194 | assert(c.bucket_count() == 7); |
| 195 | assert(c.size() == 6); |
| 196 | assert(c.count(1) == 2); |
| 197 | assert(c.count(2) == 2); |
| 198 | assert(c.count(3) == 1); |
| 199 | assert(c.count(4) == 1); |
| 200 | assert(c.hash_function() == test_hash<std::hash<int> >(8)); |
| 201 | assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); |
| 202 | assert(c.get_allocator() == A()); |
| 203 | assert(!c.empty()); |
| 204 | assert(std::distance(c.begin(), c.end()) == c.size()); |
| 205 | assert(std::distance(c.cbegin(), c.cend()) == c.size()); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 206 | assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 207 | assert(c.max_load_factor() == 1); |
| 208 | |
| 209 | assert(c0.empty()); |
| 210 | } |
| 211 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 212 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 213 | } |