Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- unordered_map -----------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_UNORDERED_MAP |
| 12 | #define _LIBCPP_UNORDERED_MAP |
| 13 | |
| 14 | /* |
| 15 | |
| 16 | unordered_map synopsis |
| 17 | |
| 18 | #include <initializer_list> |
| 19 | |
| 20 | namespace std |
| 21 | { |
| 22 | |
| 23 | template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 24 | class Alloc = allocator<pair<const Key, T>>> |
| 25 | class unordered_map |
| 26 | { |
| 27 | public: |
| 28 | // types |
| 29 | typedef Key key_type; |
| 30 | typedef T mapped_type; |
| 31 | typedef Hash hasher; |
| 32 | typedef Pred key_equal; |
| 33 | typedef Alloc allocator_type; |
| 34 | typedef pair<const key_type, mapped_type> value_type; |
| 35 | typedef value_type& reference; |
| 36 | typedef const value_type& const_reference; |
| 37 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 38 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 39 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 40 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 41 | |
| 42 | typedef /unspecified/ iterator; |
| 43 | typedef /unspecified/ const_iterator; |
| 44 | typedef /unspecified/ local_iterator; |
| 45 | typedef /unspecified/ const_local_iterator; |
| 46 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 47 | unordered_map() |
| 48 | noexcept( |
| 49 | is_nothrow_default_constructible<hasher>::value && |
| 50 | is_nothrow_default_constructible<key_equal>::value && |
| 51 | is_nothrow_default_constructible<allocator_type>::value); |
| 52 | explicit unordered_map(size_type n, const hasher& hf = hasher(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | const key_equal& eql = key_equal(), |
| 54 | const allocator_type& a = allocator_type()); |
| 55 | template <class InputIterator> |
| 56 | unordered_map(InputIterator f, InputIterator l, |
| 57 | size_type n = 0, const hasher& hf = hasher(), |
| 58 | const key_equal& eql = key_equal(), |
| 59 | const allocator_type& a = allocator_type()); |
| 60 | explicit unordered_map(const allocator_type&); |
| 61 | unordered_map(const unordered_map&); |
| 62 | unordered_map(const unordered_map&, const Allocator&); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 63 | unordered_map(unordered_map&&) |
| 64 | noexcept( |
| 65 | is_nothrow_move_constructible<hasher>::value && |
| 66 | is_nothrow_move_constructible<key_equal>::value && |
| 67 | is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | unordered_map(unordered_map&&, const Allocator&); |
| 69 | unordered_map(initializer_list<value_type>, size_type n = 0, |
| 70 | const hasher& hf = hasher(), const key_equal& eql = key_equal(), |
| 71 | const allocator_type& a = allocator_type()); |
Marshall Clow | 6dff618 | 2013-09-12 03:00:31 +0000 | [diff] [blame] | 72 | unordered_map(size_type n, const allocator_type& a) |
| 73 | : unordered_map(n, hasher(), key_equal(), a) {} // C++14 |
| 74 | unordered_map(size_type n, const hasher& hf, const allocator_type& a) |
| 75 | : unordered_map(n, hf, key_equal(), a) {} // C++14 |
| 76 | template <class InputIterator> |
| 77 | unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a) |
| 78 | : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14 |
| 79 | template <class InputIterator> |
| 80 | unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf, |
| 81 | const allocator_type& a) |
| 82 | : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14 |
| 83 | unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a) |
| 84 | : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14 |
| 85 | unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf, |
| 86 | const allocator_type& a) |
| 87 | : unordered_map(il, n, hf, key_equal(), a) {} // C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 88 | ~unordered_map(); |
| 89 | unordered_map& operator=(const unordered_map&); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 90 | unordered_map& operator=(unordered_map&&) |
| 91 | noexcept( |
| 92 | allocator_type::propagate_on_container_move_assignment::value && |
| 93 | is_nothrow_move_assignable<allocator_type>::value && |
| 94 | is_nothrow_move_assignable<hasher>::value && |
| 95 | is_nothrow_move_assignable<key_equal>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 96 | unordered_map& operator=(initializer_list<value_type>); |
| 97 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 98 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 99 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 100 | bool empty() const noexcept; |
| 101 | size_type size() const noexcept; |
| 102 | size_type max_size() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 103 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 104 | iterator begin() noexcept; |
| 105 | iterator end() noexcept; |
| 106 | const_iterator begin() const noexcept; |
| 107 | const_iterator end() const noexcept; |
| 108 | const_iterator cbegin() const noexcept; |
| 109 | const_iterator cend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 110 | |
| 111 | template <class... Args> |
| 112 | pair<iterator, bool> emplace(Args&&... args); |
| 113 | template <class... Args> |
| 114 | iterator emplace_hint(const_iterator position, Args&&... args); |
| 115 | pair<iterator, bool> insert(const value_type& obj); |
| 116 | template <class P> |
| 117 | pair<iterator, bool> insert(P&& obj); |
| 118 | iterator insert(const_iterator hint, const value_type& obj); |
| 119 | template <class P> |
| 120 | iterator insert(const_iterator hint, P&& obj); |
| 121 | template <class InputIterator> |
| 122 | void insert(InputIterator first, InputIterator last); |
| 123 | void insert(initializer_list<value_type>); |
| 124 | |
Marshall Clow | 0ce05a9 | 2015-07-07 05:45:35 +0000 | [diff] [blame] | 125 | template <class... Args> |
| 126 | pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17 |
| 127 | template <class... Args> |
| 128 | pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17 |
| 129 | template <class... Args> |
| 130 | iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17 |
| 131 | template <class... Args> |
| 132 | iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17 |
| 133 | template <class M> |
| 134 | pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17 |
| 135 | template <class M> |
| 136 | pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17 |
| 137 | template <class M> |
| 138 | iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17 |
| 139 | template <class M> |
| 140 | iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17 |
| 141 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 142 | iterator erase(const_iterator position); |
Marshall Clow | 488025c | 2015-05-10 13:35:00 +0000 | [diff] [blame] | 143 | iterator erase(iterator position); // C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | size_type erase(const key_type& k); |
| 145 | iterator erase(const_iterator first, const_iterator last); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 146 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 147 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 148 | void swap(unordered_map&) |
| 149 | noexcept( |
| 150 | (!allocator_type::propagate_on_container_swap::value || |
| 151 | __is_nothrow_swappable<allocator_type>::value) && |
| 152 | __is_nothrow_swappable<hasher>::value && |
| 153 | __is_nothrow_swappable<key_equal>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 154 | |
| 155 | hasher hash_function() const; |
| 156 | key_equal key_eq() const; |
| 157 | |
| 158 | iterator find(const key_type& k); |
| 159 | const_iterator find(const key_type& k) const; |
| 160 | size_type count(const key_type& k) const; |
| 161 | pair<iterator, iterator> equal_range(const key_type& k); |
| 162 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 163 | |
| 164 | mapped_type& operator[](const key_type& k); |
| 165 | mapped_type& operator[](key_type&& k); |
| 166 | |
| 167 | mapped_type& at(const key_type& k); |
| 168 | const mapped_type& at(const key_type& k) const; |
| 169 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 170 | size_type bucket_count() const noexcept; |
| 171 | size_type max_bucket_count() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 172 | |
| 173 | size_type bucket_size(size_type n) const; |
| 174 | size_type bucket(const key_type& k) const; |
| 175 | |
| 176 | local_iterator begin(size_type n); |
| 177 | local_iterator end(size_type n); |
| 178 | const_local_iterator begin(size_type n) const; |
| 179 | const_local_iterator end(size_type n) const; |
| 180 | const_local_iterator cbegin(size_type n) const; |
| 181 | const_local_iterator cend(size_type n) const; |
| 182 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 183 | float load_factor() const noexcept; |
| 184 | float max_load_factor() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 185 | void max_load_factor(float z); |
| 186 | void rehash(size_type n); |
| 187 | void reserve(size_type n); |
| 188 | }; |
| 189 | |
| 190 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 191 | void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x, |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 192 | unordered_map<Key, T, Hash, Pred, Alloc>& y) |
| 193 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 194 | |
| 195 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 196 | bool |
| 197 | operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x, |
| 198 | const unordered_map<Key, T, Hash, Pred, Alloc>& y); |
| 199 | |
| 200 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 201 | bool |
| 202 | operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x, |
| 203 | const unordered_map<Key, T, Hash, Pred, Alloc>& y); |
| 204 | |
| 205 | template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 206 | class Alloc = allocator<pair<const Key, T>>> |
| 207 | class unordered_multimap |
| 208 | { |
| 209 | public: |
| 210 | // types |
| 211 | typedef Key key_type; |
| 212 | typedef T mapped_type; |
| 213 | typedef Hash hasher; |
| 214 | typedef Pred key_equal; |
| 215 | typedef Alloc allocator_type; |
| 216 | typedef pair<const key_type, mapped_type> value_type; |
| 217 | typedef value_type& reference; |
| 218 | typedef const value_type& const_reference; |
| 219 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 220 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 221 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 222 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 223 | |
| 224 | typedef /unspecified/ iterator; |
| 225 | typedef /unspecified/ const_iterator; |
| 226 | typedef /unspecified/ local_iterator; |
| 227 | typedef /unspecified/ const_local_iterator; |
| 228 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 229 | unordered_multimap() |
| 230 | noexcept( |
| 231 | is_nothrow_default_constructible<hasher>::value && |
| 232 | is_nothrow_default_constructible<key_equal>::value && |
| 233 | is_nothrow_default_constructible<allocator_type>::value); |
| 234 | explicit unordered_multimap(size_type n, const hasher& hf = hasher(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | const key_equal& eql = key_equal(), |
| 236 | const allocator_type& a = allocator_type()); |
| 237 | template <class InputIterator> |
| 238 | unordered_multimap(InputIterator f, InputIterator l, |
| 239 | size_type n = 0, const hasher& hf = hasher(), |
| 240 | const key_equal& eql = key_equal(), |
| 241 | const allocator_type& a = allocator_type()); |
| 242 | explicit unordered_multimap(const allocator_type&); |
| 243 | unordered_multimap(const unordered_multimap&); |
| 244 | unordered_multimap(const unordered_multimap&, const Allocator&); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 245 | unordered_multimap(unordered_multimap&&) |
| 246 | noexcept( |
| 247 | is_nothrow_move_constructible<hasher>::value && |
| 248 | is_nothrow_move_constructible<key_equal>::value && |
| 249 | is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | unordered_multimap(unordered_multimap&&, const Allocator&); |
| 251 | unordered_multimap(initializer_list<value_type>, size_type n = 0, |
| 252 | const hasher& hf = hasher(), const key_equal& eql = key_equal(), |
| 253 | const allocator_type& a = allocator_type()); |
Marshall Clow | 6dff618 | 2013-09-12 03:00:31 +0000 | [diff] [blame] | 254 | unordered_multimap(size_type n, const allocator_type& a) |
| 255 | : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14 |
| 256 | unordered_multimap(size_type n, const hasher& hf, const allocator_type& a) |
| 257 | : unordered_multimap(n, hf, key_equal(), a) {} // C++14 |
| 258 | template <class InputIterator> |
| 259 | unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a) |
| 260 | : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14 |
| 261 | template <class InputIterator> |
| 262 | unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf, |
| 263 | const allocator_type& a) |
| 264 | : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14 |
| 265 | unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a) |
| 266 | : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14 |
| 267 | unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf, |
| 268 | const allocator_type& a) |
| 269 | : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | ~unordered_multimap(); |
| 271 | unordered_multimap& operator=(const unordered_multimap&); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 272 | unordered_multimap& operator=(unordered_multimap&&) |
| 273 | noexcept( |
| 274 | allocator_type::propagate_on_container_move_assignment::value && |
| 275 | is_nothrow_move_assignable<allocator_type>::value && |
| 276 | is_nothrow_move_assignable<hasher>::value && |
| 277 | is_nothrow_move_assignable<key_equal>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | unordered_multimap& operator=(initializer_list<value_type>); |
| 279 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 280 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 281 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 282 | bool empty() const noexcept; |
| 283 | size_type size() const noexcept; |
| 284 | size_type max_size() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 286 | iterator begin() noexcept; |
| 287 | iterator end() noexcept; |
| 288 | const_iterator begin() const noexcept; |
| 289 | const_iterator end() const noexcept; |
| 290 | const_iterator cbegin() const noexcept; |
| 291 | const_iterator cend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 292 | |
| 293 | template <class... Args> |
| 294 | iterator emplace(Args&&... args); |
| 295 | template <class... Args> |
| 296 | iterator emplace_hint(const_iterator position, Args&&... args); |
| 297 | iterator insert(const value_type& obj); |
| 298 | template <class P> |
| 299 | iterator insert(P&& obj); |
| 300 | iterator insert(const_iterator hint, const value_type& obj); |
| 301 | template <class P> |
| 302 | iterator insert(const_iterator hint, P&& obj); |
| 303 | template <class InputIterator> |
| 304 | void insert(InputIterator first, InputIterator last); |
| 305 | void insert(initializer_list<value_type>); |
| 306 | |
| 307 | iterator erase(const_iterator position); |
Marshall Clow | 488025c | 2015-05-10 13:35:00 +0000 | [diff] [blame] | 308 | iterator erase(iterator position); // C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | size_type erase(const key_type& k); |
| 310 | iterator erase(const_iterator first, const_iterator last); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 311 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 313 | void swap(unordered_multimap&) |
| 314 | noexcept( |
| 315 | (!allocator_type::propagate_on_container_swap::value || |
| 316 | __is_nothrow_swappable<allocator_type>::value) && |
| 317 | __is_nothrow_swappable<hasher>::value && |
| 318 | __is_nothrow_swappable<key_equal>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 319 | |
| 320 | hasher hash_function() const; |
| 321 | key_equal key_eq() const; |
| 322 | |
| 323 | iterator find(const key_type& k); |
| 324 | const_iterator find(const key_type& k) const; |
| 325 | size_type count(const key_type& k) const; |
| 326 | pair<iterator, iterator> equal_range(const key_type& k); |
| 327 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 328 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 329 | size_type bucket_count() const noexcept; |
| 330 | size_type max_bucket_count() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 331 | |
| 332 | size_type bucket_size(size_type n) const; |
| 333 | size_type bucket(const key_type& k) const; |
| 334 | |
| 335 | local_iterator begin(size_type n); |
| 336 | local_iterator end(size_type n); |
| 337 | const_local_iterator begin(size_type n) const; |
| 338 | const_local_iterator end(size_type n) const; |
| 339 | const_local_iterator cbegin(size_type n) const; |
| 340 | const_local_iterator cend(size_type n) const; |
| 341 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 342 | float load_factor() const noexcept; |
| 343 | float max_load_factor() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 344 | void max_load_factor(float z); |
| 345 | void rehash(size_type n); |
| 346 | void reserve(size_type n); |
| 347 | }; |
| 348 | |
| 349 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 350 | void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x, |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 351 | unordered_multimap<Key, T, Hash, Pred, Alloc>& y) |
| 352 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 353 | |
| 354 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 355 | bool |
| 356 | operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, |
| 357 | const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); |
| 358 | |
| 359 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 360 | bool |
| 361 | operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, |
| 362 | const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); |
| 363 | |
| 364 | } // std |
| 365 | |
| 366 | */ |
| 367 | |
| 368 | #include <__config> |
| 369 | #include <__hash_table> |
| 370 | #include <functional> |
| 371 | #include <stdexcept> |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 372 | #include <tuple> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 373 | |
Eric Fiselier | b953610 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 374 | #include <__debug> |
| 375 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 376 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 378 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 379 | |
| 380 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 381 | |
Eric Fiselier | 3a0e430 | 2015-06-13 07:08:02 +0000 | [diff] [blame] | 382 | template <class _Key, class _Cp, class _Hash, |
| 383 | bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value |
Howard Hinnant | d4cf215 | 2011-12-11 20:31:33 +0000 | [diff] [blame] | 384 | > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 385 | class __unordered_map_hasher |
| 386 | : private _Hash |
| 387 | { |
| 388 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 389 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 390 | __unordered_map_hasher() |
| 391 | _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) |
| 392 | : _Hash() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 393 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 394 | __unordered_map_hasher(const _Hash& __h) |
| 395 | _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) |
| 396 | : _Hash(__h) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 397 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 398 | const _Hash& hash_function() const _NOEXCEPT {return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 399 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 400 | size_t operator()(const _Cp& __x) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 401 | {return static_cast<const _Hash&>(*this)(__x.__cc.first);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 402 | _LIBCPP_INLINE_VISIBILITY |
| 403 | size_t operator()(const _Key& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | {return static_cast<const _Hash&>(*this)(__x);} |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 405 | void swap(__unordered_map_hasher&__y) |
| 406 | _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) |
| 407 | { |
| 408 | using _VSTD::swap; |
| 409 | swap(static_cast<const _Hash&>(*this), static_cast<const _Hash&>(__y)); |
| 410 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | }; |
| 412 | |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 413 | template <class _Key, class _Cp, class _Hash> |
| 414 | class __unordered_map_hasher<_Key, _Cp, _Hash, false> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | { |
| 416 | _Hash __hash_; |
| 417 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 418 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 419 | __unordered_map_hasher() |
| 420 | _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) |
| 421 | : __hash_() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 422 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 423 | __unordered_map_hasher(const _Hash& __h) |
| 424 | _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) |
| 425 | : __hash_(__h) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 426 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 427 | const _Hash& hash_function() const _NOEXCEPT {return __hash_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 428 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 429 | size_t operator()(const _Cp& __x) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 430 | {return __hash_(__x.__cc.first);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 431 | _LIBCPP_INLINE_VISIBILITY |
| 432 | size_t operator()(const _Key& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 433 | {return __hash_(__x);} |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 434 | void swap(__unordered_map_hasher&__y) |
| 435 | _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) |
| 436 | { |
| 437 | using _VSTD::swap; |
| 438 | swap(__hash_, __y.__hash_); |
| 439 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 440 | }; |
| 441 | |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 442 | template <class _Key, class _Cp, class _Hash, bool __b> |
| 443 | inline _LIBCPP_INLINE_VISIBILITY |
| 444 | void |
| 445 | swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x, |
| 446 | __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y) |
| 447 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
| 448 | { |
| 449 | __x.swap(__y); |
| 450 | } |
| 451 | |
Eric Fiselier | 3a0e430 | 2015-06-13 07:08:02 +0000 | [diff] [blame] | 452 | template <class _Key, class _Cp, class _Pred, |
| 453 | bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value |
Howard Hinnant | d4cf215 | 2011-12-11 20:31:33 +0000 | [diff] [blame] | 454 | > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 455 | class __unordered_map_equal |
| 456 | : private _Pred |
| 457 | { |
| 458 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 459 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 460 | __unordered_map_equal() |
| 461 | _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) |
| 462 | : _Pred() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 463 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 464 | __unordered_map_equal(const _Pred& __p) |
| 465 | _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) |
| 466 | : _Pred(__p) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 467 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 468 | const _Pred& key_eq() const _NOEXCEPT {return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 469 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 470 | bool operator()(const _Cp& __x, const _Cp& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 471 | {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 472 | _LIBCPP_INLINE_VISIBILITY |
| 473 | bool operator()(const _Cp& __x, const _Key& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 474 | {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 475 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 476 | bool operator()(const _Key& __x, const _Cp& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 477 | {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);} |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 478 | void swap(__unordered_map_equal&__y) |
| 479 | _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) |
| 480 | { |
| 481 | using _VSTD::swap; |
| 482 | swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y)); |
| 483 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 484 | }; |
| 485 | |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 486 | template <class _Key, class _Cp, class _Pred> |
| 487 | class __unordered_map_equal<_Key, _Cp, _Pred, false> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 488 | { |
| 489 | _Pred __pred_; |
| 490 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 491 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 492 | __unordered_map_equal() |
| 493 | _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) |
| 494 | : __pred_() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 495 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 496 | __unordered_map_equal(const _Pred& __p) |
| 497 | _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) |
| 498 | : __pred_(__p) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 499 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 500 | const _Pred& key_eq() const _NOEXCEPT {return __pred_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 501 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 502 | bool operator()(const _Cp& __x, const _Cp& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 503 | {return __pred_(__x.__cc.first, __y.__cc.first);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 504 | _LIBCPP_INLINE_VISIBILITY |
| 505 | bool operator()(const _Cp& __x, const _Key& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 506 | {return __pred_(__x.__cc.first, __y);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 507 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 508 | bool operator()(const _Key& __x, const _Cp& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 509 | {return __pred_(__x, __y.__cc.first);} |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 510 | void swap(__unordered_map_equal&__y) |
| 511 | _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) |
| 512 | { |
| 513 | using _VSTD::swap; |
| 514 | swap(__pred_, __y.__pred_); |
| 515 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | }; |
| 517 | |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 518 | template <class _Key, class _Cp, class _Pred, bool __b> |
| 519 | inline _LIBCPP_INLINE_VISIBILITY |
| 520 | void |
| 521 | swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x, |
| 522 | __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y) |
| 523 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
| 524 | { |
| 525 | __x.swap(__y); |
| 526 | } |
| 527 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 528 | template <class _Alloc> |
| 529 | class __hash_map_node_destructor |
| 530 | { |
| 531 | typedef _Alloc allocator_type; |
| 532 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 533 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 534 | public: |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 535 | |
| 536 | typedef typename __alloc_traits::pointer pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 537 | private: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 538 | |
| 539 | allocator_type& __na_; |
| 540 | |
| 541 | __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); |
| 542 | |
| 543 | public: |
| 544 | bool __first_constructed; |
| 545 | bool __second_constructed; |
| 546 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 547 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 548 | explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 549 | : __na_(__na), |
| 550 | __first_constructed(false), |
| 551 | __second_constructed(false) |
| 552 | {} |
| 553 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 554 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 555 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 556 | __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 557 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 558 | : __na_(__x.__na_), |
| 559 | __first_constructed(__x.__value_constructed), |
| 560 | __second_constructed(__x.__value_constructed) |
| 561 | { |
| 562 | __x.__value_constructed = false; |
| 563 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 564 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) |
| 567 | : __na_(__x.__na_), |
| 568 | __first_constructed(__x.__value_constructed), |
| 569 | __second_constructed(__x.__value_constructed) |
| 570 | { |
| 571 | const_cast<bool&>(__x.__value_constructed) = false; |
| 572 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 573 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 574 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 575 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 576 | void operator()(pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 577 | { |
| 578 | if (__second_constructed) |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 579 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | if (__first_constructed) |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 581 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 582 | if (__p) |
| 583 | __alloc_traits::deallocate(__na_, __p, 1); |
| 584 | } |
| 585 | }; |
| 586 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 587 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 588 | template <class _Key, class _Tp> |
| 589 | union __hash_value_type |
| 590 | { |
| 591 | typedef _Key key_type; |
| 592 | typedef _Tp mapped_type; |
| 593 | typedef pair<const key_type, mapped_type> value_type; |
| 594 | typedef pair<key_type, mapped_type> __nc_value_type; |
| 595 | |
| 596 | value_type __cc; |
| 597 | __nc_value_type __nc; |
| 598 | |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 599 | _LIBCPP_INLINE_VISIBILITY |
| 600 | __hash_value_type& operator=(const __hash_value_type& __v) |
| 601 | {__nc = __v.__cc; return *this;} |
| 602 | |
| 603 | _LIBCPP_INLINE_VISIBILITY |
| 604 | __hash_value_type& operator=(__hash_value_type&& __v) |
Marshall Clow | cd13782 | 2015-05-06 12:11:22 +0000 | [diff] [blame] | 605 | {__nc = _VSTD::move(__v.__nc); return *this;} |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 606 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 607 | template <class _ValueTp, |
| 608 | class = typename enable_if< |
| 609 | __is_same_uncvref<_ValueTp, value_type>::value |
| 610 | >::type |
| 611 | > |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 612 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 613 | __hash_value_type& operator=(_ValueTp&& __v) { |
| 614 | __nc = _VSTD::forward<_ValueTp>(__v); return *this; |
| 615 | } |
| 616 | |
| 617 | private: |
| 618 | __hash_value_type(const __hash_value_type& __v) = delete; |
| 619 | __hash_value_type(__hash_value_type&& __v) = delete; |
| 620 | template <class ..._Args> |
| 621 | explicit __hash_value_type(_Args&& ...__args) = delete; |
| 622 | |
| 623 | ~__hash_value_type() = delete; |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 624 | }; |
| 625 | |
| 626 | #else |
| 627 | |
| 628 | template <class _Key, class _Tp> |
| 629 | struct __hash_value_type |
| 630 | { |
| 631 | typedef _Key key_type; |
| 632 | typedef _Tp mapped_type; |
| 633 | typedef pair<const key_type, mapped_type> value_type; |
| 634 | |
| 635 | value_type __cc; |
| 636 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 637 | private: |
| 638 | ~__hash_value_type(); |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 639 | }; |
| 640 | |
| 641 | #endif |
| 642 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 643 | template <class _HashIterator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 644 | class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 645 | { |
| 646 | _HashIterator __i_; |
| 647 | |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 648 | typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes; |
| 649 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 650 | public: |
| 651 | typedef forward_iterator_tag iterator_category; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 652 | typedef typename _NodeTypes::__map_value_type value_type; |
| 653 | typedef typename _NodeTypes::difference_type difference_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 654 | typedef value_type& reference; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 655 | typedef typename _NodeTypes::__map_value_type_pointer pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 656 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 657 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 658 | __hash_map_iterator() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 659 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 660 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 661 | __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 663 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 664 | reference operator*() const {return __i_->__cc;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 665 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 666 | pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 667 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 668 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 669 | __hash_map_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 670 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 671 | __hash_map_iterator operator++(int) |
| 672 | { |
| 673 | __hash_map_iterator __t(*this); |
| 674 | ++(*this); |
| 675 | return __t; |
| 676 | } |
| 677 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 678 | friend _LIBCPP_INLINE_VISIBILITY |
| 679 | bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 680 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 681 | friend _LIBCPP_INLINE_VISIBILITY |
| 682 | bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 683 | {return __x.__i_ != __y.__i_;} |
| 684 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 685 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; |
| 686 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; |
| 687 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; |
| 688 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; |
| 689 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 690 | }; |
| 691 | |
| 692 | template <class _HashIterator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 693 | class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 694 | { |
| 695 | _HashIterator __i_; |
| 696 | |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 697 | typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes; |
| 698 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 699 | public: |
| 700 | typedef forward_iterator_tag iterator_category; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 701 | typedef typename _NodeTypes::__map_value_type value_type; |
| 702 | typedef typename _NodeTypes::difference_type difference_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 703 | typedef const value_type& reference; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 704 | typedef typename _NodeTypes::__const_map_value_type_pointer pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 705 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 706 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 707 | __hash_map_const_iterator() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 708 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 709 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 710 | __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 711 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 712 | __hash_map_const_iterator( |
| 713 | __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 714 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 715 | : __i_(__i.__i_) {} |
| 716 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 717 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 718 | reference operator*() const {return __i_->__cc;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 719 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 720 | pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 721 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 722 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 | __hash_map_const_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 724 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 725 | __hash_map_const_iterator operator++(int) |
| 726 | { |
| 727 | __hash_map_const_iterator __t(*this); |
| 728 | ++(*this); |
| 729 | return __t; |
| 730 | } |
| 731 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 732 | friend _LIBCPP_INLINE_VISIBILITY |
| 733 | bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 734 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 735 | friend _LIBCPP_INLINE_VISIBILITY |
| 736 | bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 737 | {return __x.__i_ != __y.__i_;} |
| 738 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 739 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; |
| 740 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; |
| 741 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; |
| 742 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 743 | }; |
| 744 | |
| 745 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 746 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 747 | class _LIBCPP_TYPE_VIS_ONLY unordered_map |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 748 | { |
| 749 | public: |
| 750 | // types |
| 751 | typedef _Key key_type; |
| 752 | typedef _Tp mapped_type; |
| 753 | typedef _Hash hasher; |
| 754 | typedef _Pred key_equal; |
| 755 | typedef _Alloc allocator_type; |
| 756 | typedef pair<const key_type, mapped_type> value_type; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 757 | typedef pair<key_type, mapped_type> __nc_value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 758 | typedef value_type& reference; |
| 759 | typedef const value_type& const_reference; |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 760 | static_assert((is_same<value_type, typename allocator_type::value_type>::value), |
| 761 | "Invalid allocator::value_type"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 762 | |
| 763 | private: |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 764 | typedef __hash_value_type<key_type, mapped_type> __value_type; |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 765 | typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; |
| 766 | typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 767 | typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, |
| 768 | __value_type>::type __allocator_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 769 | |
| 770 | typedef __hash_table<__value_type, __hasher, |
| 771 | __key_equal, __allocator_type> __table; |
| 772 | |
| 773 | __table __table_; |
| 774 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 775 | typedef typename __table::_NodeTypes _NodeTypes; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 776 | typedef typename __table::__node_pointer __node_pointer; |
| 777 | typedef typename __table::__node_const_pointer __node_const_pointer; |
| 778 | typedef typename __table::__node_traits __node_traits; |
| 779 | typedef typename __table::__node_allocator __node_allocator; |
| 780 | typedef typename __table::__node __node; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 781 | typedef __hash_map_node_destructor<__node_allocator> _Dp; |
| 782 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 783 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 784 | |
| 785 | static_assert((is_same<typename __table::__container_value_type, value_type>::value), ""); |
| 786 | static_assert((is_same<typename __table::__node_value_type, __value_type>::value), ""); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 787 | public: |
| 788 | typedef typename __alloc_traits::pointer pointer; |
| 789 | typedef typename __alloc_traits::const_pointer const_pointer; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 790 | typedef typename __table::size_type size_type; |
| 791 | typedef typename __table::difference_type difference_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 792 | |
| 793 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 794 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 795 | typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; |
| 796 | typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; |
| 797 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 799 | unordered_map() |
| 800 | _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 801 | { |
| 802 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 803 | __get_db()->__insert_c(this); |
| 804 | #endif |
| 805 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 806 | explicit unordered_map(size_type __n, const hasher& __hf = hasher(), |
| 807 | const key_equal& __eql = key_equal()); |
| 808 | unordered_map(size_type __n, const hasher& __hf, |
| 809 | const key_equal& __eql, |
| 810 | const allocator_type& __a); |
| 811 | template <class _InputIterator> |
| 812 | unordered_map(_InputIterator __first, _InputIterator __last); |
| 813 | template <class _InputIterator> |
| 814 | unordered_map(_InputIterator __first, _InputIterator __last, |
| 815 | size_type __n, const hasher& __hf = hasher(), |
| 816 | const key_equal& __eql = key_equal()); |
| 817 | template <class _InputIterator> |
| 818 | unordered_map(_InputIterator __first, _InputIterator __last, |
| 819 | size_type __n, const hasher& __hf, |
| 820 | const key_equal& __eql, |
| 821 | const allocator_type& __a); |
| 822 | explicit unordered_map(const allocator_type& __a); |
| 823 | unordered_map(const unordered_map& __u); |
| 824 | unordered_map(const unordered_map& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 825 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 826 | unordered_map(unordered_map&& __u) |
| 827 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 828 | unordered_map(unordered_map&& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 829 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 830 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | unordered_map(initializer_list<value_type> __il); |
| 832 | unordered_map(initializer_list<value_type> __il, size_type __n, |
| 833 | const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); |
| 834 | unordered_map(initializer_list<value_type> __il, size_type __n, |
| 835 | const hasher& __hf, const key_equal& __eql, |
| 836 | const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 837 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Marshall Clow | 6dff618 | 2013-09-12 03:00:31 +0000 | [diff] [blame] | 838 | #if _LIBCPP_STD_VER > 11 |
| 839 | _LIBCPP_INLINE_VISIBILITY |
| 840 | unordered_map(size_type __n, const allocator_type& __a) |
| 841 | : unordered_map(__n, hasher(), key_equal(), __a) {} |
| 842 | _LIBCPP_INLINE_VISIBILITY |
| 843 | unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a) |
| 844 | : unordered_map(__n, __hf, key_equal(), __a) {} |
| 845 | template <class _InputIterator> |
| 846 | _LIBCPP_INLINE_VISIBILITY |
| 847 | unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) |
| 848 | : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {} |
| 849 | template <class _InputIterator> |
| 850 | _LIBCPP_INLINE_VISIBILITY |
| 851 | unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, |
| 852 | const allocator_type& __a) |
| 853 | : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {} |
| 854 | _LIBCPP_INLINE_VISIBILITY |
| 855 | unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) |
| 856 | : unordered_map(__il, __n, hasher(), key_equal(), __a) {} |
| 857 | _LIBCPP_INLINE_VISIBILITY |
| 858 | unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 859 | const allocator_type& __a) |
| 860 | : unordered_map(__il, __n, __hf, key_equal(), __a) {} |
| 861 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 862 | // ~unordered_map() = default; |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 863 | _LIBCPP_INLINE_VISIBILITY |
| 864 | unordered_map& operator=(const unordered_map& __u) |
| 865 | { |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 866 | #if __cplusplus >= 201103L |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 867 | __table_ = __u.__table_; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 868 | #else |
Marshall Clow | ebfc50e | 2014-02-08 04:03:14 +0000 | [diff] [blame] | 869 | if (this != &__u) { |
| 870 | __table_.clear(); |
| 871 | __table_.hash_function() = __u.__table_.hash_function(); |
| 872 | __table_.key_eq() = __u.__table_.key_eq(); |
| 873 | __table_.max_load_factor() = __u.__table_.max_load_factor(); |
| 874 | __table_.__copy_assign_alloc(__u.__table_); |
| 875 | insert(__u.begin(), __u.end()); |
| 876 | } |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 877 | #endif |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 878 | return *this; |
| 879 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 880 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 881 | unordered_map& operator=(unordered_map&& __u) |
| 882 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 883 | #endif |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 884 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 885 | unordered_map& operator=(initializer_list<value_type> __il); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 886 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 887 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 888 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 889 | allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 890 | {return allocator_type(__table_.__node_alloc());} |
| 891 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 892 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 893 | bool empty() const _NOEXCEPT {return __table_.size() == 0;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 894 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 895 | size_type size() const _NOEXCEPT {return __table_.size();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 896 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 897 | size_type max_size() const _NOEXCEPT {return __table_.max_size();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 898 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 899 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 900 | iterator begin() _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 901 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 902 | iterator end() _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 903 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 904 | const_iterator begin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 905 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 906 | const_iterator end() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 907 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 908 | const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 909 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 910 | const_iterator cend() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 911 | |
Eric Fiselier | 91a1565 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 912 | _LIBCPP_INLINE_VISIBILITY |
| 913 | pair<iterator, bool> insert(const value_type& __x) |
| 914 | {return __table_.__insert_unique(__x);} |
| 915 | |
| 916 | iterator insert(const_iterator __p, const value_type& __x) { |
| 917 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 918 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 919 | "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" |
| 920 | " referring to this unordered_map"); |
| 921 | #endif |
| 922 | return insert(__x).first; |
| 923 | } |
| 924 | |
| 925 | template <class _InputIterator> |
| 926 | void insert(_InputIterator __first, _InputIterator __last); |
| 927 | |
| 928 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 929 | _LIBCPP_INLINE_VISIBILITY |
| 930 | void insert(initializer_list<value_type> __il) |
| 931 | {insert(__il.begin(), __il.end());} |
| 932 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 933 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 934 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 91a1565 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 935 | _LIBCPP_INLINE_VISIBILITY |
| 936 | pair<iterator, bool> insert(value_type&& __x) |
| 937 | {return __table_.__insert_unique(_VSTD::move(__x));} |
| 938 | |
| 939 | iterator insert(const_iterator __p, value_type&& __x) { |
| 940 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 941 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 942 | "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" |
| 943 | " referring to this unordered_map"); |
| 944 | #endif |
| 945 | return __table_.__insert_unique(_VSTD::move(__x)).first; |
| 946 | } |
| 947 | |
| 948 | template <class _Pp, |
| 949 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
| 950 | _LIBCPP_INLINE_VISIBILITY |
| 951 | pair<iterator, bool> insert(_Pp&& __x) |
| 952 | {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));} |
| 953 | |
| 954 | template <class _Pp, |
| 955 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
| 956 | _LIBCPP_INLINE_VISIBILITY |
| 957 | iterator insert(const_iterator __p, _Pp&& __x) |
| 958 | { |
| 959 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 960 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 961 | "unordered_map::insert(const_iterator, value_type&&) called with an iterator not" |
| 962 | " referring to this unordered_map"); |
| 963 | #endif |
| 964 | return insert(_VSTD::forward<_Pp>(__x)).first; |
| 965 | } |
| 966 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 967 | template <class... _Args> |
| 968 | _LIBCPP_INLINE_VISIBILITY |
| 969 | pair<iterator, bool> emplace(_Args&&... __args) { |
| 970 | return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...); |
| 971 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 972 | |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 973 | template <class... _Args> |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 974 | _LIBCPP_INLINE_VISIBILITY |
| 975 | iterator emplace_hint(const_iterator __p, _Args&&... __args) { |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 976 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 977 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 978 | "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not" |
| 979 | " referring to this unordered_map"); |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 980 | #endif |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 981 | return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; |
| 982 | } |
| 983 | |
Eric Fiselier | 91a1565 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 984 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 985 | |
Marshall Clow | 0ce05a9 | 2015-07-07 05:45:35 +0000 | [diff] [blame] | 986 | #if _LIBCPP_STD_VER > 14 |
| 987 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 988 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 989 | template <class... _Args> |
| 990 | _LIBCPP_INLINE_VISIBILITY |
| 991 | pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) |
| 992 | { |
| 993 | iterator __p = __table_.find(__k); |
| 994 | if ( __p != end()) |
| 995 | return _VSTD::make_pair(__p, false); |
| 996 | else |
| 997 | return _VSTD::make_pair( |
| 998 | emplace_hint(__p, |
| 999 | _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), |
| 1000 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)), |
| 1001 | true); |
| 1002 | } |
| 1003 | |
| 1004 | template <class... _Args> |
| 1005 | _LIBCPP_INLINE_VISIBILITY |
| 1006 | pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) |
| 1007 | { |
| 1008 | iterator __p = __table_.find(__k); |
| 1009 | if ( __p != end()) |
| 1010 | return _VSTD::make_pair(__p, false); |
| 1011 | else |
| 1012 | return _VSTD::make_pair( |
| 1013 | emplace_hint(__p, |
| 1014 | _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), |
| 1015 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)), |
| 1016 | true); |
| 1017 | } |
| 1018 | |
| 1019 | template <class... _Args> |
| 1020 | _LIBCPP_INLINE_VISIBILITY |
| 1021 | iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) |
| 1022 | { |
| 1023 | iterator __p = __table_.find(__k); |
| 1024 | if ( __p != end()) |
| 1025 | return __p; |
| 1026 | else |
| 1027 | return emplace_hint(__h, |
| 1028 | _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), |
| 1029 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); |
| 1030 | } |
| 1031 | |
| 1032 | template <class... _Args> |
| 1033 | _LIBCPP_INLINE_VISIBILITY |
| 1034 | iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) |
| 1035 | { |
| 1036 | iterator __p = __table_.find(__k); |
| 1037 | if ( __p != end()) |
| 1038 | return __p; |
| 1039 | else |
| 1040 | return emplace_hint(__h, |
| 1041 | _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), |
| 1042 | _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); |
| 1043 | } |
| 1044 | |
| 1045 | template <class _Vp> |
| 1046 | _LIBCPP_INLINE_VISIBILITY |
| 1047 | pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) |
| 1048 | { |
| 1049 | iterator __p = __table_.find(__k); |
| 1050 | if ( __p != end()) |
| 1051 | { |
| 1052 | __p->second = _VSTD::move(__v); |
| 1053 | return _VSTD::make_pair(__p, false); |
| 1054 | } |
| 1055 | return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true); |
| 1056 | } |
| 1057 | |
| 1058 | template <class _Vp> |
| 1059 | _LIBCPP_INLINE_VISIBILITY |
| 1060 | pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) |
| 1061 | { |
| 1062 | iterator __p = __table_.find(__k); |
| 1063 | if ( __p != end()) |
| 1064 | { |
| 1065 | __p->second = _VSTD::move(__v); |
| 1066 | return _VSTD::make_pair(__p, false); |
| 1067 | } |
| 1068 | return _VSTD::make_pair(emplace_hint(__p, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)), true); |
| 1069 | } |
| 1070 | |
| 1071 | template <class _Vp> |
| 1072 | _LIBCPP_INLINE_VISIBILITY |
| 1073 | iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v) |
| 1074 | { |
| 1075 | iterator __p = __table_.find(__k); |
| 1076 | if ( __p != end()) |
| 1077 | { |
| 1078 | __p->second = _VSTD::move(__v); |
| 1079 | return __p; |
| 1080 | } |
| 1081 | return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v)); |
| 1082 | } |
| 1083 | |
| 1084 | template <class _Vp> |
| 1085 | _LIBCPP_INLINE_VISIBILITY |
| 1086 | iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v) |
| 1087 | { |
| 1088 | iterator __p = __table_.find(__k); |
| 1089 | if ( __p != end()) |
| 1090 | { |
| 1091 | __p->second = _VSTD::move(__v); |
| 1092 | return __p; |
| 1093 | } |
| 1094 | return emplace_hint(__h, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)); |
| 1095 | } |
| 1096 | #endif |
| 1097 | #endif |
| 1098 | #endif |
| 1099 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1100 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1101 | iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1102 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 488025c | 2015-05-10 13:35:00 +0000 | [diff] [blame] | 1103 | iterator erase(iterator __p) {return __table_.erase(__p.__i_);} |
| 1104 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1105 | size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1106 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1107 | iterator erase(const_iterator __first, const_iterator __last) |
| 1108 | {return __table_.erase(__first.__i_, __last.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1109 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1110 | void clear() _NOEXCEPT {__table_.clear();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1111 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1112 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1113 | void swap(unordered_map& __u) |
| 1114 | _NOEXCEPT_(__is_nothrow_swappable<__table>::value) |
| 1115 | {__table_.swap(__u.__table_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1116 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1117 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1118 | hasher hash_function() const |
| 1119 | {return __table_.hash_function().hash_function();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1120 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1121 | key_equal key_eq() const |
| 1122 | {return __table_.key_eq().key_eq();} |
| 1123 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1124 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1125 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1126 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1127 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1128 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1129 | size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1130 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1131 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 1132 | {return __table_.__equal_range_unique(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1133 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1134 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 1135 | {return __table_.__equal_range_unique(__k);} |
| 1136 | |
| 1137 | mapped_type& operator[](const key_type& __k); |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1138 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1139 | mapped_type& operator[](key_type&& __k); |
| 1140 | #endif |
| 1141 | |
| 1142 | mapped_type& at(const key_type& __k); |
| 1143 | const mapped_type& at(const key_type& __k) const; |
| 1144 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1145 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1146 | size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1147 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1148 | size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1149 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1150 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1151 | size_type bucket_size(size_type __n) const |
| 1152 | {return __table_.bucket_size(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1153 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1154 | size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} |
| 1155 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1156 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1157 | local_iterator begin(size_type __n) {return __table_.begin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1158 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1159 | local_iterator end(size_type __n) {return __table_.end(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1160 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1161 | const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1162 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1163 | const_local_iterator end(size_type __n) const {return __table_.cend(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1164 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1165 | const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1166 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} |
| 1168 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1169 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1170 | float load_factor() const _NOEXCEPT {return __table_.load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1171 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1172 | float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1173 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1174 | void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1175 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1176 | void rehash(size_type __n) {__table_.rehash(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1177 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1178 | void reserve(size_type __n) {__table_.reserve(__n);} |
| 1179 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1180 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1181 | |
| 1182 | bool __dereferenceable(const const_iterator* __i) const |
| 1183 | {return __table_.__dereferenceable(&__i->__i_);} |
| 1184 | bool __decrementable(const const_iterator* __i) const |
| 1185 | {return __table_.__decrementable(&__i->__i_);} |
| 1186 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const |
| 1187 | {return __table_.__addable(&__i->__i_, __n);} |
| 1188 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 1189 | {return __table_.__addable(&__i->__i_, __n);} |
| 1190 | |
| 1191 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 1192 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1193 | private: |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1194 | |
| 1195 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1196 | __node_holder __construct_node_with_key(const key_type& __k); |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1197 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | }; |
| 1199 | |
| 1200 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1201 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1202 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 1203 | : __table_(__hf, __eql) |
| 1204 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1205 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1206 | __get_db()->__insert_c(this); |
| 1207 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1208 | __table_.rehash(__n); |
| 1209 | } |
| 1210 | |
| 1211 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1212 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1213 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 1214 | const allocator_type& __a) |
| 1215 | : __table_(__hf, __eql, __a) |
| 1216 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1217 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1218 | __get_db()->__insert_c(this); |
| 1219 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1220 | __table_.rehash(__n); |
| 1221 | } |
| 1222 | |
| 1223 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1224 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1225 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1226 | const allocator_type& __a) |
| 1227 | : __table_(__a) |
| 1228 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1229 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1230 | __get_db()->__insert_c(this); |
| 1231 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1235 | template <class _InputIterator> |
| 1236 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1237 | _InputIterator __first, _InputIterator __last) |
| 1238 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1239 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1240 | __get_db()->__insert_c(this); |
| 1241 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1242 | insert(__first, __last); |
| 1243 | } |
| 1244 | |
| 1245 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1246 | template <class _InputIterator> |
| 1247 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1248 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1249 | const hasher& __hf, const key_equal& __eql) |
| 1250 | : __table_(__hf, __eql) |
| 1251 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1252 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1253 | __get_db()->__insert_c(this); |
| 1254 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1255 | __table_.rehash(__n); |
| 1256 | insert(__first, __last); |
| 1257 | } |
| 1258 | |
| 1259 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1260 | template <class _InputIterator> |
| 1261 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1262 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1263 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 1264 | : __table_(__hf, __eql, __a) |
| 1265 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1266 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1267 | __get_db()->__insert_c(this); |
| 1268 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1269 | __table_.rehash(__n); |
| 1270 | insert(__first, __last); |
| 1271 | } |
| 1272 | |
| 1273 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1274 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1275 | const unordered_map& __u) |
| 1276 | : __table_(__u.__table_) |
| 1277 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1278 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1279 | __get_db()->__insert_c(this); |
| 1280 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1281 | __table_.rehash(__u.bucket_count()); |
| 1282 | insert(__u.begin(), __u.end()); |
| 1283 | } |
| 1284 | |
| 1285 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1286 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1287 | const unordered_map& __u, const allocator_type& __a) |
| 1288 | : __table_(__u.__table_, __a) |
| 1289 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1290 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1291 | __get_db()->__insert_c(this); |
| 1292 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1293 | __table_.rehash(__u.bucket_count()); |
| 1294 | insert(__u.begin(), __u.end()); |
| 1295 | } |
| 1296 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1297 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1298 | |
| 1299 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1300 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1301 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1302 | unordered_map&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1303 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1304 | : __table_(_VSTD::move(__u.__table_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1305 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1306 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1307 | __get_db()->__insert_c(this); |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 1308 | __get_db()->swap(this, &__u); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1309 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1313 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1314 | unordered_map&& __u, const allocator_type& __a) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1315 | : __table_(_VSTD::move(__u.__table_), __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1316 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1317 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1318 | __get_db()->__insert_c(this); |
| 1319 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1320 | if (__a != __u.get_allocator()) |
| 1321 | { |
| 1322 | iterator __i = __u.begin(); |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1323 | while (__u.size() != 0) { |
| 1324 | __table_.__emplace_unique(_VSTD::move( |
| 1325 | __u.__table_.remove((__i++).__i_)->__value_.__nc)); |
| 1326 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1327 | } |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 1328 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1329 | else |
| 1330 | __get_db()->swap(this, &__u); |
| 1331 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1334 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1335 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1336 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1337 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1339 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1340 | initializer_list<value_type> __il) |
| 1341 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1342 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1343 | __get_db()->__insert_c(this); |
| 1344 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1345 | insert(__il.begin(), __il.end()); |
| 1346 | } |
| 1347 | |
| 1348 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1349 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1350 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1351 | const key_equal& __eql) |
| 1352 | : __table_(__hf, __eql) |
| 1353 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1354 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1355 | __get_db()->__insert_c(this); |
| 1356 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1357 | __table_.rehash(__n); |
| 1358 | insert(__il.begin(), __il.end()); |
| 1359 | } |
| 1360 | |
| 1361 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1362 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1363 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1364 | const key_equal& __eql, const allocator_type& __a) |
| 1365 | : __table_(__hf, __eql, __a) |
| 1366 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1367 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1368 | __get_db()->__insert_c(this); |
| 1369 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1370 | __table_.rehash(__n); |
| 1371 | insert(__il.begin(), __il.end()); |
| 1372 | } |
| 1373 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1374 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1375 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1376 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1377 | |
| 1378 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1379 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1380 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1381 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1382 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1383 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1384 | __table_ = _VSTD::move(__u.__table_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1385 | return *this; |
| 1386 | } |
| 1387 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1388 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1389 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1390 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1391 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1392 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1393 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1394 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1395 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( |
| 1396 | initializer_list<value_type> __il) |
| 1397 | { |
| 1398 | __table_.__assign_unique(__il.begin(), __il.end()); |
| 1399 | return *this; |
| 1400 | } |
| 1401 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1402 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1403 | |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1404 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1405 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1406 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1407 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1408 | { |
| 1409 | __node_allocator& __na = __table_.__node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1410 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1411 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1412 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1413 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1414 | __h.get_deleter().__second_constructed = true; |
Dimitry Andric | 8966350 | 2015-08-19 06:43:33 +0000 | [diff] [blame] | 1415 | return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1416 | } |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1417 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1418 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1419 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1420 | template <class _InputIterator> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1421 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1422 | void |
| 1423 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 1424 | _InputIterator __last) |
| 1425 | { |
| 1426 | for (; __first != __last; ++__first) |
| 1427 | __table_.__insert_unique(*__first); |
| 1428 | } |
| 1429 | |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1430 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1431 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1432 | _Tp& |
| 1433 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) |
| 1434 | { |
| 1435 | iterator __i = find(__k); |
| 1436 | if (__i != end()) |
| 1437 | return __i->second; |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1438 | __node_holder __h = __construct_node_with_key(__k); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1439 | pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); |
| 1440 | __h.release(); |
| 1441 | return __r.first->second; |
| 1442 | } |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1443 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1444 | |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1445 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1446 | _Tp& |
| 1447 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) |
| 1448 | { |
| 1449 | return __table_.__emplace_unique_key_args(__k, |
| 1450 | std::piecewise_construct, std::forward_as_tuple(__k), |
| 1451 | std::forward_as_tuple()).first->__cc.second; |
| 1452 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1453 | |
| 1454 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1455 | _Tp& |
| 1456 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k) |
| 1457 | { |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1458 | return __table_.__emplace_unique_key_args(__k, |
| 1459 | std::piecewise_construct, std::forward_as_tuple(std::move(__k)), |
| 1460 | std::forward_as_tuple()).first->__cc.second; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Eric Fiselier | 410ed30 | 2016-02-11 21:45:53 +0000 | [diff] [blame] | 1463 | #endif // !_LIBCPP_CXX03_MODE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1464 | |
| 1465 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1466 | _Tp& |
| 1467 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) |
| 1468 | { |
| 1469 | iterator __i = find(__k); |
| 1470 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1471 | if (__i == end()) |
| 1472 | throw out_of_range("unordered_map::at: key not found"); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1473 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1474 | return __i->second; |
| 1475 | } |
| 1476 | |
| 1477 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1478 | const _Tp& |
| 1479 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const |
| 1480 | { |
| 1481 | const_iterator __i = find(__k); |
| 1482 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1483 | if (__i == end()) |
| 1484 | throw out_of_range("unordered_map::at: key not found"); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1485 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1486 | return __i->second; |
| 1487 | } |
| 1488 | |
| 1489 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1490 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1491 | void |
| 1492 | swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1493 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1494 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1495 | { |
| 1496 | __x.swap(__y); |
| 1497 | } |
| 1498 | |
| 1499 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1500 | bool |
| 1501 | operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1502 | const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1503 | { |
| 1504 | if (__x.size() != __y.size()) |
| 1505 | return false; |
| 1506 | typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 1507 | const_iterator; |
| 1508 | for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); |
| 1509 | __i != __ex; ++__i) |
| 1510 | { |
| 1511 | const_iterator __j = __y.find(__i->first); |
| 1512 | if (__j == __ey || !(*__i == *__j)) |
| 1513 | return false; |
| 1514 | } |
| 1515 | return true; |
| 1516 | } |
| 1517 | |
| 1518 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1519 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1520 | bool |
| 1521 | operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1522 | const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1523 | { |
| 1524 | return !(__x == __y); |
| 1525 | } |
| 1526 | |
| 1527 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 1528 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1529 | class _LIBCPP_TYPE_VIS_ONLY unordered_multimap |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1530 | { |
| 1531 | public: |
| 1532 | // types |
| 1533 | typedef _Key key_type; |
| 1534 | typedef _Tp mapped_type; |
| 1535 | typedef _Hash hasher; |
| 1536 | typedef _Pred key_equal; |
| 1537 | typedef _Alloc allocator_type; |
| 1538 | typedef pair<const key_type, mapped_type> value_type; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1539 | typedef pair<key_type, mapped_type> __nc_value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1540 | typedef value_type& reference; |
| 1541 | typedef const value_type& const_reference; |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1542 | static_assert((is_same<value_type, typename allocator_type::value_type>::value), |
| 1543 | "Invalid allocator::value_type"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1544 | |
| 1545 | private: |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 1546 | typedef __hash_value_type<key_type, mapped_type> __value_type; |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 1547 | typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; |
| 1548 | typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1549 | typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, |
| 1550 | __value_type>::type __allocator_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1551 | |
| 1552 | typedef __hash_table<__value_type, __hasher, |
| 1553 | __key_equal, __allocator_type> __table; |
| 1554 | |
| 1555 | __table __table_; |
| 1556 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1557 | typedef typename __table::_NodeTypes _NodeTypes; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1558 | typedef typename __table::__node_traits __node_traits; |
| 1559 | typedef typename __table::__node_allocator __node_allocator; |
| 1560 | typedef typename __table::__node __node; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1561 | typedef __hash_map_node_destructor<__node_allocator> _Dp; |
| 1562 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1563 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 1564 | static_assert((is_same<typename __node_traits::size_type, |
| 1565 | typename __alloc_traits::size_type>::value), |
| 1566 | "Allocator uses different size_type for different types"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1567 | public: |
| 1568 | typedef typename __alloc_traits::pointer pointer; |
| 1569 | typedef typename __alloc_traits::const_pointer const_pointer; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 1570 | typedef typename __table::size_type size_type; |
| 1571 | typedef typename __table::difference_type difference_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1572 | |
| 1573 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 1574 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 1575 | typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; |
| 1576 | typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; |
| 1577 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1579 | unordered_multimap() |
| 1580 | _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1581 | { |
| 1582 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1583 | __get_db()->__insert_c(this); |
| 1584 | #endif |
| 1585 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1586 | explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(), |
| 1587 | const key_equal& __eql = key_equal()); |
| 1588 | unordered_multimap(size_type __n, const hasher& __hf, |
| 1589 | const key_equal& __eql, |
| 1590 | const allocator_type& __a); |
| 1591 | template <class _InputIterator> |
| 1592 | unordered_multimap(_InputIterator __first, _InputIterator __last); |
| 1593 | template <class _InputIterator> |
| 1594 | unordered_multimap(_InputIterator __first, _InputIterator __last, |
| 1595 | size_type __n, const hasher& __hf = hasher(), |
| 1596 | const key_equal& __eql = key_equal()); |
| 1597 | template <class _InputIterator> |
| 1598 | unordered_multimap(_InputIterator __first, _InputIterator __last, |
| 1599 | size_type __n, const hasher& __hf, |
| 1600 | const key_equal& __eql, |
| 1601 | const allocator_type& __a); |
| 1602 | explicit unordered_multimap(const allocator_type& __a); |
| 1603 | unordered_multimap(const unordered_multimap& __u); |
| 1604 | unordered_multimap(const unordered_multimap& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1605 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1606 | unordered_multimap(unordered_multimap&& __u) |
| 1607 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1608 | unordered_multimap(unordered_multimap&& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1609 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1610 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1611 | unordered_multimap(initializer_list<value_type> __il); |
| 1612 | unordered_multimap(initializer_list<value_type> __il, size_type __n, |
| 1613 | const hasher& __hf = hasher(), |
| 1614 | const key_equal& __eql = key_equal()); |
| 1615 | unordered_multimap(initializer_list<value_type> __il, size_type __n, |
| 1616 | const hasher& __hf, const key_equal& __eql, |
| 1617 | const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1618 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Marshall Clow | 6dff618 | 2013-09-12 03:00:31 +0000 | [diff] [blame] | 1619 | #if _LIBCPP_STD_VER > 11 |
| 1620 | _LIBCPP_INLINE_VISIBILITY |
| 1621 | unordered_multimap(size_type __n, const allocator_type& __a) |
| 1622 | : unordered_multimap(__n, hasher(), key_equal(), __a) {} |
| 1623 | _LIBCPP_INLINE_VISIBILITY |
| 1624 | unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a) |
| 1625 | : unordered_multimap(__n, __hf, key_equal(), __a) {} |
| 1626 | template <class _InputIterator> |
| 1627 | _LIBCPP_INLINE_VISIBILITY |
| 1628 | unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) |
| 1629 | : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {} |
| 1630 | template <class _InputIterator> |
| 1631 | _LIBCPP_INLINE_VISIBILITY |
| 1632 | unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, |
| 1633 | const allocator_type& __a) |
| 1634 | : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {} |
| 1635 | _LIBCPP_INLINE_VISIBILITY |
| 1636 | unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) |
| 1637 | : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {} |
| 1638 | _LIBCPP_INLINE_VISIBILITY |
| 1639 | unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1640 | const allocator_type& __a) |
| 1641 | : unordered_multimap(__il, __n, __hf, key_equal(), __a) {} |
| 1642 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1643 | // ~unordered_multimap() = default; |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1644 | _LIBCPP_INLINE_VISIBILITY |
| 1645 | unordered_multimap& operator=(const unordered_multimap& __u) |
| 1646 | { |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1647 | #if __cplusplus >= 201103L |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1648 | __table_ = __u.__table_; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1649 | #else |
Marshall Clow | ebfc50e | 2014-02-08 04:03:14 +0000 | [diff] [blame] | 1650 | if (this != &__u) { |
| 1651 | __table_.clear(); |
| 1652 | __table_.hash_function() = __u.__table_.hash_function(); |
| 1653 | __table_.key_eq() = __u.__table_.key_eq(); |
| 1654 | __table_.max_load_factor() = __u.__table_.max_load_factor(); |
| 1655 | __table_.__copy_assign_alloc(__u.__table_); |
| 1656 | insert(__u.begin(), __u.end()); |
| 1657 | } |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1658 | #endif |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1659 | return *this; |
| 1660 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1661 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1662 | unordered_multimap& operator=(unordered_multimap&& __u) |
| 1663 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1664 | #endif |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1665 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1666 | unordered_multimap& operator=(initializer_list<value_type> __il); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1667 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1668 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1669 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1670 | allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1671 | {return allocator_type(__table_.__node_alloc());} |
| 1672 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1673 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1674 | bool empty() const _NOEXCEPT {return __table_.size() == 0;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1675 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1676 | size_type size() const _NOEXCEPT {return __table_.size();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1677 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1678 | size_type max_size() const _NOEXCEPT {return __table_.max_size();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1679 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1680 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1681 | iterator begin() _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1682 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1683 | iterator end() _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1684 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1685 | const_iterator begin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1686 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1687 | const_iterator end() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1688 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1689 | const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1690 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1691 | const_iterator cend() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1692 | |
Eric Fiselier | 91a1565 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 1693 | _LIBCPP_INLINE_VISIBILITY |
| 1694 | iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} |
| 1695 | |
| 1696 | _LIBCPP_INLINE_VISIBILITY |
| 1697 | iterator insert(const_iterator __p, const value_type& __x) |
| 1698 | {return __table_.__insert_multi(__p.__i_, __x);} |
| 1699 | |
| 1700 | template <class _InputIterator> |
| 1701 | void insert(_InputIterator __first, _InputIterator __last); |
| 1702 | |
| 1703 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1704 | _LIBCPP_INLINE_VISIBILITY |
| 1705 | void insert(initializer_list<value_type> __il) |
| 1706 | {insert(__il.begin(), __il.end());} |
| 1707 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1708 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1709 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 91a1565 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 1710 | _LIBCPP_INLINE_VISIBILITY |
| 1711 | iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));} |
| 1712 | |
| 1713 | _LIBCPP_INLINE_VISIBILITY |
| 1714 | iterator insert(const_iterator __p, value_type&& __x) |
| 1715 | {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));} |
| 1716 | |
| 1717 | template <class _Pp, |
| 1718 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
| 1719 | _LIBCPP_INLINE_VISIBILITY |
| 1720 | iterator insert(_Pp&& __x) |
| 1721 | {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));} |
| 1722 | |
| 1723 | template <class _Pp, |
| 1724 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
| 1725 | _LIBCPP_INLINE_VISIBILITY |
| 1726 | iterator insert(const_iterator __p, _Pp&& __x) |
| 1727 | {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));} |
| 1728 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1729 | template <class... _Args> |
| 1730 | iterator emplace(_Args&&... __args) { |
| 1731 | return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...); |
| 1732 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1733 | |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1734 | template <class... _Args> |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1735 | iterator emplace_hint(const_iterator __p, _Args&&... __args) { |
| 1736 | return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...); |
| 1737 | } |
| 1738 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1739 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1740 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1741 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1742 | iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1743 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 488025c | 2015-05-10 13:35:00 +0000 | [diff] [blame] | 1744 | iterator erase(iterator __p) {return __table_.erase(__p.__i_);} |
| 1745 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1746 | size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1747 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1748 | iterator erase(const_iterator __first, const_iterator __last) |
| 1749 | {return __table_.erase(__first.__i_, __last.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1750 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1751 | void clear() _NOEXCEPT {__table_.clear();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1752 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1753 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1754 | void swap(unordered_multimap& __u) |
| 1755 | _NOEXCEPT_(__is_nothrow_swappable<__table>::value) |
| 1756 | {__table_.swap(__u.__table_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1757 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1758 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1759 | hasher hash_function() const |
| 1760 | {return __table_.hash_function().hash_function();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1761 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1762 | key_equal key_eq() const |
| 1763 | {return __table_.key_eq().key_eq();} |
| 1764 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1765 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1766 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1767 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1768 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1769 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1770 | size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1771 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1772 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 1773 | {return __table_.__equal_range_multi(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1774 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1775 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 1776 | {return __table_.__equal_range_multi(__k);} |
| 1777 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1778 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1779 | size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1780 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1781 | size_type max_bucket_count() const _NOEXCEPT |
| 1782 | {return __table_.max_bucket_count();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1783 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1784 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1785 | size_type bucket_size(size_type __n) const |
| 1786 | {return __table_.bucket_size(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1787 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1788 | size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} |
| 1789 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1790 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1791 | local_iterator begin(size_type __n) {return __table_.begin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1793 | local_iterator end(size_type __n) {return __table_.end(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1794 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1795 | const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1796 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1797 | const_local_iterator end(size_type __n) const {return __table_.cend(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1799 | const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1800 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1801 | const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} |
| 1802 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1803 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1804 | float load_factor() const _NOEXCEPT {return __table_.load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1805 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1806 | float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1807 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1808 | void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1809 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1810 | void rehash(size_type __n) {__table_.rehash(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1811 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1812 | void reserve(size_type __n) {__table_.reserve(__n);} |
| 1813 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1814 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1815 | |
| 1816 | bool __dereferenceable(const const_iterator* __i) const |
| 1817 | {return __table_.__dereferenceable(&__i->__i_);} |
| 1818 | bool __decrementable(const const_iterator* __i) const |
| 1819 | {return __table_.__decrementable(&__i->__i_);} |
| 1820 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const |
| 1821 | {return __table_.__addable(&__i->__i_, __n);} |
| 1822 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 1823 | {return __table_.__addable(&__i->__i_, __n);} |
| 1824 | |
| 1825 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 1826 | |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1827 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1828 | }; |
| 1829 | |
| 1830 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1831 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1832 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 1833 | : __table_(__hf, __eql) |
| 1834 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1835 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1836 | __get_db()->__insert_c(this); |
| 1837 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1838 | __table_.rehash(__n); |
| 1839 | } |
| 1840 | |
| 1841 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1842 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1843 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 1844 | const allocator_type& __a) |
| 1845 | : __table_(__hf, __eql, __a) |
| 1846 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1847 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1848 | __get_db()->__insert_c(this); |
| 1849 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1850 | __table_.rehash(__n); |
| 1851 | } |
| 1852 | |
| 1853 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1854 | template <class _InputIterator> |
| 1855 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1856 | _InputIterator __first, _InputIterator __last) |
| 1857 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1858 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1859 | __get_db()->__insert_c(this); |
| 1860 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1861 | insert(__first, __last); |
| 1862 | } |
| 1863 | |
| 1864 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1865 | template <class _InputIterator> |
| 1866 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1867 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1868 | const hasher& __hf, const key_equal& __eql) |
| 1869 | : __table_(__hf, __eql) |
| 1870 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1871 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1872 | __get_db()->__insert_c(this); |
| 1873 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1874 | __table_.rehash(__n); |
| 1875 | insert(__first, __last); |
| 1876 | } |
| 1877 | |
| 1878 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1879 | template <class _InputIterator> |
| 1880 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1881 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1882 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 1883 | : __table_(__hf, __eql, __a) |
| 1884 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1885 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1886 | __get_db()->__insert_c(this); |
| 1887 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1888 | __table_.rehash(__n); |
| 1889 | insert(__first, __last); |
| 1890 | } |
| 1891 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1892 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1893 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1894 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1895 | const allocator_type& __a) |
| 1896 | : __table_(__a) |
| 1897 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1898 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1899 | __get_db()->__insert_c(this); |
| 1900 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1904 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1905 | const unordered_multimap& __u) |
| 1906 | : __table_(__u.__table_) |
| 1907 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1908 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1909 | __get_db()->__insert_c(this); |
| 1910 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1911 | __table_.rehash(__u.bucket_count()); |
| 1912 | insert(__u.begin(), __u.end()); |
| 1913 | } |
| 1914 | |
| 1915 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1916 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1917 | const unordered_multimap& __u, const allocator_type& __a) |
| 1918 | : __table_(__u.__table_, __a) |
| 1919 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1920 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1921 | __get_db()->__insert_c(this); |
| 1922 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1923 | __table_.rehash(__u.bucket_count()); |
| 1924 | insert(__u.begin(), __u.end()); |
| 1925 | } |
| 1926 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1927 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1928 | |
| 1929 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1930 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1931 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1932 | unordered_multimap&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1933 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1934 | : __table_(_VSTD::move(__u.__table_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1935 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1936 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1937 | __get_db()->__insert_c(this); |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 1938 | __get_db()->swap(this, &__u); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1939 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1943 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1944 | unordered_multimap&& __u, const allocator_type& __a) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1945 | : __table_(_VSTD::move(__u.__table_), __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1946 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1947 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1948 | __get_db()->__insert_c(this); |
| 1949 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1950 | if (__a != __u.get_allocator()) |
| 1951 | { |
| 1952 | iterator __i = __u.begin(); |
| 1953 | while (__u.size() != 0) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1954 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1955 | __table_.__insert_multi( |
Eric Fiselier | 2960ae2 | 2016-02-11 11:59:44 +0000 | [diff] [blame] | 1956 | _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_.__nc) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1957 | ); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1958 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1959 | } |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 1960 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1961 | else |
| 1962 | __get_db()->swap(this, &__u); |
| 1963 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1966 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1967 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1968 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1969 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1970 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1971 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1972 | initializer_list<value_type> __il) |
| 1973 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1974 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1975 | __get_db()->__insert_c(this); |
| 1976 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1977 | insert(__il.begin(), __il.end()); |
| 1978 | } |
| 1979 | |
| 1980 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1981 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1982 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1983 | const key_equal& __eql) |
| 1984 | : __table_(__hf, __eql) |
| 1985 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1986 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1987 | __get_db()->__insert_c(this); |
| 1988 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1989 | __table_.rehash(__n); |
| 1990 | insert(__il.begin(), __il.end()); |
| 1991 | } |
| 1992 | |
| 1993 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1994 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1995 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1996 | const key_equal& __eql, const allocator_type& __a) |
| 1997 | : __table_(__hf, __eql, __a) |
| 1998 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1999 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2000 | __get_db()->__insert_c(this); |
| 2001 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2002 | __table_.rehash(__n); |
| 2003 | insert(__il.begin(), __il.end()); |
| 2004 | } |
| 2005 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2006 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2007 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2008 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2009 | |
| 2010 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2011 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2012 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 2013 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2014 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2015 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2016 | __table_ = _VSTD::move(__u.__table_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2017 | return *this; |
| 2018 | } |
| 2019 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2020 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2021 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2022 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2023 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2024 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2025 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2026 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 2027 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( |
| 2028 | initializer_list<value_type> __il) |
| 2029 | { |
| 2030 | __table_.__assign_multi(__il.begin(), __il.end()); |
| 2031 | return *this; |
| 2032 | } |
| 2033 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2034 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2035 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2036 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2037 | |
| 2038 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2039 | template <class _InputIterator> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2040 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2041 | void |
| 2042 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 2043 | _InputIterator __last) |
| 2044 | { |
| 2045 | for (; __first != __last; ++__first) |
| 2046 | __table_.__insert_multi(*__first); |
| 2047 | } |
| 2048 | |
| 2049 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2050 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2051 | void |
| 2052 | swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 2053 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2054 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2055 | { |
| 2056 | __x.swap(__y); |
| 2057 | } |
| 2058 | |
| 2059 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2060 | bool |
| 2061 | operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 2062 | const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 2063 | { |
| 2064 | if (__x.size() != __y.size()) |
| 2065 | return false; |
| 2066 | typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 2067 | const_iterator; |
| 2068 | typedef pair<const_iterator, const_iterator> _EqRng; |
| 2069 | for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) |
| 2070 | { |
| 2071 | _EqRng __xeq = __x.equal_range(__i->first); |
| 2072 | _EqRng __yeq = __y.equal_range(__i->first); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2073 | if (_VSTD::distance(__xeq.first, __xeq.second) != |
| 2074 | _VSTD::distance(__yeq.first, __yeq.second) || |
| 2075 | !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | return false; |
| 2077 | __i = __xeq.second; |
| 2078 | } |
| 2079 | return true; |
| 2080 | } |
| 2081 | |
| 2082 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2083 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2084 | bool |
| 2085 | operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 2086 | const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 2087 | { |
| 2088 | return !(__x == __y); |
| 2089 | } |
| 2090 | |
| 2091 | _LIBCPP_END_NAMESPACE_STD |
| 2092 | |
| 2093 | #endif // _LIBCPP_UNORDERED_MAP |