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++98, c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-no-deduction-guides
12 
13 // template<class InputIterator,
14 //          class Hash = hash<iter-key-type<InputIterator>>,
15 //          class Pred = equal_to<iter-key-type<InputIterator>>,
16 //          class Allocator = allocator<iter-to-alloc-type<InputIterator>>>
17 // unordered_multimap(InputIterator, InputIterator, typename see below::size_type = see below,
18 //                    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
19 //   -> unordered_multimap<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Hash, Pred,
20 //                         Allocator>;
21 //
22 // template<class Key, class T, class Hash = hash<Key>,
23 //          class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
24 // unordered_multimap(initializer_list<pair<Key, T>>,
25 //                    typename see below::size_type = see below, Hash = Hash(),
26 //                    Pred = Pred(), Allocator = Allocator())
27 //   -> unordered_multimap<Key, T, Hash, Pred, Allocator>;
28 //
29 // template<class InputIterator, class Allocator>
30 // unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Allocator)
31 //   -> unordered_multimap<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>,
32 //                         hash<iter-key-type<InputIterator>>,
33 //                         equal_to<iter-key-type<InputIterator>>, Allocator>;
34 //
35 // template<class InputIterator, class Allocator>
36 // unordered_multimap(InputIterator, InputIterator, Allocator)
37 //   -> unordered_multimap<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>,
38 //                         hash<iter-key-type<InputIterator>>,
39 //                         equal_to<iter-key-type<InputIterator>>, Allocator>;
40 //
41 // template<class InputIterator, class Hash, class Allocator>
42 // unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
43 //   -> unordered_multimap<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Hash,
44 //                         equal_to<iter-key-type<InputIterator>>, Allocator>;
45 //
46 // template<class Key, class T, class Allocator>
47 // unordered_multimap(initializer_list<pair<Key, T>>, typename see below::size_type, Allocator)
48 //   -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>;
49 //
50 // template<class Key, class T, class Allocator>
51 // unordered_multimap(initializer_list<pair<Key, T>>, Allocator)
52 //   -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>;
53 //
54 // template<class Key, class T, class Hash, class Allocator>
55 // unordered_multimap(initializer_list<pair<Key, T>>, typename see below::size_type, Hash,
56 //                    Allocator)
57 //   -> unordered_multimap<Key, T, Hash, equal_to<Key>, Allocator>;
58 
59 #include <algorithm> // is_permutation
60 #include <cassert>
61 #include <climits> // INT_MAX
62 #include <functional>
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