1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
16 // unordered_map(unordered_map&& u);
18 // UNSUPPORTED: c++98, c++03
20 #include <unordered_map>
27 #include "test_macros.h"
28 #include "../../../test_compare.h"
29 #include "../../../test_hash.h"
30 #include "test_allocator.h"
31 #include "min_allocator.h"
36 typedef std::unordered_map<int, std::string,
37 test_hash<std::hash<int> >,
38 test_compare<std::equal_to<int> >,
39 test_allocator<std::pair<const int, std::string> >
42 test_hash<std::hash<int> >(8),
43 test_compare<std::equal_to<int> >(9),
44 test_allocator<std::pair<const int, std::string> >(10)
47 LIBCPP_ASSERT(c.bucket_count() == 7);
48 assert(c.size() == 0);
49 assert(c.hash_function() == test_hash<std::hash<int> >(8));
50 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
51 assert(c.get_allocator() ==
52 (test_allocator<std::pair<const int, std::string> >(10)));
54 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
55 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
56 assert(c.load_factor() == 0);
57 assert(c.max_load_factor() == 1);
62 typedef std::unordered_map<int, std::string,
63 test_hash<std::hash<int> >,
64 test_compare<std::equal_to<int> >,
65 test_allocator<std::pair<const int, std::string> >
67 typedef std::pair<int, std::string> P;
77 C c0(a, a + sizeof(a)/sizeof(a[0]),
79 test_hash<std::hash<int> >(8),
80 test_compare<std::equal_to<int> >(9),
81 test_allocator<std::pair<const int, std::string> >(10)
84 LIBCPP_ASSERT(c.bucket_count() == 7);
85 assert(c.size() == 4);
86 assert(c.at(1) == "one");
87 assert(c.at(2) == "two");
88 assert(c.at(3) == "three");
89 assert(c.at(4) == "four");
90 assert(c.hash_function() == test_hash<std::hash<int> >(8));
91 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
92 assert(c.get_allocator() ==
93 (test_allocator<std::pair<const int, std::string> >(10)));
95 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
96 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
97 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
98 assert(c.max_load_factor() == 1);
103 typedef std::unordered_map<int, std::string,
104 test_hash<std::hash<int> >,
105 test_compare<std::equal_to<int> >,
106 min_allocator<std::pair<const int, std::string> >
109 test_hash<std::hash<int> >(8),
110 test_compare<std::equal_to<int> >(9),
111 min_allocator<std::pair<const int, std::string> >()
114 LIBCPP_ASSERT(c.bucket_count() == 7);
115 assert(c.size() == 0);
116 assert(c.hash_function() == test_hash<std::hash<int> >(8));
117 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
118 assert(c.get_allocator() ==
119 (min_allocator<std::pair<const int, std::string> >()));
121 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
122 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
123 assert(c.load_factor() == 0);
124 assert(c.max_load_factor() == 1);
129 typedef std::unordered_map<int, std::string,
130 test_hash<std::hash<int> >,
131 test_compare<std::equal_to<int> >,
132 min_allocator<std::pair<const int, std::string> >
134 typedef std::pair<int, std::string> P;
144 C c0(a, a + sizeof(a)/sizeof(a[0]),
146 test_hash<std::hash<int> >(8),
147 test_compare<std::equal_to<int> >(9),
148 min_allocator<std::pair<const int, std::string> >()
151 LIBCPP_ASSERT(c.bucket_count() == 7);
152 assert(c.size() == 4);
153 assert(c.at(1) == "one");
154 assert(c.at(2) == "two");
155 assert(c.at(3) == "three");
156 assert(c.at(4) == "four");
157 assert(c.hash_function() == test_hash<std::hash<int> >(8));
158 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
159 assert(c.get_allocator() ==
160 (min_allocator<std::pair<const int, std::string> >()));
162 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
163 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
164 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
165 assert(c.max_load_factor() == 1);
169 #if _LIBCPP_DEBUG >= 1
171 std::unordered_map<int, int> s1 = {{1, 1}, {2, 2}, {3, 3}};
172 std::unordered_map<int, int>::iterator i = s1.begin();
173 std::pair<const int, int> k = *i;
174 std::unordered_map<int, int> s2 = std::move(s1);
177 assert(s2.size() == 2);