assign_init.pass.cpp (3141B)
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 // UNSUPPORTED: c++98, c++03 11 12 // <unordered_set> 13 14 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, 15 // class Alloc = allocator<Value>> 16 // class unordered_set 17 18 // unordered_set& operator=(initializer_list<value_type> il); 19 20 #include <unordered_set> 21 #include <cassert> 22 #include <cfloat> 23 #include <cmath> 24 #include <cstddef> 25 26 #include "../../../test_compare.h" 27 #include "../../../test_hash.h" 28 #include "test_allocator.h" 29 #include "min_allocator.h" 30 31 int main() 32 { 33 { 34 typedef test_allocator<int> A; 35 typedef std::unordered_set<int, 36 test_hash<std::hash<int> >, 37 test_compare<std::equal_to<int> >, 38 A 39 > C; 40 typedef int P; 41 C c = { 42 P(4), 43 P(1), 44 P(2) 45 }; 46 c = { 47 P(1), 48 P(2), 49 P(3), 50 P(4), 51 P(1), 52 P(2) 53 }; 54 assert(c.bucket_count() >= 5); 55 assert(c.size() == 4); 56 assert(c.count(1) == 1); 57 assert(c.count(2) == 1); 58 assert(c.count(3) == 1); 59 assert(c.count(4) == 1); 60 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); 61 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); 62 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 63 assert(c.max_load_factor() == 1); 64 } 65 { 66 typedef min_allocator<int> A; 67 typedef std::unordered_set<int, 68 test_hash<std::hash<int> >, 69 test_compare<std::equal_to<int> >, 70 A 71 > C; 72 typedef int P; 73 C c = { 74 P(4), 75 P(1), 76 P(2) 77 }; 78 c = { 79 P(1), 80 P(2), 81 P(3), 82 P(4), 83 P(1), 84 P(2) 85 }; 86 assert(c.bucket_count() >= 5); 87 assert(c.size() == 4); 88 assert(c.count(1) == 1); 89 assert(c.count(2) == 1); 90 assert(c.count(3) == 1); 91 assert(c.count(4) == 1); 92 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size()); 93 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size()); 94 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 95 assert(c.max_load_factor() == 1); 96 } 97 }