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> |
| 372 | |
Eric Fiselier | b953610 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 373 | #include <__debug> |
| 374 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 375 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 376 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 377 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 378 | |
| 379 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 380 | |
Eric Fiselier | 3a0e430 | 2015-06-13 07:08:02 +0000 | [diff] [blame] | 381 | template <class _Key, class _Cp, class _Hash, |
| 382 | bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value |
Howard Hinnant | d4cf215 | 2011-12-11 20:31:33 +0000 | [diff] [blame] | 383 | > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | class __unordered_map_hasher |
| 385 | : private _Hash |
| 386 | { |
| 387 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 388 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 389 | __unordered_map_hasher() |
| 390 | _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) |
| 391 | : _Hash() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 392 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 393 | __unordered_map_hasher(const _Hash& __h) |
| 394 | _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) |
| 395 | : _Hash(__h) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 396 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 397 | const _Hash& hash_function() const _NOEXCEPT {return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 398 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 399 | size_t operator()(const _Cp& __x) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 400 | {return static_cast<const _Hash&>(*this)(__x.__cc.first);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 401 | _LIBCPP_INLINE_VISIBILITY |
| 402 | size_t operator()(const _Key& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 403 | {return static_cast<const _Hash&>(*this)(__x);} |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 404 | void swap(__unordered_map_hasher&__y) |
| 405 | _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) |
| 406 | { |
| 407 | using _VSTD::swap; |
| 408 | swap(static_cast<const _Hash&>(*this), static_cast<const _Hash&>(__y)); |
| 409 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | }; |
| 411 | |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 412 | template <class _Key, class _Cp, class _Hash> |
| 413 | class __unordered_map_hasher<_Key, _Cp, _Hash, false> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 414 | { |
| 415 | _Hash __hash_; |
| 416 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 417 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 418 | __unordered_map_hasher() |
| 419 | _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) |
| 420 | : __hash_() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 421 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 422 | __unordered_map_hasher(const _Hash& __h) |
| 423 | _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) |
| 424 | : __hash_(__h) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 425 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 426 | const _Hash& hash_function() const _NOEXCEPT {return __hash_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 427 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 428 | size_t operator()(const _Cp& __x) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 429 | {return __hash_(__x.__cc.first);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 430 | _LIBCPP_INLINE_VISIBILITY |
| 431 | size_t operator()(const _Key& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 432 | {return __hash_(__x);} |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 433 | void swap(__unordered_map_hasher&__y) |
| 434 | _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) |
| 435 | { |
| 436 | using _VSTD::swap; |
| 437 | swap(__hash_, __y.__hash_); |
| 438 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 439 | }; |
| 440 | |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 441 | template <class _Key, class _Cp, class _Hash, bool __b> |
| 442 | inline _LIBCPP_INLINE_VISIBILITY |
| 443 | void |
| 444 | swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x, |
| 445 | __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y) |
| 446 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
| 447 | { |
| 448 | __x.swap(__y); |
| 449 | } |
| 450 | |
Eric Fiselier | 3a0e430 | 2015-06-13 07:08:02 +0000 | [diff] [blame] | 451 | template <class _Key, class _Cp, class _Pred, |
| 452 | bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value |
Howard Hinnant | d4cf215 | 2011-12-11 20:31:33 +0000 | [diff] [blame] | 453 | > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 454 | class __unordered_map_equal |
| 455 | : private _Pred |
| 456 | { |
| 457 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 458 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 459 | __unordered_map_equal() |
| 460 | _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) |
| 461 | : _Pred() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 462 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 463 | __unordered_map_equal(const _Pred& __p) |
| 464 | _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) |
| 465 | : _Pred(__p) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 466 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 467 | const _Pred& key_eq() const _NOEXCEPT {return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 468 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 469 | bool operator()(const _Cp& __x, const _Cp& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 470 | {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 471 | _LIBCPP_INLINE_VISIBILITY |
| 472 | bool operator()(const _Cp& __x, const _Key& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 473 | {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 474 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 475 | bool operator()(const _Key& __x, const _Cp& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 476 | {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);} |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 477 | void swap(__unordered_map_equal&__y) |
| 478 | _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) |
| 479 | { |
| 480 | using _VSTD::swap; |
| 481 | swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y)); |
| 482 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 483 | }; |
| 484 | |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 485 | template <class _Key, class _Cp, class _Pred> |
| 486 | class __unordered_map_equal<_Key, _Cp, _Pred, false> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 487 | { |
| 488 | _Pred __pred_; |
| 489 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 490 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 491 | __unordered_map_equal() |
| 492 | _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) |
| 493 | : __pred_() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 494 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 495 | __unordered_map_equal(const _Pred& __p) |
| 496 | _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) |
| 497 | : __pred_(__p) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 498 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 499 | const _Pred& key_eq() const _NOEXCEPT {return __pred_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 500 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 501 | bool operator()(const _Cp& __x, const _Cp& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 502 | {return __pred_(__x.__cc.first, __y.__cc.first);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 503 | _LIBCPP_INLINE_VISIBILITY |
| 504 | bool operator()(const _Cp& __x, const _Key& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 505 | {return __pred_(__x.__cc.first, __y);} |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 506 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8880d0 | 2011-12-12 17:26:24 +0000 | [diff] [blame] | 507 | bool operator()(const _Key& __x, const _Cp& __y) const |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 508 | {return __pred_(__x, __y.__cc.first);} |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 509 | void swap(__unordered_map_equal&__y) |
| 510 | _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) |
| 511 | { |
| 512 | using _VSTD::swap; |
| 513 | swap(__pred_, __y.__pred_); |
| 514 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | }; |
| 516 | |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 517 | template <class _Key, class _Cp, class _Pred, bool __b> |
| 518 | inline _LIBCPP_INLINE_VISIBILITY |
| 519 | void |
| 520 | swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x, |
| 521 | __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y) |
| 522 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
| 523 | { |
| 524 | __x.swap(__y); |
| 525 | } |
| 526 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 527 | template <class _Alloc> |
| 528 | class __hash_map_node_destructor |
| 529 | { |
| 530 | typedef _Alloc allocator_type; |
| 531 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 532 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | public: |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 534 | |
| 535 | typedef typename __alloc_traits::pointer pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 536 | private: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 537 | |
| 538 | allocator_type& __na_; |
| 539 | |
| 540 | __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); |
| 541 | |
| 542 | public: |
| 543 | bool __first_constructed; |
| 544 | bool __second_constructed; |
| 545 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 546 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 547 | explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 548 | : __na_(__na), |
| 549 | __first_constructed(false), |
| 550 | __second_constructed(false) |
| 551 | {} |
| 552 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 553 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 554 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 555 | __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 556 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | : __na_(__x.__na_), |
| 558 | __first_constructed(__x.__value_constructed), |
| 559 | __second_constructed(__x.__value_constructed) |
| 560 | { |
| 561 | __x.__value_constructed = false; |
| 562 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 563 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 564 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 565 | __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) |
| 566 | : __na_(__x.__na_), |
| 567 | __first_constructed(__x.__value_constructed), |
| 568 | __second_constructed(__x.__value_constructed) |
| 569 | { |
| 570 | const_cast<bool&>(__x.__value_constructed) = false; |
| 571 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 572 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 573 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 575 | void operator()(pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 576 | { |
| 577 | if (__second_constructed) |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 578 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 579 | if (__first_constructed) |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 580 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | if (__p) |
| 582 | __alloc_traits::deallocate(__na_, __p, 1); |
| 583 | } |
| 584 | }; |
| 585 | |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 586 | #if __cplusplus >= 201103L |
| 587 | |
| 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 | |
| 599 | template <class ..._Args> |
| 600 | _LIBCPP_INLINE_VISIBILITY |
| 601 | __hash_value_type(_Args&& ...__args) |
| 602 | : __cc(std::forward<_Args>(__args)...) {} |
| 603 | |
| 604 | _LIBCPP_INLINE_VISIBILITY |
| 605 | __hash_value_type(const __hash_value_type& __v) |
| 606 | : __cc(__v.__cc) {} |
| 607 | |
| 608 | _LIBCPP_INLINE_VISIBILITY |
| 609 | __hash_value_type(__hash_value_type&& __v) |
Marshall Clow | cd13782 | 2015-05-06 12:11:22 +0000 | [diff] [blame] | 610 | : __nc(_VSTD::move(__v.__nc)) {} |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 611 | |
| 612 | _LIBCPP_INLINE_VISIBILITY |
| 613 | __hash_value_type& operator=(const __hash_value_type& __v) |
| 614 | {__nc = __v.__cc; return *this;} |
| 615 | |
| 616 | _LIBCPP_INLINE_VISIBILITY |
| 617 | __hash_value_type& operator=(__hash_value_type&& __v) |
Marshall Clow | cd13782 | 2015-05-06 12:11:22 +0000 | [diff] [blame] | 618 | {__nc = _VSTD::move(__v.__nc); return *this;} |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 619 | |
| 620 | _LIBCPP_INLINE_VISIBILITY |
| 621 | ~__hash_value_type() {__cc.~value_type();} |
| 622 | }; |
| 623 | |
| 624 | #else |
| 625 | |
| 626 | template <class _Key, class _Tp> |
| 627 | struct __hash_value_type |
| 628 | { |
| 629 | typedef _Key key_type; |
| 630 | typedef _Tp mapped_type; |
| 631 | typedef pair<const key_type, mapped_type> value_type; |
| 632 | |
| 633 | value_type __cc; |
| 634 | |
| 635 | _LIBCPP_INLINE_VISIBILITY |
| 636 | __hash_value_type() {} |
| 637 | |
| 638 | template <class _A0> |
| 639 | _LIBCPP_INLINE_VISIBILITY |
| 640 | __hash_value_type(const _A0& __a0) |
| 641 | : __cc(__a0) {} |
| 642 | |
| 643 | template <class _A0, class _A1> |
| 644 | _LIBCPP_INLINE_VISIBILITY |
| 645 | __hash_value_type(const _A0& __a0, const _A1& __a1) |
| 646 | : __cc(__a0, __a1) {} |
| 647 | }; |
| 648 | |
| 649 | #endif |
| 650 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 651 | template <class _HashIterator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 652 | class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 653 | { |
| 654 | _HashIterator __i_; |
| 655 | |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 656 | typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes; |
| 657 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | public: |
| 659 | typedef forward_iterator_tag iterator_category; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 660 | typedef typename _NodeTypes::__map_value_type value_type; |
| 661 | typedef typename _NodeTypes::difference_type difference_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | typedef value_type& reference; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 663 | typedef typename _NodeTypes::__map_value_type_pointer pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 664 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 665 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 666 | __hash_map_iterator() _NOEXCEPT {} |
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 | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 669 | __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 670 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 671 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 672 | reference operator*() const {return __i_->__cc;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 673 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 674 | pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 675 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 676 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 677 | __hash_map_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 678 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 679 | __hash_map_iterator operator++(int) |
| 680 | { |
| 681 | __hash_map_iterator __t(*this); |
| 682 | ++(*this); |
| 683 | return __t; |
| 684 | } |
| 685 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 686 | friend _LIBCPP_INLINE_VISIBILITY |
| 687 | bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 688 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 689 | friend _LIBCPP_INLINE_VISIBILITY |
| 690 | bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 691 | {return __x.__i_ != __y.__i_;} |
| 692 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 693 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; |
| 694 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; |
| 695 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; |
| 696 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; |
| 697 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 698 | }; |
| 699 | |
| 700 | template <class _HashIterator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 701 | class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 702 | { |
| 703 | _HashIterator __i_; |
| 704 | |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 705 | typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes; |
| 706 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 707 | public: |
| 708 | typedef forward_iterator_tag iterator_category; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 709 | typedef typename _NodeTypes::__map_value_type value_type; |
| 710 | typedef typename _NodeTypes::difference_type difference_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 711 | typedef const value_type& reference; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 712 | typedef typename _NodeTypes::__const_map_value_type_pointer pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 713 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 714 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 715 | __hash_map_const_iterator() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 716 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 717 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 718 | __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 719 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 720 | __hash_map_const_iterator( |
| 721 | __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 722 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 | : __i_(__i.__i_) {} |
| 724 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 725 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 726 | reference operator*() const {return __i_->__cc;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 727 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 728 | pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 729 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 730 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 731 | __hash_map_const_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 732 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 733 | __hash_map_const_iterator operator++(int) |
| 734 | { |
| 735 | __hash_map_const_iterator __t(*this); |
| 736 | ++(*this); |
| 737 | return __t; |
| 738 | } |
| 739 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 740 | friend _LIBCPP_INLINE_VISIBILITY |
| 741 | 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] | 742 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 743 | friend _LIBCPP_INLINE_VISIBILITY |
| 744 | 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] | 745 | {return __x.__i_ != __y.__i_;} |
| 746 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 747 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map; |
| 748 | template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap; |
| 749 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator; |
| 750 | template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 751 | }; |
| 752 | |
| 753 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 754 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 755 | class _LIBCPP_TYPE_VIS_ONLY unordered_map |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 756 | { |
| 757 | public: |
| 758 | // types |
| 759 | typedef _Key key_type; |
| 760 | typedef _Tp mapped_type; |
| 761 | typedef _Hash hasher; |
| 762 | typedef _Pred key_equal; |
| 763 | typedef _Alloc allocator_type; |
| 764 | typedef pair<const key_type, mapped_type> value_type; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 765 | typedef pair<key_type, mapped_type> __nc_value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 766 | typedef value_type& reference; |
| 767 | typedef const value_type& const_reference; |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 768 | static_assert((is_same<value_type, typename allocator_type::value_type>::value), |
| 769 | "Invalid allocator::value_type"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 770 | |
| 771 | private: |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 772 | typedef __hash_value_type<key_type, mapped_type> __value_type; |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 773 | typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; |
| 774 | typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 775 | typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, |
| 776 | __value_type>::type __allocator_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 777 | |
| 778 | typedef __hash_table<__value_type, __hasher, |
| 779 | __key_equal, __allocator_type> __table; |
| 780 | |
| 781 | __table __table_; |
| 782 | |
| 783 | typedef typename __table::__node_pointer __node_pointer; |
| 784 | typedef typename __table::__node_const_pointer __node_const_pointer; |
| 785 | typedef typename __table::__node_traits __node_traits; |
| 786 | typedef typename __table::__node_allocator __node_allocator; |
| 787 | typedef typename __table::__node __node; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 788 | typedef __hash_map_node_destructor<__node_allocator> _Dp; |
| 789 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 790 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 791 | public: |
| 792 | typedef typename __alloc_traits::pointer pointer; |
| 793 | typedef typename __alloc_traits::const_pointer const_pointer; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 794 | typedef typename __table::size_type size_type; |
| 795 | typedef typename __table::difference_type difference_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 796 | |
| 797 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 798 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 799 | typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; |
| 800 | typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; |
| 801 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 803 | unordered_map() |
| 804 | _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 805 | { |
| 806 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 807 | __get_db()->__insert_c(this); |
| 808 | #endif |
| 809 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 810 | explicit unordered_map(size_type __n, const hasher& __hf = hasher(), |
| 811 | const key_equal& __eql = key_equal()); |
| 812 | unordered_map(size_type __n, const hasher& __hf, |
| 813 | const key_equal& __eql, |
| 814 | const allocator_type& __a); |
| 815 | template <class _InputIterator> |
| 816 | unordered_map(_InputIterator __first, _InputIterator __last); |
| 817 | template <class _InputIterator> |
| 818 | unordered_map(_InputIterator __first, _InputIterator __last, |
| 819 | size_type __n, const hasher& __hf = hasher(), |
| 820 | const key_equal& __eql = key_equal()); |
| 821 | template <class _InputIterator> |
| 822 | unordered_map(_InputIterator __first, _InputIterator __last, |
| 823 | size_type __n, const hasher& __hf, |
| 824 | const key_equal& __eql, |
| 825 | const allocator_type& __a); |
| 826 | explicit unordered_map(const allocator_type& __a); |
| 827 | unordered_map(const unordered_map& __u); |
| 828 | unordered_map(const unordered_map& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 829 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 830 | unordered_map(unordered_map&& __u) |
| 831 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 832 | unordered_map(unordered_map&& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 833 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 834 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 835 | unordered_map(initializer_list<value_type> __il); |
| 836 | unordered_map(initializer_list<value_type> __il, size_type __n, |
| 837 | const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); |
| 838 | unordered_map(initializer_list<value_type> __il, size_type __n, |
| 839 | const hasher& __hf, const key_equal& __eql, |
| 840 | const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 841 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Marshall Clow | 6dff618 | 2013-09-12 03:00:31 +0000 | [diff] [blame] | 842 | #if _LIBCPP_STD_VER > 11 |
| 843 | _LIBCPP_INLINE_VISIBILITY |
| 844 | unordered_map(size_type __n, const allocator_type& __a) |
| 845 | : unordered_map(__n, hasher(), key_equal(), __a) {} |
| 846 | _LIBCPP_INLINE_VISIBILITY |
| 847 | unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a) |
| 848 | : unordered_map(__n, __hf, key_equal(), __a) {} |
| 849 | template <class _InputIterator> |
| 850 | _LIBCPP_INLINE_VISIBILITY |
| 851 | unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) |
| 852 | : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {} |
| 853 | template <class _InputIterator> |
| 854 | _LIBCPP_INLINE_VISIBILITY |
| 855 | unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, |
| 856 | const allocator_type& __a) |
| 857 | : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {} |
| 858 | _LIBCPP_INLINE_VISIBILITY |
| 859 | unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) |
| 860 | : unordered_map(__il, __n, hasher(), key_equal(), __a) {} |
| 861 | _LIBCPP_INLINE_VISIBILITY |
| 862 | unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 863 | const allocator_type& __a) |
| 864 | : unordered_map(__il, __n, __hf, key_equal(), __a) {} |
| 865 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 866 | // ~unordered_map() = default; |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 867 | _LIBCPP_INLINE_VISIBILITY |
| 868 | unordered_map& operator=(const unordered_map& __u) |
| 869 | { |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 870 | #if __cplusplus >= 201103L |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 871 | __table_ = __u.__table_; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 872 | #else |
Marshall Clow | ebfc50e | 2014-02-08 04:03:14 +0000 | [diff] [blame] | 873 | if (this != &__u) { |
| 874 | __table_.clear(); |
| 875 | __table_.hash_function() = __u.__table_.hash_function(); |
| 876 | __table_.key_eq() = __u.__table_.key_eq(); |
| 877 | __table_.max_load_factor() = __u.__table_.max_load_factor(); |
| 878 | __table_.__copy_assign_alloc(__u.__table_); |
| 879 | insert(__u.begin(), __u.end()); |
| 880 | } |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 881 | #endif |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 882 | return *this; |
| 883 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 884 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 885 | unordered_map& operator=(unordered_map&& __u) |
| 886 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 887 | #endif |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 888 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 889 | unordered_map& operator=(initializer_list<value_type> __il); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 890 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 894 | {return allocator_type(__table_.__node_alloc());} |
| 895 | |
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 | bool empty() const _NOEXCEPT {return __table_.size() == 0;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 898 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 899 | size_type size() const _NOEXCEPT {return __table_.size();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 900 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 901 | size_type max_size() const _NOEXCEPT {return __table_.max_size();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 902 | |
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 | iterator begin() _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 | iterator end() _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 begin() 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 end() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 911 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 912 | const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 913 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 914 | const_iterator cend() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 915 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 916 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 917 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 918 | |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 919 | template <class... _Args> |
Duncan P. N. Exon Smith | 005e38f | 2016-01-23 15:12:47 +0000 | [diff] [blame] | 920 | pair<iterator, bool> emplace(_Args&&... __args); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 921 | |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 922 | template <class... _Args> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 923 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 924 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 925 | iterator emplace_hint(const_iterator __p, _Args&&... __args) |
| 926 | { |
| 927 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 928 | "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not" |
| 929 | " referring to this unordered_map"); |
Duncan P. N. Exon Smith | 005e38f | 2016-01-23 15:12:47 +0000 | [diff] [blame] | 930 | return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 931 | } |
| 932 | #else |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 933 | iterator emplace_hint(const_iterator, _Args&&... __args) |
| 934 | {return emplace(_VSTD::forward<_Args>(__args)...).first;} |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 935 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 936 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 937 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 938 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 939 | pair<iterator, bool> insert(const value_type& __x) |
| 940 | {return __table_.__insert_unique(__x);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 941 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 942 | template <class _Pp, |
| 943 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 944 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 945 | pair<iterator, bool> insert(_Pp&& __x) |
| 946 | {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 947 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 948 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 949 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 950 | iterator insert(const_iterator __p, const value_type& __x) |
| 951 | { |
| 952 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 953 | "unordered_map::insert(const_iterator, const value_type&) called with an iterator not" |
| 954 | " referring to this unordered_map"); |
| 955 | return insert(__x).first; |
| 956 | } |
| 957 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 958 | iterator insert(const_iterator, const value_type& __x) |
| 959 | {return insert(__x).first;} |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 960 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 961 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 962 | template <class _Pp, |
| 963 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 964 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 965 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 966 | iterator insert(const_iterator __p, _Pp&& __x) |
| 967 | { |
| 968 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 969 | "unordered_map::insert(const_iterator, value_type&&) called with an iterator not" |
| 970 | " referring to this unordered_map"); |
| 971 | return insert(_VSTD::forward<_Pp>(__x)).first; |
| 972 | } |
| 973 | #else |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 974 | iterator insert(const_iterator, _Pp&& __x) |
| 975 | {return insert(_VSTD::forward<_Pp>(__x)).first;} |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 976 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 977 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 978 | template <class _InputIterator> |
| 979 | void insert(_InputIterator __first, _InputIterator __last); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 980 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 981 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 982 | void insert(initializer_list<value_type> __il) |
| 983 | {insert(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 984 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
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); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1138 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
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: |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1194 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1195 | __node_holder __construct_node(); |
| 1196 | template <class _A0> |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1197 | __node_holder |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1198 | __construct_node(_A0&& __a0); |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1199 | __node_holder __construct_node_with_key(key_type&& __k); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1200 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1201 | template <class _A0, class _A1, class ..._Args> |
| 1202 | __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1203 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1204 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1205 | __node_holder __construct_node_with_key(const key_type& __k); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1206 | }; |
| 1207 | |
| 1208 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1209 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1210 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 1211 | : __table_(__hf, __eql) |
| 1212 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1213 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1214 | __get_db()->__insert_c(this); |
| 1215 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1216 | __table_.rehash(__n); |
| 1217 | } |
| 1218 | |
| 1219 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1220 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1221 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 1222 | const allocator_type& __a) |
| 1223 | : __table_(__hf, __eql, __a) |
| 1224 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1225 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1226 | __get_db()->__insert_c(this); |
| 1227 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1228 | __table_.rehash(__n); |
| 1229 | } |
| 1230 | |
| 1231 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1232 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1233 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1234 | const allocator_type& __a) |
| 1235 | : __table_(__a) |
| 1236 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1237 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1238 | __get_db()->__insert_c(this); |
| 1239 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1243 | template <class _InputIterator> |
| 1244 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1245 | _InputIterator __first, _InputIterator __last) |
| 1246 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1247 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1248 | __get_db()->__insert_c(this); |
| 1249 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1250 | insert(__first, __last); |
| 1251 | } |
| 1252 | |
| 1253 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1254 | template <class _InputIterator> |
| 1255 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1256 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1257 | const hasher& __hf, const key_equal& __eql) |
| 1258 | : __table_(__hf, __eql) |
| 1259 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1260 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1261 | __get_db()->__insert_c(this); |
| 1262 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1263 | __table_.rehash(__n); |
| 1264 | insert(__first, __last); |
| 1265 | } |
| 1266 | |
| 1267 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1268 | template <class _InputIterator> |
| 1269 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1270 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1271 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 1272 | : __table_(__hf, __eql, __a) |
| 1273 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1274 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1275 | __get_db()->__insert_c(this); |
| 1276 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1277 | __table_.rehash(__n); |
| 1278 | insert(__first, __last); |
| 1279 | } |
| 1280 | |
| 1281 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1282 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1283 | const unordered_map& __u) |
| 1284 | : __table_(__u.__table_) |
| 1285 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1286 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1287 | __get_db()->__insert_c(this); |
| 1288 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1289 | __table_.rehash(__u.bucket_count()); |
| 1290 | insert(__u.begin(), __u.end()); |
| 1291 | } |
| 1292 | |
| 1293 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1294 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1295 | const unordered_map& __u, const allocator_type& __a) |
| 1296 | : __table_(__u.__table_, __a) |
| 1297 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1298 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1299 | __get_db()->__insert_c(this); |
| 1300 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1301 | __table_.rehash(__u.bucket_count()); |
| 1302 | insert(__u.begin(), __u.end()); |
| 1303 | } |
| 1304 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1305 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1306 | |
| 1307 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1308 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1309 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1310 | unordered_map&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1311 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1312 | : __table_(_VSTD::move(__u.__table_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1313 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1314 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1315 | __get_db()->__insert_c(this); |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 1316 | __get_db()->swap(this, &__u); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1317 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1321 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1322 | unordered_map&& __u, const allocator_type& __a) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1323 | : __table_(_VSTD::move(__u.__table_), __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1324 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1325 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1326 | __get_db()->__insert_c(this); |
| 1327 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1328 | if (__a != __u.get_allocator()) |
| 1329 | { |
| 1330 | iterator __i = __u.begin(); |
| 1331 | while (__u.size() != 0) |
| 1332 | __table_.__insert_unique( |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1333 | _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1334 | ); |
| 1335 | } |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 1336 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1337 | else |
| 1338 | __get_db()->swap(this, &__u); |
| 1339 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1342 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1343 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1344 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1345 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1346 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1347 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1348 | initializer_list<value_type> __il) |
| 1349 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1350 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1351 | __get_db()->__insert_c(this); |
| 1352 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1353 | insert(__il.begin(), __il.end()); |
| 1354 | } |
| 1355 | |
| 1356 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1357 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1358 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1359 | const key_equal& __eql) |
| 1360 | : __table_(__hf, __eql) |
| 1361 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1362 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1363 | __get_db()->__insert_c(this); |
| 1364 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1365 | __table_.rehash(__n); |
| 1366 | insert(__il.begin(), __il.end()); |
| 1367 | } |
| 1368 | |
| 1369 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1370 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1371 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1372 | const key_equal& __eql, const allocator_type& __a) |
| 1373 | : __table_(__hf, __eql, __a) |
| 1374 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1375 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1376 | __get_db()->__insert_c(this); |
| 1377 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1378 | __table_.rehash(__n); |
| 1379 | insert(__il.begin(), __il.end()); |
| 1380 | } |
| 1381 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1382 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1383 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1384 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1385 | |
| 1386 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1387 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1388 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1389 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1390 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1391 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1392 | __table_ = _VSTD::move(__u.__table_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1393 | return *this; |
| 1394 | } |
| 1395 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1396 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1397 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1398 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1399 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1400 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1401 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1402 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1403 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( |
| 1404 | initializer_list<value_type> __il) |
| 1405 | { |
| 1406 | __table_.__assign_unique(__il.begin(), __il.end()); |
| 1407 | return *this; |
| 1408 | } |
| 1409 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1410 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1411 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1412 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1413 | |
| 1414 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1415 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1416 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1417 | { |
| 1418 | __node_allocator& __na = __table_.__node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1419 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1420 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1421 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1422 | __h.get_deleter().__second_constructed = true; |
| 1423 | return __h; |
| 1424 | } |
| 1425 | |
| 1426 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1427 | template <class _A0> |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1428 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1429 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) |
| 1430 | { |
| 1431 | __node_allocator& __na = __table_.__node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1432 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1433 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_), |
| 1434 | _VSTD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1435 | __h.get_deleter().__first_constructed = true; |
| 1436 | __h.get_deleter().__second_constructed = true; |
| 1437 | return __h; |
| 1438 | } |
| 1439 | |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1440 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1441 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 1442 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k) |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1443 | { |
| 1444 | __node_allocator& __na = __table_.__node_alloc(); |
| 1445 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1446 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k)); |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1447 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1448 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1449 | __h.get_deleter().__second_constructed = true; |
Howard Hinnant | 9a894d9 | 2013-08-22 18:29:50 +0000 | [diff] [blame] | 1450 | return __h; |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1453 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1454 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1455 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1456 | template <class _A0, class _A1, class ..._Args> |
| 1457 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 1458 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0, |
| 1459 | _A1&& __a1, |
| 1460 | _Args&&... __args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1461 | { |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1462 | __node_allocator& __na = __table_.__node_alloc(); |
| 1463 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
| 1464 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_), |
| 1465 | _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1), |
| 1466 | _VSTD::forward<_Args>(__args)...); |
| 1467 | __h.get_deleter().__first_constructed = true; |
| 1468 | __h.get_deleter().__second_constructed = true; |
| 1469 | return __h; |
| 1470 | } |
| 1471 | |
| 1472 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1473 | template <class... _Args> |
| 1474 | pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool> |
Duncan P. N. Exon Smith | 005e38f | 2016-01-23 15:12:47 +0000 | [diff] [blame] | 1475 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args) |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1476 | { |
| 1477 | __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1478 | pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); |
| 1479 | if (__r.second) |
| 1480 | __h.release(); |
| 1481 | return __r; |
| 1482 | } |
| 1483 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1484 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1485 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1486 | |
| 1487 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1488 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1489 | 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] | 1490 | { |
| 1491 | __node_allocator& __na = __table_.__node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1492 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1493 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1494 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1495 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1496 | __h.get_deleter().__second_constructed = true; |
Dimitry Andric | 8966350 | 2015-08-19 06:43:33 +0000 | [diff] [blame] | 1497 | return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1500 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1501 | template <class _InputIterator> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1502 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1503 | void |
| 1504 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 1505 | _InputIterator __last) |
| 1506 | { |
| 1507 | for (; __first != __last; ++__first) |
| 1508 | __table_.__insert_unique(*__first); |
| 1509 | } |
| 1510 | |
| 1511 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1512 | _Tp& |
| 1513 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) |
| 1514 | { |
| 1515 | iterator __i = find(__k); |
| 1516 | if (__i != end()) |
| 1517 | return __i->second; |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1518 | __node_holder __h = __construct_node_with_key(__k); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1519 | pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); |
| 1520 | __h.release(); |
| 1521 | return __r.first->second; |
| 1522 | } |
| 1523 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1524 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1525 | |
| 1526 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1527 | _Tp& |
| 1528 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k) |
| 1529 | { |
| 1530 | iterator __i = find(__k); |
| 1531 | if (__i != end()) |
| 1532 | return __i->second; |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1533 | __node_holder __h = __construct_node_with_key(_VSTD::move(__k)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1534 | pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); |
| 1535 | __h.release(); |
| 1536 | return __r.first->second; |
| 1537 | } |
| 1538 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1539 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1540 | |
| 1541 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1542 | _Tp& |
| 1543 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) |
| 1544 | { |
| 1545 | iterator __i = find(__k); |
| 1546 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1547 | if (__i == end()) |
| 1548 | throw out_of_range("unordered_map::at: key not found"); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1549 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1550 | return __i->second; |
| 1551 | } |
| 1552 | |
| 1553 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1554 | const _Tp& |
| 1555 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const |
| 1556 | { |
| 1557 | const_iterator __i = find(__k); |
| 1558 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1559 | if (__i == end()) |
| 1560 | throw out_of_range("unordered_map::at: key not found"); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1561 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1562 | return __i->second; |
| 1563 | } |
| 1564 | |
| 1565 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1566 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1567 | void |
| 1568 | swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1569 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1570 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1571 | { |
| 1572 | __x.swap(__y); |
| 1573 | } |
| 1574 | |
| 1575 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1576 | bool |
| 1577 | operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1578 | const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1579 | { |
| 1580 | if (__x.size() != __y.size()) |
| 1581 | return false; |
| 1582 | typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 1583 | const_iterator; |
| 1584 | for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); |
| 1585 | __i != __ex; ++__i) |
| 1586 | { |
| 1587 | const_iterator __j = __y.find(__i->first); |
| 1588 | if (__j == __ey || !(*__i == *__j)) |
| 1589 | return false; |
| 1590 | } |
| 1591 | return true; |
| 1592 | } |
| 1593 | |
| 1594 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1595 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1596 | bool |
| 1597 | operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1598 | const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1599 | { |
| 1600 | return !(__x == __y); |
| 1601 | } |
| 1602 | |
| 1603 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 1604 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1605 | class _LIBCPP_TYPE_VIS_ONLY unordered_multimap |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1606 | { |
| 1607 | public: |
| 1608 | // types |
| 1609 | typedef _Key key_type; |
| 1610 | typedef _Tp mapped_type; |
| 1611 | typedef _Hash hasher; |
| 1612 | typedef _Pred key_equal; |
| 1613 | typedef _Alloc allocator_type; |
| 1614 | typedef pair<const key_type, mapped_type> value_type; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1615 | typedef pair<key_type, mapped_type> __nc_value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1616 | typedef value_type& reference; |
| 1617 | typedef const value_type& const_reference; |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1618 | static_assert((is_same<value_type, typename allocator_type::value_type>::value), |
| 1619 | "Invalid allocator::value_type"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1620 | |
| 1621 | private: |
Howard Hinnant | ff7546e | 2013-09-30 19:08:22 +0000 | [diff] [blame] | 1622 | typedef __hash_value_type<key_type, mapped_type> __value_type; |
Howard Hinnant | 9b128e0 | 2013-07-05 18:06:00 +0000 | [diff] [blame] | 1623 | typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; |
| 1624 | typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1625 | typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, |
| 1626 | __value_type>::type __allocator_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1627 | |
| 1628 | typedef __hash_table<__value_type, __hasher, |
| 1629 | __key_equal, __allocator_type> __table; |
| 1630 | |
| 1631 | __table __table_; |
| 1632 | |
| 1633 | typedef typename __table::__node_traits __node_traits; |
| 1634 | typedef typename __table::__node_allocator __node_allocator; |
| 1635 | typedef typename __table::__node __node; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1636 | typedef __hash_map_node_destructor<__node_allocator> _Dp; |
| 1637 | typedef unique_ptr<__node, _Dp> __node_holder; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1638 | typedef allocator_traits<allocator_type> __alloc_traits; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 1639 | static_assert((is_same<typename __node_traits::size_type, |
| 1640 | typename __alloc_traits::size_type>::value), |
| 1641 | "Allocator uses different size_type for different types"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1642 | public: |
| 1643 | typedef typename __alloc_traits::pointer pointer; |
| 1644 | typedef typename __alloc_traits::const_pointer const_pointer; |
Eric Fiselier | 774c7c5 | 2016-02-10 20:46:23 +0000 | [diff] [blame] | 1645 | typedef typename __table::size_type size_type; |
| 1646 | typedef typename __table::difference_type difference_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1647 | |
| 1648 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 1649 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 1650 | typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; |
| 1651 | typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; |
| 1652 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1653 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1654 | unordered_multimap() |
| 1655 | _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1656 | { |
| 1657 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1658 | __get_db()->__insert_c(this); |
| 1659 | #endif |
| 1660 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1661 | explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(), |
| 1662 | const key_equal& __eql = key_equal()); |
| 1663 | unordered_multimap(size_type __n, const hasher& __hf, |
| 1664 | const key_equal& __eql, |
| 1665 | const allocator_type& __a); |
| 1666 | template <class _InputIterator> |
| 1667 | unordered_multimap(_InputIterator __first, _InputIterator __last); |
| 1668 | template <class _InputIterator> |
| 1669 | unordered_multimap(_InputIterator __first, _InputIterator __last, |
| 1670 | size_type __n, const hasher& __hf = hasher(), |
| 1671 | const key_equal& __eql = key_equal()); |
| 1672 | template <class _InputIterator> |
| 1673 | unordered_multimap(_InputIterator __first, _InputIterator __last, |
| 1674 | size_type __n, const hasher& __hf, |
| 1675 | const key_equal& __eql, |
| 1676 | const allocator_type& __a); |
| 1677 | explicit unordered_multimap(const allocator_type& __a); |
| 1678 | unordered_multimap(const unordered_multimap& __u); |
| 1679 | unordered_multimap(const unordered_multimap& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1680 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1681 | unordered_multimap(unordered_multimap&& __u) |
| 1682 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1683 | unordered_multimap(unordered_multimap&& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1684 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1685 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1686 | unordered_multimap(initializer_list<value_type> __il); |
| 1687 | unordered_multimap(initializer_list<value_type> __il, size_type __n, |
| 1688 | const hasher& __hf = hasher(), |
| 1689 | const key_equal& __eql = key_equal()); |
| 1690 | unordered_multimap(initializer_list<value_type> __il, size_type __n, |
| 1691 | const hasher& __hf, const key_equal& __eql, |
| 1692 | const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1693 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Marshall Clow | 6dff618 | 2013-09-12 03:00:31 +0000 | [diff] [blame] | 1694 | #if _LIBCPP_STD_VER > 11 |
| 1695 | _LIBCPP_INLINE_VISIBILITY |
| 1696 | unordered_multimap(size_type __n, const allocator_type& __a) |
| 1697 | : unordered_multimap(__n, hasher(), key_equal(), __a) {} |
| 1698 | _LIBCPP_INLINE_VISIBILITY |
| 1699 | unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a) |
| 1700 | : unordered_multimap(__n, __hf, key_equal(), __a) {} |
| 1701 | template <class _InputIterator> |
| 1702 | _LIBCPP_INLINE_VISIBILITY |
| 1703 | unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) |
| 1704 | : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {} |
| 1705 | template <class _InputIterator> |
| 1706 | _LIBCPP_INLINE_VISIBILITY |
| 1707 | unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, |
| 1708 | const allocator_type& __a) |
| 1709 | : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {} |
| 1710 | _LIBCPP_INLINE_VISIBILITY |
| 1711 | unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) |
| 1712 | : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {} |
| 1713 | _LIBCPP_INLINE_VISIBILITY |
| 1714 | unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1715 | const allocator_type& __a) |
| 1716 | : unordered_multimap(__il, __n, __hf, key_equal(), __a) {} |
| 1717 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1718 | // ~unordered_multimap() = default; |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1719 | _LIBCPP_INLINE_VISIBILITY |
| 1720 | unordered_multimap& operator=(const unordered_multimap& __u) |
| 1721 | { |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1722 | #if __cplusplus >= 201103L |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1723 | __table_ = __u.__table_; |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1724 | #else |
Marshall Clow | ebfc50e | 2014-02-08 04:03:14 +0000 | [diff] [blame] | 1725 | if (this != &__u) { |
| 1726 | __table_.clear(); |
| 1727 | __table_.hash_function() = __u.__table_.hash_function(); |
| 1728 | __table_.key_eq() = __u.__table_.key_eq(); |
| 1729 | __table_.max_load_factor() = __u.__table_.max_load_factor(); |
| 1730 | __table_.__copy_assign_alloc(__u.__table_); |
| 1731 | insert(__u.begin(), __u.end()); |
| 1732 | } |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 1733 | #endif |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 1734 | return *this; |
| 1735 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1736 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1737 | unordered_multimap& operator=(unordered_multimap&& __u) |
| 1738 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1739 | #endif |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1740 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1741 | unordered_multimap& operator=(initializer_list<value_type> __il); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1742 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1743 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1744 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1745 | allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1746 | {return allocator_type(__table_.__node_alloc());} |
| 1747 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1748 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1749 | bool empty() const _NOEXCEPT {return __table_.size() == 0;} |
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 | size_type size() const _NOEXCEPT {return __table_.size();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1752 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1753 | size_type max_size() const _NOEXCEPT {return __table_.max_size();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1754 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1755 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1756 | iterator begin() _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1757 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1758 | iterator end() _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1759 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1760 | const_iterator begin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1761 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1762 | const_iterator end() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1763 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1764 | const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1765 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1766 | const_iterator cend() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1767 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1768 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1769 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1770 | |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1771 | template <class... _Args> |
| 1772 | iterator emplace(_Args&&... __args); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1773 | |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1774 | template <class... _Args> |
| 1775 | iterator emplace_hint(const_iterator __p, _Args&&... __args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1776 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1777 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1778 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1779 | iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1780 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1781 | template <class _Pp, |
| 1782 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1784 | iterator insert(_Pp&& __x) |
| 1785 | {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1786 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
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 | iterator insert(const_iterator __p, const value_type& __x) |
| 1789 | {return __table_.__insert_multi(__p.__i_, __x);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1790 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1791 | template <class _Pp, |
| 1792 | class = typename enable_if<is_constructible<value_type, _Pp>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1793 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1794 | iterator insert(const_iterator __p, _Pp&& __x) |
| 1795 | {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1796 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1797 | template <class _InputIterator> |
| 1798 | void insert(_InputIterator __first, _InputIterator __last); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1799 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
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 | void insert(initializer_list<value_type> __il) |
| 1802 | {insert(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1803 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1804 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1805 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1806 | iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1807 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 488025c | 2015-05-10 13:35:00 +0000 | [diff] [blame] | 1808 | iterator erase(iterator __p) {return __table_.erase(__p.__i_);} |
| 1809 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1810 | size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} |
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 | iterator erase(const_iterator __first, const_iterator __last) |
| 1813 | {return __table_.erase(__first.__i_, __last.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1814 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1815 | void clear() _NOEXCEPT {__table_.clear();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1816 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1817 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1818 | void swap(unordered_multimap& __u) |
| 1819 | _NOEXCEPT_(__is_nothrow_swappable<__table>::value) |
| 1820 | {__table_.swap(__u.__table_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1821 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1822 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1823 | hasher hash_function() const |
| 1824 | {return __table_.hash_function().hash_function();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1825 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1826 | key_equal key_eq() const |
| 1827 | {return __table_.key_eq().key_eq();} |
| 1828 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1829 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1830 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1831 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1832 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1833 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1834 | 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] | 1835 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1836 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 1837 | {return __table_.__equal_range_multi(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1838 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1839 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 1840 | {return __table_.__equal_range_multi(__k);} |
| 1841 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1842 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1843 | size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1844 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1845 | size_type max_bucket_count() const _NOEXCEPT |
| 1846 | {return __table_.max_bucket_count();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1847 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1848 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1849 | size_type bucket_size(size_type __n) const |
| 1850 | {return __table_.bucket_size(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1851 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1852 | size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} |
| 1853 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1854 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1855 | local_iterator begin(size_type __n) {return __table_.begin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1857 | local_iterator end(size_type __n) {return __table_.end(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1858 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1859 | const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1860 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1861 | const_local_iterator end(size_type __n) const {return __table_.cend(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1862 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1863 | const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1864 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} |
| 1866 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1867 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1868 | float load_factor() const _NOEXCEPT {return __table_.load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1869 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1870 | float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1871 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1872 | void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1873 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1874 | void rehash(size_type __n) {__table_.rehash(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1875 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1876 | void reserve(size_type __n) {__table_.reserve(__n);} |
| 1877 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1878 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1879 | |
| 1880 | bool __dereferenceable(const const_iterator* __i) const |
| 1881 | {return __table_.__dereferenceable(&__i->__i_);} |
| 1882 | bool __decrementable(const const_iterator* __i) const |
| 1883 | {return __table_.__decrementable(&__i->__i_);} |
| 1884 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const |
| 1885 | {return __table_.__addable(&__i->__i_, __n);} |
| 1886 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 1887 | {return __table_.__addable(&__i->__i_, __n);} |
| 1888 | |
| 1889 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 1890 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1891 | private: |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1892 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1893 | __node_holder __construct_node(); |
| 1894 | template <class _A0> |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 1895 | __node_holder |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 1896 | __construct_node(_A0&& __a0); |
| 1897 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1898 | template <class _A0, class _A1, class ..._Args> |
| 1899 | __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args); |
| 1900 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1901 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1902 | }; |
| 1903 | |
| 1904 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1905 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1906 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 1907 | : __table_(__hf, __eql) |
| 1908 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1909 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1910 | __get_db()->__insert_c(this); |
| 1911 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1912 | __table_.rehash(__n); |
| 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 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 1918 | const allocator_type& __a) |
| 1919 | : __table_(__hf, __eql, __a) |
| 1920 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1921 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1922 | __get_db()->__insert_c(this); |
| 1923 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1924 | __table_.rehash(__n); |
| 1925 | } |
| 1926 | |
| 1927 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1928 | template <class _InputIterator> |
| 1929 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1930 | _InputIterator __first, _InputIterator __last) |
| 1931 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1932 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1933 | __get_db()->__insert_c(this); |
| 1934 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1935 | insert(__first, __last); |
| 1936 | } |
| 1937 | |
| 1938 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1939 | template <class _InputIterator> |
| 1940 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1941 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1942 | const hasher& __hf, const key_equal& __eql) |
| 1943 | : __table_(__hf, __eql) |
| 1944 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1945 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1946 | __get_db()->__insert_c(this); |
| 1947 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1948 | __table_.rehash(__n); |
| 1949 | insert(__first, __last); |
| 1950 | } |
| 1951 | |
| 1952 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1953 | template <class _InputIterator> |
| 1954 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1955 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1956 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 1957 | : __table_(__hf, __eql, __a) |
| 1958 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1959 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1960 | __get_db()->__insert_c(this); |
| 1961 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1962 | __table_.rehash(__n); |
| 1963 | insert(__first, __last); |
| 1964 | } |
| 1965 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1966 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1967 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1968 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1969 | const allocator_type& __a) |
| 1970 | : __table_(__a) |
| 1971 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1972 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1973 | __get_db()->__insert_c(this); |
| 1974 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1978 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1979 | const unordered_multimap& __u) |
| 1980 | : __table_(__u.__table_) |
| 1981 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1982 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1983 | __get_db()->__insert_c(this); |
| 1984 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1985 | __table_.rehash(__u.bucket_count()); |
| 1986 | insert(__u.begin(), __u.end()); |
| 1987 | } |
| 1988 | |
| 1989 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1990 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1991 | const unordered_multimap& __u, const allocator_type& __a) |
| 1992 | : __table_(__u.__table_, __a) |
| 1993 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 1994 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1995 | __get_db()->__insert_c(this); |
| 1996 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1997 | __table_.rehash(__u.bucket_count()); |
| 1998 | insert(__u.begin(), __u.end()); |
| 1999 | } |
| 2000 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2001 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2002 | |
| 2003 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2004 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2005 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2006 | unordered_multimap&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2007 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2008 | : __table_(_VSTD::move(__u.__table_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2009 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2010 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2011 | __get_db()->__insert_c(this); |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 2012 | __get_db()->swap(this, &__u); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2013 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2017 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2018 | unordered_multimap&& __u, const allocator_type& __a) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2019 | : __table_(_VSTD::move(__u.__table_), __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2020 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2021 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2022 | __get_db()->__insert_c(this); |
| 2023 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2024 | if (__a != __u.get_allocator()) |
| 2025 | { |
| 2026 | iterator __i = __u.begin(); |
| 2027 | while (__u.size() != 0) |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2028 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2029 | __table_.__insert_multi( |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2030 | _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2031 | ); |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2032 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2033 | } |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 2034 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2035 | else |
| 2036 | __get_db()->swap(this, &__u); |
| 2037 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2040 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2041 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2042 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2043 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2044 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2045 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2046 | initializer_list<value_type> __il) |
| 2047 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2048 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2049 | __get_db()->__insert_c(this); |
| 2050 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2051 | insert(__il.begin(), __il.end()); |
| 2052 | } |
| 2053 | |
| 2054 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2055 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2056 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 2057 | const key_equal& __eql) |
| 2058 | : __table_(__hf, __eql) |
| 2059 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2060 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2061 | __get_db()->__insert_c(this); |
| 2062 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2063 | __table_.rehash(__n); |
| 2064 | insert(__il.begin(), __il.end()); |
| 2065 | } |
| 2066 | |
| 2067 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2068 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 2069 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 2070 | const key_equal& __eql, const allocator_type& __a) |
| 2071 | : __table_(__hf, __eql, __a) |
| 2072 | { |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 2073 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2074 | __get_db()->__insert_c(this); |
| 2075 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | __table_.rehash(__n); |
| 2077 | insert(__il.begin(), __il.end()); |
| 2078 | } |
| 2079 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2080 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2081 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2082 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2083 | |
| 2084 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2085 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2086 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 2087 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2088 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2089 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2090 | __table_ = _VSTD::move(__u.__table_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2091 | return *this; |
| 2092 | } |
| 2093 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2094 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2095 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2096 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2097 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2098 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2099 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2100 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 2101 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( |
| 2102 | initializer_list<value_type> __il) |
| 2103 | { |
| 2104 | __table_.__assign_multi(__il.begin(), __il.end()); |
| 2105 | return *this; |
| 2106 | } |
| 2107 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2108 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2109 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2110 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2111 | |
| 2112 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2113 | typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 2114 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2115 | { |
| 2116 | __node_allocator& __na = __table_.__node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2117 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 2118 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2119 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2120 | __h.get_deleter().__second_constructed = true; |
| 2121 | return __h; |
| 2122 | } |
| 2123 | |
| 2124 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 2125 | template <class _A0> |
Howard Hinnant | b66e1c3 | 2013-07-04 20:59:16 +0000 | [diff] [blame] | 2126 | typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2127 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) |
| 2128 | { |
| 2129 | __node_allocator& __na = __table_.__node_alloc(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2130 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2131 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_), |
| 2132 | _VSTD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2133 | __h.get_deleter().__first_constructed = true; |
| 2134 | __h.get_deleter().__second_constructed = true; |
| 2135 | return __h; |
| 2136 | } |
| 2137 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2138 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 2139 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2140 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 2141 | template <class _A0, class _A1, class ..._Args> |
| 2142 | typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 2143 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node( |
| 2144 | _A0&& __a0, _A1&& __a1, _Args&&... __args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2145 | { |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 2146 | __node_allocator& __na = __table_.__node_alloc(); |
| 2147 | __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); |
| 2148 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_), |
| 2149 | _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1), |
| 2150 | _VSTD::forward<_Args>(__args)...); |
| 2151 | __h.get_deleter().__first_constructed = true; |
| 2152 | __h.get_deleter().__second_constructed = true; |
| 2153 | return __h; |
| 2154 | } |
| 2155 | |
| 2156 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2157 | template <class... _Args> |
| 2158 | typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator |
| 2159 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args) |
| 2160 | { |
| 2161 | __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2162 | iterator __r = __table_.__node_insert_multi(__h.get()); |
| 2163 | __h.release(); |
| 2164 | return __r; |
| 2165 | } |
| 2166 | |
| 2167 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 2168 | template <class... _Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2169 | typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator |
| 2170 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint( |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 2171 | const_iterator __p, _Args&&... __args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2172 | { |
Howard Hinnant | 635ce1d | 2012-05-25 22:04:21 +0000 | [diff] [blame] | 2173 | __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2174 | iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get()); |
| 2175 | __h.release(); |
| 2176 | return __r; |
| 2177 | } |
| 2178 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2179 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 2180 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2181 | |
| 2182 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2183 | template <class _InputIterator> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2184 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2185 | void |
| 2186 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 2187 | _InputIterator __last) |
| 2188 | { |
| 2189 | for (; __first != __last; ++__first) |
| 2190 | __table_.__insert_multi(*__first); |
| 2191 | } |
| 2192 | |
| 2193 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2194 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2195 | void |
| 2196 | swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 2197 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 2198 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2199 | { |
| 2200 | __x.swap(__y); |
| 2201 | } |
| 2202 | |
| 2203 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 2204 | bool |
| 2205 | operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 2206 | const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 2207 | { |
| 2208 | if (__x.size() != __y.size()) |
| 2209 | return false; |
| 2210 | typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 2211 | const_iterator; |
| 2212 | typedef pair<const_iterator, const_iterator> _EqRng; |
| 2213 | for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) |
| 2214 | { |
| 2215 | _EqRng __xeq = __x.equal_range(__i->first); |
| 2216 | _EqRng __yeq = __y.equal_range(__i->first); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2217 | if (_VSTD::distance(__xeq.first, __xeq.second) != |
| 2218 | _VSTD::distance(__yeq.first, __yeq.second) || |
| 2219 | !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2220 | return false; |
| 2221 | __i = __xeq.second; |
| 2222 | } |
| 2223 | return true; |
| 2224 | } |
| 2225 | |
| 2226 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2227 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2228 | bool |
| 2229 | operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 2230 | const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 2231 | { |
| 2232 | return !(__x == __y); |
| 2233 | } |
| 2234 | |
| 2235 | _LIBCPP_END_NAMESPACE_STD |
| 2236 | |
| 2237 | #endif // _LIBCPP_UNORDERED_MAP |