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