blob: d71838f1dfb488c584c16ef19c8f4ec8d2cffea5 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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_multimap
15
16// unordered_multimap(const unordered_multimap& u);
17
18#include <unordered_map>
19#include <string>
20#include <cassert>
Howard Hinnantf836d532011-12-02 21:23:14 +000021#include <cfloat>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022
23#include "../../../test_compare.h"
24#include "../../../test_hash.h"
Marshall Clow1b921882013-12-03 00:18:10 +000025#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000026#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000027
28int main()
29{
30 {
31 typedef std::unordered_multimap<int, std::string,
32 test_hash<std::hash<int> >,
33 test_compare<std::equal_to<int> >,
34 test_allocator<std::pair<const int, std::string> >
35 > C;
36 typedef std::pair<int, std::string> P;
37 P a[] =
38 {
39 P(1, "one"),
40 P(2, "two"),
41 P(3, "three"),
42 P(4, "four"),
43 P(1, "four"),
44 P(2, "four"),
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 test_allocator<std::pair<const int, std::string> >(10)
51 );
52 C c = c0;
53 assert(c.bucket_count() == 7);
54 assert(c.size() == 6);
55 C::const_iterator i = c.cbegin();
56 assert(i->first == 1);
57 assert(i->second == "one");
58 ++i;
59 assert(i->first == 1);
60 assert(i->second == "four");
61 ++i;
62 assert(i->first == 2);
63 assert(i->second == "two");
64 ++i;
65 assert(i->first == 2);
66 assert(i->second == "four");
67 ++i;
68 assert(i->first == 3);
69 assert(i->second == "three");
70 ++i;
71 assert(i->first == 4);
72 assert(i->second == "four");
73 assert(c.hash_function() == test_hash<std::hash<int> >(8));
74 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
75 assert(c.get_allocator() ==
76 (test_allocator<std::pair<const int, std::string> >(10)));
77 assert(!c.empty());
78 assert(std::distance(c.begin(), c.end()) == c.size());
79 assert(std::distance(c.cbegin(), c.cend()) == c.size());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070080 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000081 assert(c.max_load_factor() == 1);
82 }
83#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
84 {
85 typedef std::unordered_multimap<int, std::string,
86 test_hash<std::hash<int> >,
87 test_compare<std::equal_to<int> >,
88 other_allocator<std::pair<const int, std::string> >
89 > C;
90 typedef std::pair<int, std::string> P;
91 P a[] =
92 {
93 P(1, "one"),
94 P(2, "two"),
95 P(3, "three"),
96 P(4, "four"),
97 P(1, "four"),
98 P(2, "four"),
99 };
100 C c0(a, a + sizeof(a)/sizeof(a[0]),
101 7,
102 test_hash<std::hash<int> >(8),
103 test_compare<std::equal_to<int> >(9),
104 other_allocator<std::pair<const int, std::string> >(10)
105 );
106 C c = c0;
107 assert(c.bucket_count() == 7);
108 assert(c.size() == 6);
109 C::const_iterator i = c.cbegin();
110 assert(i->first == 1);
111 assert(i->second == "one");
112 ++i;
113 assert(i->first == 1);
114 assert(i->second == "four");
115 ++i;
116 assert(i->first == 2);
117 assert(i->second == "two");
118 ++i;
119 assert(i->first == 2);
120 assert(i->second == "four");
121 ++i;
122 assert(i->first == 3);
123 assert(i->second == "three");
124 ++i;
125 assert(i->first == 4);
126 assert(i->second == "four");
127 assert(c.hash_function() == test_hash<std::hash<int> >(8));
128 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
129 assert(c.get_allocator() ==
130 (other_allocator<std::pair<const int, std::string> >(-2)));
131 assert(!c.empty());
132 assert(std::distance(c.begin(), c.end()) == c.size());
133 assert(std::distance(c.cbegin(), c.cend()) == c.size());
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700134 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000135 assert(c.max_load_factor() == 1);
136 }
Howard Hinnant6046ace2010-08-22 00:15:28 +0000137#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000138#if __cplusplus >= 201103L
139 {
140 typedef std::unordered_multimap<int, std::string,
141 test_hash<std::hash<int> >,
142 test_compare<std::equal_to<int> >,
143 min_allocator<std::pair<const int, std::string> >
144 > C;
145 typedef std::pair<int, std::string> P;
146 P a[] =
147 {
148 P(1, "one"),
149 P(2, "two"),
150 P(3, "three"),
151 P(4, "four"),
152 P(1, "four"),
153 P(2, "four"),
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 min_allocator<std::pair<const int, std::string> >()
160 );
161 C c = c0;
162 assert(c.bucket_count() == 7);
163 assert(c.size() == 6);
164 C::const_iterator i = c.cbegin();
165 assert(i->first == 1);
166 assert(i->second == "one");
167 ++i;
168 assert(i->first == 1);
169 assert(i->second == "four");
170 ++i;
171 assert(i->first == 2);
172 assert(i->second == "two");
173 ++i;
174 assert(i->first == 2);
175 assert(i->second == "four");
176 ++i;
177 assert(i->first == 3);
178 assert(i->second == "three");
179 ++i;
180 assert(i->first == 4);
181 assert(i->second == "four");
182 assert(c.hash_function() == test_hash<std::hash<int> >(8));
183 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
184 assert(c.get_allocator() ==
185 (min_allocator<std::pair<const int, std::string> >()));
186 assert(!c.empty());
187 assert(std::distance(c.begin(), c.end()) == c.size());
188 assert(std::distance(c.cbegin(), c.cend()) == c.size());
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700189 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000190 assert(c.max_load_factor() == 1);
191 }
192#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000193}