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=(initializer_list<value_type> il); 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 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 30 { 31 typedef test_allocator<int> A; 32 typedef std::unordered_set<int, 33 test_hash<std::hash<int> >, 34 test_compare<std::equal_to<int> >, 35 A 36 > C; 37 typedef int P; 38 C c = { 39 P(4), 40 P(1), 41 P(2) 42 }; 43 c = { 44 P(1), 45 P(2), 46 P(3), 47 P(4), 48 P(1), 49 P(2) 50 }; 51 assert(c.bucket_count() >= 5); 52 assert(c.size() == 4); 53 assert(c.count(1) == 1); 54 assert(c.count(2) == 1); 55 assert(c.count(3) == 1); 56 assert(c.count(4) == 1); 57 assert(std::distance(c.begin(), c.end()) == c.size()); 58 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 59 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 60 assert(c.max_load_factor() == 1); 61 } 62 #if __cplusplus >= 201103L 63 { 64 typedef min_allocator<int> A; 65 typedef std::unordered_set<int, 66 test_hash<std::hash<int> >, 67 test_compare<std::equal_to<int> >, 68 A 69 > C; 70 typedef int P; 71 C c = { 72 P(4), 73 P(1), 74 P(2) 75 }; 76 c = { 77 P(1), 78 P(2), 79 P(3), 80 P(4), 81 P(1), 82 P(2) 83 }; 84 assert(c.bucket_count() >= 5); 85 assert(c.size() == 4); 86 assert(c.count(1) == 1); 87 assert(c.count(2) == 1); 88 assert(c.count(3) == 1); 89 assert(c.count(4) == 1); 90 assert(std::distance(c.begin(), c.end()) == c.size()); 91 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 92 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 93 assert(c.max_load_factor() == 1); 94 } 95 #endif 96 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 97 } 98