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_multimap
15 
16 // unordered_multimap& operator=(initializer_list<value_type> il);
17 
18 #include <unordered_map>
19 #include <string>
20 #include <cassert>
21 #include <cfloat>
22 
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 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
31     {
32         typedef test_allocator<std::pair<const int, std::string> > A;
33         typedef std::unordered_multimap<int, std::string,
34                                    test_hash<std::hash<int> >,
35                                    test_compare<std::equal_to<int> >,
36                                    A
37                                    > C;
38         typedef std::pair<int, std::string> P;
39         C c =   {
40                     P(4, "four"),
41                     P(1, "four"),
42                     P(2, "four"),
43                 };
44         c =     {
45                     P(1, "one"),
46                     P(2, "two"),
47                     P(3, "three"),
48                     P(4, "four"),
49                     P(1, "four"),
50                     P(2, "four"),
51                 };
52         assert(c.bucket_count() >= 7);
53         assert(c.size() == 6);
54         typedef std::pair<C::const_iterator, C::const_iterator> Eq;
55         Eq eq = c.equal_range(1);
56         assert(std::distance(eq.first, eq.second) == 2);
57         C::const_iterator i = eq.first;
58         assert(i->first == 1);
59         assert(i->second == "one");
60         ++i;
61         assert(i->first == 1);
62         assert(i->second == "four");
63         eq = c.equal_range(2);
64         assert(std::distance(eq.first, eq.second) == 2);
65         i = eq.first;
66         assert(i->first == 2);
67         assert(i->second == "two");
68         ++i;
69         assert(i->first == 2);
70         assert(i->second == "four");
71 
72         eq = c.equal_range(3);
73         assert(std::distance(eq.first, eq.second) == 1);
74         i = eq.first;
75         assert(i->first == 3);
76         assert(i->second == "three");
77         eq = c.equal_range(4);
78         assert(std::distance(eq.first, eq.second) == 1);
79         i = eq.first;
80         assert(i->first == 4);
81         assert(i->second == "four");
82         assert(std::distance(c.begin(), c.end()) == c.size());
83         assert(std::distance(c.cbegin(), c.cend()) == c.size());
84         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
85         assert(c.max_load_factor() == 1);
86     }
87 #if __cplusplus >= 201103L
88     {
89         typedef min_allocator<std::pair<const int, std::string> > A;
90         typedef std::unordered_multimap<int, std::string,
91                                    test_hash<std::hash<int> >,
92                                    test_compare<std::equal_to<int> >,
93                                    A
94                                    > C;
95         typedef std::pair<int, std::string> P;
96         C c =   {
97                     P(4, "four"),
98                     P(1, "four"),
99                     P(2, "four"),
100                 };
101         c =     {
102                     P(1, "one"),
103                     P(2, "two"),
104                     P(3, "three"),
105                     P(4, "four"),
106                     P(1, "four"),
107                     P(2, "four"),
108                 };
109         assert(c.bucket_count() >= 7);
110         assert(c.size() == 6);
111         typedef std::pair<C::const_iterator, C::const_iterator> Eq;
112         Eq eq = c.equal_range(1);
113         assert(std::distance(eq.first, eq.second) == 2);
114         C::const_iterator i = eq.first;
115         assert(i->first == 1);
116         assert(i->second == "one");
117         ++i;
118         assert(i->first == 1);
119         assert(i->second == "four");
120         eq = c.equal_range(2);
121         assert(std::distance(eq.first, eq.second) == 2);
122         i = eq.first;
123         assert(i->first == 2);
124         assert(i->second == "two");
125         ++i;
126         assert(i->first == 2);
127         assert(i->second == "four");
128 
129         eq = c.equal_range(3);
130         assert(std::distance(eq.first, eq.second) == 1);
131         i = eq.first;
132         assert(i->first == 3);
133         assert(i->second == "three");
134         eq = c.equal_range(4);
135         assert(std::distance(eq.first, eq.second) == 1);
136         i = eq.first;
137         assert(i->first == 4);
138         assert(i->second == "four");
139         assert(std::distance(c.begin(), c.end()) == c.size());
140         assert(std::distance(c.cbegin(), c.cend()) == c.size());
141         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
142         assert(c.max_load_factor() == 1);
143     }
144 #endif
145 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
146 }
147