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