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 // void insert(initializer_list<value_type> il);
17 
18 #include <unordered_map>
19 #include <string>
20 #include <cassert>
21 
22 #include "test_iterators.h"
23 #include "min_allocator.h"
24 
main()25 int main()
26 {
27 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
28     {
29         typedef std::unordered_multimap<int, std::string> C;
30         typedef std::pair<int, std::string> P;
31         C c;
32         c.insert(
33                     {
34                         P(1, "one"),
35                         P(2, "two"),
36                         P(3, "three"),
37                         P(4, "four"),
38                         P(1, "four"),
39                         P(2, "four"),
40                     }
41                 );
42         assert(c.size() == 6);
43         typedef std::pair<C::iterator, C::iterator> Eq;
44         Eq eq = c.equal_range(1);
45         assert(std::distance(eq.first, eq.second) == 2);
46         C::iterator k = eq.first;
47         assert(k->first == 1);
48         assert(k->second == "one");
49         ++k;
50         assert(k->first == 1);
51         assert(k->second == "four");
52         eq = c.equal_range(2);
53         assert(std::distance(eq.first, eq.second) == 2);
54         k = eq.first;
55         assert(k->first == 2);
56         assert(k->second == "two");
57         ++k;
58         assert(k->first == 2);
59         assert(k->second == "four");
60         eq = c.equal_range(3);
61         assert(std::distance(eq.first, eq.second) == 1);
62         k = eq.first;
63         assert(k->first == 3);
64         assert(k->second == "three");
65         eq = c.equal_range(4);
66         assert(std::distance(eq.first, eq.second) == 1);
67         k = eq.first;
68         assert(k->first == 4);
69         assert(k->second == "four");
70         assert(std::distance(c.begin(), c.end()) == c.size());
71         assert(std::distance(c.cbegin(), c.cend()) == c.size());
72     }
73 #if __cplusplus >= 201103L
74     {
75         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
76                             min_allocator<std::pair<const int, std::string>>> C;
77         typedef std::pair<int, std::string> P;
78         C c;
79         c.insert(
80                     {
81                         P(1, "one"),
82                         P(2, "two"),
83                         P(3, "three"),
84                         P(4, "four"),
85                         P(1, "four"),
86                         P(2, "four"),
87                     }
88                 );
89         assert(c.size() == 6);
90         typedef std::pair<C::iterator, C::iterator> Eq;
91         Eq eq = c.equal_range(1);
92         assert(std::distance(eq.first, eq.second) == 2);
93         C::iterator k = eq.first;
94         assert(k->first == 1);
95         assert(k->second == "one");
96         ++k;
97         assert(k->first == 1);
98         assert(k->second == "four");
99         eq = c.equal_range(2);
100         assert(std::distance(eq.first, eq.second) == 2);
101         k = eq.first;
102         assert(k->first == 2);
103         assert(k->second == "two");
104         ++k;
105         assert(k->first == 2);
106         assert(k->second == "four");
107         eq = c.equal_range(3);
108         assert(std::distance(eq.first, eq.second) == 1);
109         k = eq.first;
110         assert(k->first == 3);
111         assert(k->second == "three");
112         eq = c.equal_range(4);
113         assert(std::distance(eq.first, eq.second) == 1);
114         k = eq.first;
115         assert(k->first == 4);
116         assert(k->second == "four");
117         assert(std::distance(c.begin(), c.end()) == c.size());
118         assert(std::distance(c.cbegin(), c.cend()) == c.size());
119     }
120 #endif
121 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
122 }
123