default.pass.cpp (4493B)
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_map> 11 12 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 13 // class Alloc = allocator<pair<const Key, T>>> 14 // class unordered_map 15 16 // unordered_map(); 17 18 #include <unordered_map> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "../../../NotConstructible.h" 23 #include "../../../test_compare.h" 24 #include "../../../test_hash.h" 25 #include "test_allocator.h" 26 #include "min_allocator.h" 27 28 int main() 29 { 30 { 31 typedef std::unordered_map<NotConstructible, NotConstructible, 32 test_hash<std::hash<NotConstructible> >, 33 test_compare<std::equal_to<NotConstructible> >, 34 test_allocator<std::pair<const NotConstructible, 35 NotConstructible> > 36 > C; 37 C c; 38 LIBCPP_ASSERT(c.bucket_count() == 0); 39 assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); 40 assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); 41 assert(c.get_allocator() == 42 (test_allocator<std::pair<const NotConstructible, NotConstructible> >())); 43 assert(c.size() == 0); 44 assert(c.empty()); 45 assert(std::distance(c.begin(), c.end()) == 0); 46 assert(c.load_factor() == 0); 47 assert(c.max_load_factor() == 1); 48 } 49 #if TEST_STD_VER >= 11 50 { 51 typedef std::unordered_map<NotConstructible, NotConstructible, 52 test_hash<std::hash<NotConstructible> >, 53 test_compare<std::equal_to<NotConstructible> >, 54 min_allocator<std::pair<const NotConstructible, 55 NotConstructible> > 56 > C; 57 C c; 58 LIBCPP_ASSERT(c.bucket_count() == 0); 59 assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); 60 assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); 61 assert(c.get_allocator() == 62 (min_allocator<std::pair<const NotConstructible, NotConstructible> >())); 63 assert(c.size() == 0); 64 assert(c.empty()); 65 assert(std::distance(c.begin(), c.end()) == 0); 66 assert(c.load_factor() == 0); 67 assert(c.max_load_factor() == 1); 68 } 69 { 70 typedef explicit_allocator<std::pair<const NotConstructible, NotConstructible>> A; 71 typedef std::unordered_map<NotConstructible, NotConstructible, 72 test_hash<std::hash<NotConstructible> >, 73 test_compare<std::equal_to<NotConstructible> >, 74 A 75 > C; 76 { 77 C c; 78 LIBCPP_ASSERT(c.bucket_count() == 0); 79 assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); 80 assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); 81 assert(c.get_allocator() == A()); 82 assert(c.size() == 0); 83 assert(c.empty()); 84 assert(std::distance(c.begin(), c.end()) == 0); 85 assert(c.load_factor() == 0); 86 assert(c.max_load_factor() == 1); 87 } 88 { 89 A a; 90 C c(a); 91 LIBCPP_ASSERT(c.bucket_count() == 0); 92 assert(c.hash_function() == test_hash<std::hash<NotConstructible> >()); 93 assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >()); 94 assert(c.get_allocator() == a); 95 assert(c.size() == 0); 96 assert(c.empty()); 97 assert(std::distance(c.begin(), c.end()) == 0); 98 assert(c.load_factor() == 0); 99 assert(c.max_load_factor() == 1); 100 } 101 } 102 { 103 std::unordered_map<int, int> c = {}; 104 LIBCPP_ASSERT(c.bucket_count() == 0); 105 assert(c.size() == 0); 106 assert(c.empty()); 107 assert(std::distance(c.begin(), c.end()) == 0); 108 assert(c.load_factor() == 0); 109 assert(c.max_load_factor() == 1); 110 } 111 #endif 112 }