assign_copy.pass.cpp revision 06086258d3d8c48a916ec51c33e1ad8f46821b81
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_set 15 16// unordered_set& operator=(const unordered_set& 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 27int main() 28{ 29 { 30 typedef test_allocator<int> A; 31 typedef std::unordered_set<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() == 4); 61 assert(c.count(1) == 1); 62 assert(c.count(2) == 1); 63 assert(c.count(3) == 1); 64 assert(c.count(4) == 1); 65 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 66 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 67 assert(c.get_allocator() == A(4)); 68 assert(!c.empty()); 69 assert(std::distance(c.begin(), c.end()) == c.size()); 70 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 71 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 72 assert(c.max_load_factor() == 1); 73 } 74 { 75 typedef std::unordered_set<int> C; 76 typedef int P; 77 P a[] = 78 { 79 P(1), 80 P(2), 81 P(3), 82 P(4), 83 P(1), 84 P(2) 85 }; 86 C c(a, a + sizeof(a)/sizeof(a[0])); 87 C *p = &c; 88 c = *p; 89 assert(c.size() == 4); 90 assert(std::is_permutation(c.begin(), c.end(), a)); 91 } 92 { 93 typedef other_allocator<int> A; 94 typedef std::unordered_set<int, 95 test_hash<std::hash<int> >, 96 test_compare<std::equal_to<int> >, 97 A 98 > C; 99 typedef int P; 100 P a[] = 101 { 102 P(1), 103 P(2), 104 P(3), 105 P(4), 106 P(1), 107 P(2) 108 }; 109 C c0(a, a + sizeof(a)/sizeof(a[0]), 110 7, 111 test_hash<std::hash<int> >(8), 112 test_compare<std::equal_to<int> >(9), 113 A(10) 114 ); 115 C c(a, a + 2, 116 7, 117 test_hash<std::hash<int> >(2), 118 test_compare<std::equal_to<int> >(3), 119 A(4) 120 ); 121 c = c0; 122 assert(c.bucket_count() >= 5); 123 assert(c.size() == 4); 124 assert(c.count(1) == 1); 125 assert(c.count(2) == 1); 126 assert(c.count(3) == 1); 127 assert(c.count(4) == 1); 128 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 129 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 130 assert(c.get_allocator() == A(10)); 131 assert(!c.empty()); 132 assert(std::distance(c.begin(), c.end()) == c.size()); 133 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 134 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 135 assert(c.max_load_factor() == 1); 136 } 137#if __cplusplus >= 201103L 138 { 139 typedef min_allocator<int> A; 140 typedef std::unordered_set<int, 141 test_hash<std::hash<int> >, 142 test_compare<std::equal_to<int> >, 143 A 144 > C; 145 typedef int P; 146 P a[] = 147 { 148 P(1), 149 P(2), 150 P(3), 151 P(4), 152 P(1), 153 P(2) 154 }; 155 C c0(a, a + sizeof(a)/sizeof(a[0]), 156 7, 157 test_hash<std::hash<int> >(8), 158 test_compare<std::equal_to<int> >(9), 159 A() 160 ); 161 C c(a, a + 2, 162 7, 163 test_hash<std::hash<int> >(2), 164 test_compare<std::equal_to<int> >(3), 165 A() 166 ); 167 c = c0; 168 assert(c.bucket_count() == 7); 169 assert(c.size() == 4); 170 assert(c.count(1) == 1); 171 assert(c.count(2) == 1); 172 assert(c.count(3) == 1); 173 assert(c.count(4) == 1); 174 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 175 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 176 assert(c.get_allocator() == A()); 177 assert(!c.empty()); 178 assert(std::distance(c.begin(), c.end()) == c.size()); 179 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 180 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 181 assert(c.max_load_factor() == 1); 182 } 183#endif 184} 185