| 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 | |
| 71 | int main(int, char**) { |
| 72 | const PC expected_m[] = {{1, 1}, {1, 1}, {2, 2}, {3, 1}, {INT_MAX, 1}}; |
| 73 | |
| 74 | { |
| 75 | const PC arr[] = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 1}, {3, 1}}; |
| 76 | std::unordered_multimap m(std::begin(arr: arr), std::end(arr: arr)); |
| 77 | ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long>); |
| 78 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 79 | } |
| 80 | |
| 81 | { |
| 82 | const PC arr[] = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 1}, {3, 1}}; |
| 83 | std::unordered_multimap m(std::begin(arr: arr), std::end(arr: arr), 42); |
| 84 | ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long>); |
| 85 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 86 | } |
| 87 | |
| 88 | { |
| 89 | const PC arr[] = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 1}, {3, 1}}; |
| 90 | std::unordered_multimap m(std::begin(arr: arr), std::end(arr: arr), 42, std::hash<short>()); |
| 91 | ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<int>>); |
| 92 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 93 | } |
| 94 | |
| 95 | { |
| 96 | const PC arr[] = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 1}, {3, 1}}; |
| 97 | std::unordered_multimap m(std::begin(arr: arr), std::end(arr: arr), 42, std::hash<short>(), std::equal_to<>()); |
| 98 | ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<>>); |
| 99 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 100 | } |
| 101 | |
| 102 | { |
| 103 | const PC arr[] = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 1}, {3, 1}}; |
| 104 | std::unordered_multimap m( |
| 105 | std::begin(arr: arr), std::end(arr: arr), 42, std::hash<short>(), std::equal_to<>(), test_allocator<PC>(0, 41)); |
| 106 | ASSERT_SAME_TYPE( |
| 107 | decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<>, test_allocator<PC>>); |
| 108 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 109 | assert(m.get_allocator().get_id() == 41); |
| 110 | } |
| 111 | |
| 112 | { |
| 113 | std::unordered_multimap m{PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}; |
| 114 | ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long>); |
| 115 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 116 | } |
| 117 | |
| 118 | { |
| 119 | std::unordered_multimap m({PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}, 42); |
| 120 | ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long>); |
| 121 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 122 | } |
| 123 | |
| 124 | { |
| 125 | std::unordered_multimap m({PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}, 42, std::hash<short>()); |
| 126 | ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>>); |
| 127 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 128 | } |
| 129 | |
| 130 | { |
| 131 | std::unordered_multimap m( |
| 132 | {PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}, 42, std::hash<short>(), std::equal_to<>()); |
| 133 | ASSERT_SAME_TYPE(decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<>>); |
| 134 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 135 | } |
| 136 | |
| 137 | { |
| 138 | std::unordered_multimap m( |
| 139 | {PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}, |
| 140 | 42, |
| 141 | std::hash<short>(), |
| 142 | std::equal_to<>(), |
| 143 | test_allocator<PC>(0, 44)); |
| 144 | ASSERT_SAME_TYPE( |
| 145 | decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<>, 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() == 44); |
| 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: arr), std::end(arr: arr), 42, test_allocator<PC>(0, 45)); |
| 153 | ASSERT_SAME_TYPE( |
| 154 | decltype(m), std::unordered_multimap<int, long, std::hash<int>, std::equal_to<int>, test_allocator<PC>>); |
| 155 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 156 | assert(m.get_allocator().get_id() == 45); |
| 157 | } |
| 158 | |
| 159 | { |
| 160 | const PC arr[] = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 1}, {3, 1}}; |
| 161 | std::unordered_multimap m(std::begin(arr: arr), std::end(arr: arr), 42, std::hash<short>(), test_allocator<PC>(0, 46)); |
| 162 | ASSERT_SAME_TYPE( |
| 163 | decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<int>, test_allocator<PC>>); |
| 164 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 165 | assert(m.get_allocator().get_id() == 46); |
| 166 | } |
| 167 | |
| 168 | { |
| 169 | std::unordered_multimap m( |
| 170 | {PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}, 42, test_allocator<PC>(0, 47)); |
| 171 | ASSERT_SAME_TYPE( |
| 172 | decltype(m), std::unordered_multimap<int, long, std::hash<int>, std::equal_to<int>, test_allocator<PC>>); |
| 173 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 174 | assert(m.get_allocator().get_id() == 47); |
| 175 | } |
| 176 | |
| 177 | { |
| 178 | std::unordered_multimap m( |
| 179 | {PC{1, 1L}, PC{2, 2L}, PC{1, 1L}, PC{INT_MAX, 1L}, PC{3, 1L}}, |
| 180 | 42, |
| 181 | std::hash<short>(), |
| 182 | test_allocator<PC>(0, 48)); |
| 183 | ASSERT_SAME_TYPE( |
| 184 | decltype(m), std::unordered_multimap<int, long, std::hash<short>, std::equal_to<int>, test_allocator<PC>>); |
| 185 | assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m))); |
| 186 | assert(m.get_allocator().get_id() == 48); |
| 187 | } |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |