1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <unordered_map>
10 // UNSUPPORTED: c++03, c++11, c++14
11
12 // template<class InputIterator,
13 // class Hash = hash<iter-key-type<InputIterator>>,
14 // class Pred = equal_to<iter-key-type<InputIterator>>,
15 // class Allocator = allocator<iter-to-alloc-type<InputIterator>>>
16 // unordered_multimap(InputIterator, InputIterator, typename see below::size_type = see below,
17 // Hash = Hash(), Pred = Pred(), Allocator = Allocator())
18 // -> unordered_multimap<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Hash, Pred,
19 // Allocator>;
20 //
21 // template<class Key, class T, class Hash = hash<Key>,
22 // class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
23 // unordered_multimap(initializer_list<pair<Key, T>>,
24 // typename see below::size_type = see below, Hash = Hash(),
25 // Pred = Pred(), Allocator = Allocator())
26 // -> unordered_multimap<Key, T, Hash, Pred, Allocator>;
27 //
28 // template<class InputIterator, class Allocator>
29 // unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Allocator)
30 // -> unordered_multimap<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>,
31 // hash<iter-key-type<InputIterator>>,
32 // equal_to<iter-key-type<InputIterator>>, Allocator>;
33 //
34 // template<class InputIterator, class Allocator>
35 // unordered_multimap(InputIterator, InputIterator, Allocator)
36 // -> unordered_multimap<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>,
37 // hash<iter-key-type<InputIterator>>,
38 // equal_to<iter-key-type<InputIterator>>, Allocator>;
39 //
40 // template<class InputIterator, class Hash, class Allocator>
41 // unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
42 // -> unordered_multimap<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Hash,
43 // equal_to<iter-key-type<InputIterator>>, Allocator>;
44 //
45 // template<class Key, class T, class Allocator>
46 // unordered_multimap(initializer_list<pair<Key, T>>, typename see below::size_type, Allocator)
47 // -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>;
48 //
49 // template<class Key, class T, class Allocator>
50 // unordered_multimap(initializer_list<pair<Key, T>>, Allocator)
51 // -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>;
52 //
53 // template<class Key, class T, class Hash, class Allocator>
54 // unordered_multimap(initializer_list<pair<Key, T>>, typename see below::size_type, Hash,
55 // Allocator)
56 // -> unordered_multimap<Key, T, Hash, equal_to<Key>, Allocator>;
57
58 #include <algorithm> // is_permutation
59 #include <cassert>
60 #include <climits> // INT_MAX
61 #include <functional>
62 #include <iterator>
63 #include <type_traits>
64 #include <unordered_map>
65
66 #include "test_allocator.h"
67
68 using P = std::pair<int, long>;
69 using PC = std::pair<const int, long>;
70
main(int,char **)71 int main(int, char**)
72 {
73 const PC expected_m[] = { {1,1}, {1,1}, {2,2}, {3,1}, {INT_MAX,1} };
74
75 {
76 const PC arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} };
77 std::unordered_multimap m(std::begin(arr), std::end(arr));
78 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long>);
79 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
80 }
81
82 {
83 const PC arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} };
84 std::unordered_multimap m(std::begin(arr), std::end(arr), 42);
85 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long>);
86 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
87 }
88
89 {
90 const PC arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} };
91 std::unordered_multimap m(std::begin(arr), std::end(arr), 42, std::hash<short>());
92 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<int>>);
93 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
94 }
95
96 {
97 const PC arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} };
98 std::unordered_multimap m(std::begin(arr), std::end(arr), 42, std::hash<short>(), std::equal_to<>());
99 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<>>);
100 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
101 }
102
103 {
104 const PC arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} };
105 std::unordered_multimap m(std::begin(arr), std::end(arr), 42, std::hash<short>(), std::equal_to<>(), test_allocator<PC>(0, 41));
106 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<>, test_allocator<PC>>);
107 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
108 assert(m.get_allocator().get_id() == 41);
109 }
110
111 {
112 std::unordered_multimap m { PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} };
113 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long>);
114 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
115 }
116
117 {
118 std::unordered_multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, 42);
119 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long>);
120 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
121 }
122
123 {
124 std::unordered_multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, 42, std::hash<short>());
125 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>>);
126 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
127 }
128
129 {
130 std::unordered_multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, 42, std::hash<short>(), std::equal_to<>());
131 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<>>);
132 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
133 }
134
135 {
136 std::unordered_multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, 42, std::hash<short>(), std::equal_to<>(), test_allocator<PC>(0, 44));
137 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<>, test_allocator<PC>>);
138 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
139 assert(m.get_allocator().get_id() == 44);
140 }
141
142 {
143 const PC arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} };
144 std::unordered_multimap m(std::begin(arr), std::end(arr), 42, test_allocator<PC>(0, 45));
145 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<int>, std::equal_to<int>, test_allocator<PC>>);
146 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
147 assert(m.get_allocator().get_id() == 45);
148 }
149
150 {
151 const PC arr[] = { {1,1}, {2,2}, {1,1}, {INT_MAX,1}, {3,1} };
152 std::unordered_multimap m(std::begin(arr), std::end(arr), 42, std::hash<short>(), test_allocator<PC>(0, 46));
153 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<int>, test_allocator<PC>>);
154 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
155 assert(m.get_allocator().get_id() == 46);
156 }
157
158 {
159 std::unordered_multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, 42, test_allocator<PC>(0, 47));
160 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<int>, std::equal_to<int>, test_allocator<PC>>);
161 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
162 assert(m.get_allocator().get_id() == 47);
163 }
164
165 {
166 std::unordered_multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, 42, std::hash<short>(), test_allocator<PC>(0, 48));
167 ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<int>, test_allocator<PC>>);
168 assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
169 assert(m.get_allocator().get_id() == 48);
170 }
171
172 return 0;
173 }
174