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()); |
| 72 | ~unordered_map(); |
| 73 | unordered_map& operator=(const unordered_map&); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 74 | unordered_map& operator=(unordered_map&&) |
| 75 | noexcept( |
| 76 | allocator_type::propagate_on_container_move_assignment::value && |
| 77 | is_nothrow_move_assignable<allocator_type>::value && |
| 78 | is_nothrow_move_assignable<hasher>::value && |
| 79 | is_nothrow_move_assignable<key_equal>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 | unordered_map& operator=(initializer_list<value_type>); |
| 81 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 82 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 83 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 84 | bool empty() const noexcept; |
| 85 | size_type size() const noexcept; |
| 86 | size_type max_size() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 87 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 88 | iterator begin() noexcept; |
| 89 | iterator end() noexcept; |
| 90 | const_iterator begin() const noexcept; |
| 91 | const_iterator end() const noexcept; |
| 92 | const_iterator cbegin() const noexcept; |
| 93 | const_iterator cend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 94 | |
| 95 | template <class... Args> |
| 96 | pair<iterator, bool> emplace(Args&&... args); |
| 97 | template <class... Args> |
| 98 | iterator emplace_hint(const_iterator position, Args&&... args); |
| 99 | pair<iterator, bool> insert(const value_type& obj); |
| 100 | template <class P> |
| 101 | pair<iterator, bool> insert(P&& obj); |
| 102 | iterator insert(const_iterator hint, const value_type& obj); |
| 103 | template <class P> |
| 104 | iterator insert(const_iterator hint, P&& obj); |
| 105 | template <class InputIterator> |
| 106 | void insert(InputIterator first, InputIterator last); |
| 107 | void insert(initializer_list<value_type>); |
| 108 | |
| 109 | iterator erase(const_iterator position); |
| 110 | size_type erase(const key_type& k); |
| 111 | iterator erase(const_iterator first, const_iterator last); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 112 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 113 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 114 | void swap(unordered_map&) |
| 115 | noexcept( |
| 116 | (!allocator_type::propagate_on_container_swap::value || |
| 117 | __is_nothrow_swappable<allocator_type>::value) && |
| 118 | __is_nothrow_swappable<hasher>::value && |
| 119 | __is_nothrow_swappable<key_equal>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 120 | |
| 121 | hasher hash_function() const; |
| 122 | key_equal key_eq() const; |
| 123 | |
| 124 | iterator find(const key_type& k); |
| 125 | const_iterator find(const key_type& k) const; |
| 126 | size_type count(const key_type& k) const; |
| 127 | pair<iterator, iterator> equal_range(const key_type& k); |
| 128 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 129 | |
| 130 | mapped_type& operator[](const key_type& k); |
| 131 | mapped_type& operator[](key_type&& k); |
| 132 | |
| 133 | mapped_type& at(const key_type& k); |
| 134 | const mapped_type& at(const key_type& k) const; |
| 135 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 136 | size_type bucket_count() const noexcept; |
| 137 | size_type max_bucket_count() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 138 | |
| 139 | size_type bucket_size(size_type n) const; |
| 140 | size_type bucket(const key_type& k) const; |
| 141 | |
| 142 | local_iterator begin(size_type n); |
| 143 | local_iterator end(size_type n); |
| 144 | const_local_iterator begin(size_type n) const; |
| 145 | const_local_iterator end(size_type n) const; |
| 146 | const_local_iterator cbegin(size_type n) const; |
| 147 | const_local_iterator cend(size_type n) const; |
| 148 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 149 | float load_factor() const noexcept; |
| 150 | float max_load_factor() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 151 | void max_load_factor(float z); |
| 152 | void rehash(size_type n); |
| 153 | void reserve(size_type n); |
| 154 | }; |
| 155 | |
| 156 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 157 | void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x, |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 158 | unordered_map<Key, T, Hash, Pred, Alloc>& y) |
| 159 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 160 | |
| 161 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 162 | bool |
| 163 | operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x, |
| 164 | const unordered_map<Key, T, Hash, Pred, Alloc>& y); |
| 165 | |
| 166 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 167 | bool |
| 168 | operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x, |
| 169 | const unordered_map<Key, T, Hash, Pred, Alloc>& y); |
| 170 | |
| 171 | template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 172 | class Alloc = allocator<pair<const Key, T>>> |
| 173 | class unordered_multimap |
| 174 | { |
| 175 | public: |
| 176 | // types |
| 177 | typedef Key key_type; |
| 178 | typedef T mapped_type; |
| 179 | typedef Hash hasher; |
| 180 | typedef Pred key_equal; |
| 181 | typedef Alloc allocator_type; |
| 182 | typedef pair<const key_type, mapped_type> value_type; |
| 183 | typedef value_type& reference; |
| 184 | typedef const value_type& const_reference; |
| 185 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 186 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 187 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 188 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 189 | |
| 190 | typedef /unspecified/ iterator; |
| 191 | typedef /unspecified/ const_iterator; |
| 192 | typedef /unspecified/ local_iterator; |
| 193 | typedef /unspecified/ const_local_iterator; |
| 194 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 195 | unordered_multimap() |
| 196 | noexcept( |
| 197 | is_nothrow_default_constructible<hasher>::value && |
| 198 | is_nothrow_default_constructible<key_equal>::value && |
| 199 | is_nothrow_default_constructible<allocator_type>::value); |
| 200 | explicit unordered_multimap(size_type n, const hasher& hf = hasher(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | const key_equal& eql = key_equal(), |
| 202 | const allocator_type& a = allocator_type()); |
| 203 | template <class InputIterator> |
| 204 | unordered_multimap(InputIterator f, InputIterator l, |
| 205 | size_type n = 0, const hasher& hf = hasher(), |
| 206 | const key_equal& eql = key_equal(), |
| 207 | const allocator_type& a = allocator_type()); |
| 208 | explicit unordered_multimap(const allocator_type&); |
| 209 | unordered_multimap(const unordered_multimap&); |
| 210 | unordered_multimap(const unordered_multimap&, const Allocator&); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 211 | unordered_multimap(unordered_multimap&&) |
| 212 | noexcept( |
| 213 | is_nothrow_move_constructible<hasher>::value && |
| 214 | is_nothrow_move_constructible<key_equal>::value && |
| 215 | is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 216 | unordered_multimap(unordered_multimap&&, const Allocator&); |
| 217 | unordered_multimap(initializer_list<value_type>, size_type n = 0, |
| 218 | const hasher& hf = hasher(), const key_equal& eql = key_equal(), |
| 219 | const allocator_type& a = allocator_type()); |
| 220 | ~unordered_multimap(); |
| 221 | unordered_multimap& operator=(const unordered_multimap&); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 222 | unordered_multimap& operator=(unordered_multimap&&) |
| 223 | noexcept( |
| 224 | allocator_type::propagate_on_container_move_assignment::value && |
| 225 | is_nothrow_move_assignable<allocator_type>::value && |
| 226 | is_nothrow_move_assignable<hasher>::value && |
| 227 | is_nothrow_move_assignable<key_equal>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 228 | unordered_multimap& operator=(initializer_list<value_type>); |
| 229 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 230 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 231 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 232 | bool empty() const noexcept; |
| 233 | size_type size() const noexcept; |
| 234 | size_type max_size() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 236 | iterator begin() noexcept; |
| 237 | iterator end() noexcept; |
| 238 | const_iterator begin() const noexcept; |
| 239 | const_iterator end() const noexcept; |
| 240 | const_iterator cbegin() const noexcept; |
| 241 | const_iterator cend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 242 | |
| 243 | template <class... Args> |
| 244 | iterator emplace(Args&&... args); |
| 245 | template <class... Args> |
| 246 | iterator emplace_hint(const_iterator position, Args&&... args); |
| 247 | iterator insert(const value_type& obj); |
| 248 | template <class P> |
| 249 | iterator insert(P&& obj); |
| 250 | iterator insert(const_iterator hint, const value_type& obj); |
| 251 | template <class P> |
| 252 | iterator insert(const_iterator hint, P&& obj); |
| 253 | template <class InputIterator> |
| 254 | void insert(InputIterator first, InputIterator last); |
| 255 | void insert(initializer_list<value_type>); |
| 256 | |
| 257 | iterator erase(const_iterator position); |
| 258 | size_type erase(const key_type& k); |
| 259 | iterator erase(const_iterator first, const_iterator last); |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 260 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 261 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 262 | void swap(unordered_multimap&) |
| 263 | noexcept( |
| 264 | (!allocator_type::propagate_on_container_swap::value || |
| 265 | __is_nothrow_swappable<allocator_type>::value) && |
| 266 | __is_nothrow_swappable<hasher>::value && |
| 267 | __is_nothrow_swappable<key_equal>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | |
| 269 | hasher hash_function() const; |
| 270 | key_equal key_eq() const; |
| 271 | |
| 272 | iterator find(const key_type& k); |
| 273 | const_iterator find(const key_type& k) const; |
| 274 | size_type count(const key_type& k) const; |
| 275 | pair<iterator, iterator> equal_range(const key_type& k); |
| 276 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 277 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 278 | size_type bucket_count() const noexcept; |
| 279 | size_type max_bucket_count() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | |
| 281 | size_type bucket_size(size_type n) const; |
| 282 | size_type bucket(const key_type& k) const; |
| 283 | |
| 284 | local_iterator begin(size_type n); |
| 285 | local_iterator end(size_type n); |
| 286 | const_local_iterator begin(size_type n) const; |
| 287 | const_local_iterator end(size_type n) const; |
| 288 | const_local_iterator cbegin(size_type n) const; |
| 289 | const_local_iterator cend(size_type n) const; |
| 290 | |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 291 | float load_factor() const noexcept; |
| 292 | float max_load_factor() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | void max_load_factor(float z); |
| 294 | void rehash(size_type n); |
| 295 | void reserve(size_type n); |
| 296 | }; |
| 297 | |
| 298 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 299 | void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x, |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 300 | unordered_multimap<Key, T, Hash, Pred, Alloc>& y) |
| 301 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 302 | |
| 303 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 304 | bool |
| 305 | operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, |
| 306 | const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); |
| 307 | |
| 308 | template <class Key, class T, class Hash, class Pred, class Alloc> |
| 309 | bool |
| 310 | operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, |
| 311 | const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); |
| 312 | |
| 313 | } // std |
| 314 | |
| 315 | */ |
| 316 | |
| 317 | #include <__config> |
| 318 | #include <__hash_table> |
| 319 | #include <functional> |
| 320 | #include <stdexcept> |
| 321 | |
| 322 | #pragma GCC system_header |
| 323 | |
| 324 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 325 | |
| 326 | template <class _Tp, class _Hash, bool = is_empty<_Hash>::value> |
| 327 | class __unordered_map_hasher |
| 328 | : private _Hash |
| 329 | { |
| 330 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 331 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 332 | __unordered_map_hasher() |
| 333 | _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) |
| 334 | : _Hash() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 335 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 336 | __unordered_map_hasher(const _Hash& __h) |
| 337 | _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) |
| 338 | : _Hash(__h) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 339 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 340 | const _Hash& hash_function() const _NOEXCEPT {return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 341 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 342 | size_t operator()(const _Tp& __x) const |
| 343 | {return static_cast<const _Hash&>(*this)(__x.first);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 344 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 345 | size_t operator()(const typename _Tp::first_type& __x) const |
| 346 | {return static_cast<const _Hash&>(*this)(__x);} |
| 347 | }; |
| 348 | |
| 349 | template <class _Tp, class _Hash> |
| 350 | class __unordered_map_hasher<_Tp, _Hash, false> |
| 351 | { |
| 352 | _Hash __hash_; |
| 353 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 354 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 355 | __unordered_map_hasher() |
| 356 | _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) |
| 357 | : __hash_() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 358 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 359 | __unordered_map_hasher(const _Hash& __h) |
| 360 | _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value) |
| 361 | : __hash_(__h) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 362 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 363 | const _Hash& hash_function() const _NOEXCEPT {return __hash_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 364 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | size_t operator()(const _Tp& __x) const |
| 366 | {return __hash_(__x.first);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 367 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 368 | size_t operator()(const typename _Tp::first_type& __x) const |
| 369 | {return __hash_(__x);} |
| 370 | }; |
| 371 | |
| 372 | template <class _Tp, class _Pred, bool = is_empty<_Pred>::value> |
| 373 | class __unordered_map_equal |
| 374 | : private _Pred |
| 375 | { |
| 376 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 377 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 378 | __unordered_map_equal() |
| 379 | _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) |
| 380 | : _Pred() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 381 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 382 | __unordered_map_equal(const _Pred& __p) |
| 383 | _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) |
| 384 | : _Pred(__p) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 385 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 386 | const _Pred& key_eq() const _NOEXCEPT {return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 387 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 388 | bool operator()(const _Tp& __x, const _Tp& __y) const |
| 389 | {return static_cast<const _Pred&>(*this)(__x.first, __y.first);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 390 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const |
| 392 | {return static_cast<const _Pred&>(*this)(__x, __y.first);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 393 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const |
| 395 | {return static_cast<const _Pred&>(*this)(__x.first, __y);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 396 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 397 | bool operator()(const typename _Tp::first_type& __x, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 398 | const typename _Tp::first_type& __y) const |
| 399 | {return static_cast<const _Pred&>(*this)(__x, __y);} |
| 400 | }; |
| 401 | |
| 402 | template <class _Tp, class _Pred> |
| 403 | class __unordered_map_equal<_Tp, _Pred, false> |
| 404 | { |
| 405 | _Pred __pred_; |
| 406 | public: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 407 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 408 | __unordered_map_equal() |
| 409 | _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) |
| 410 | : __pred_() {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 411 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 412 | __unordered_map_equal(const _Pred& __p) |
| 413 | _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value) |
| 414 | : __pred_(__p) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 415 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 416 | const _Pred& key_eq() const _NOEXCEPT {return __pred_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 417 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 418 | bool operator()(const _Tp& __x, const _Tp& __y) const |
| 419 | {return __pred_(__x.first, __y.first);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 420 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const |
| 422 | {return __pred_(__x, __y.first);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 423 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const |
| 425 | {return __pred_(__x.first, __y);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 426 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 427 | bool operator()(const typename _Tp::first_type& __x, |
| 428 | const typename _Tp::first_type& __y) const |
| 429 | {return __pred_(__x, __y);} |
| 430 | }; |
| 431 | |
| 432 | template <class _Alloc> |
| 433 | class __hash_map_node_destructor |
| 434 | { |
| 435 | typedef _Alloc allocator_type; |
| 436 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 437 | typedef typename __alloc_traits::value_type::value_type value_type; |
| 438 | public: |
| 439 | typedef typename __alloc_traits::pointer pointer; |
| 440 | private: |
| 441 | typedef typename value_type::first_type first_type; |
| 442 | typedef typename value_type::second_type second_type; |
| 443 | |
| 444 | allocator_type& __na_; |
| 445 | |
| 446 | __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); |
| 447 | |
| 448 | public: |
| 449 | bool __first_constructed; |
| 450 | bool __second_constructed; |
| 451 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 452 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 453 | explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 454 | : __na_(__na), |
| 455 | __first_constructed(false), |
| 456 | __second_constructed(false) |
| 457 | {} |
| 458 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 459 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 460 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 461 | __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 462 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | : __na_(__x.__na_), |
| 464 | __first_constructed(__x.__value_constructed), |
| 465 | __second_constructed(__x.__value_constructed) |
| 466 | { |
| 467 | __x.__value_constructed = false; |
| 468 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 469 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 470 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 471 | __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) |
| 472 | : __na_(__x.__na_), |
| 473 | __first_constructed(__x.__value_constructed), |
| 474 | __second_constructed(__x.__value_constructed) |
| 475 | { |
| 476 | const_cast<bool&>(__x.__value_constructed) = false; |
| 477 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 478 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 479 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 480 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 481 | void operator()(pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 482 | { |
| 483 | if (__second_constructed) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 484 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 | if (__first_constructed) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 486 | __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 487 | if (__p) |
| 488 | __alloc_traits::deallocate(__na_, __p, 1); |
| 489 | } |
| 490 | }; |
| 491 | |
| 492 | template <class _HashIterator> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 493 | class _LIBCPP_VISIBLE __hash_map_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 494 | { |
| 495 | _HashIterator __i_; |
| 496 | |
| 497 | typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits; |
| 498 | typedef const typename _HashIterator::value_type::first_type key_type; |
| 499 | typedef typename _HashIterator::value_type::second_type mapped_type; |
| 500 | public: |
| 501 | typedef forward_iterator_tag iterator_category; |
| 502 | typedef pair<key_type, mapped_type> value_type; |
| 503 | typedef typename _HashIterator::difference_type difference_type; |
| 504 | typedef value_type& reference; |
| 505 | typedef typename __pointer_traits::template |
| 506 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 507 | rebind<value_type> |
| 508 | #else |
| 509 | rebind<value_type>::other |
| 510 | #endif |
| 511 | pointer; |
| 512 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 513 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 514 | __hash_map_iterator() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 517 | __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 519 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | reference operator*() const {return *operator->();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 521 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 522 | pointer operator->() const {return (pointer)__i_.operator->();} |
| 523 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 524 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 525 | __hash_map_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 526 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 527 | __hash_map_iterator operator++(int) |
| 528 | { |
| 529 | __hash_map_iterator __t(*this); |
| 530 | ++(*this); |
| 531 | return __t; |
| 532 | } |
| 533 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 534 | friend _LIBCPP_INLINE_VISIBILITY |
| 535 | bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 536 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 537 | friend _LIBCPP_INLINE_VISIBILITY |
| 538 | bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | {return __x.__i_ != __y.__i_;} |
| 540 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 541 | template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_map; |
| 542 | template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_multimap; |
| 543 | template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator; |
| 544 | template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator; |
| 545 | template <class> friend class _LIBCPP_VISIBLE __hash_map_const_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 546 | }; |
| 547 | |
| 548 | template <class _HashIterator> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 549 | class _LIBCPP_VISIBLE __hash_map_const_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | { |
| 551 | _HashIterator __i_; |
| 552 | |
| 553 | typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits; |
| 554 | typedef const typename _HashIterator::value_type::first_type key_type; |
| 555 | typedef typename _HashIterator::value_type::second_type mapped_type; |
| 556 | public: |
| 557 | typedef forward_iterator_tag iterator_category; |
| 558 | typedef pair<key_type, mapped_type> value_type; |
| 559 | typedef typename _HashIterator::difference_type difference_type; |
| 560 | typedef const value_type& reference; |
| 561 | typedef typename __pointer_traits::template |
| 562 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 563 | rebind<value_type> |
| 564 | #else |
| 565 | rebind<value_type>::other |
| 566 | #endif |
| 567 | pointer; |
| 568 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 569 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 570 | __hash_map_const_iterator() _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 571 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 572 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 573 | __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | __hash_map_const_iterator( |
| 576 | __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 577 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 578 | : __i_(__i.__i_) {} |
| 579 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | reference operator*() const {return *operator->();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 582 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 583 | pointer operator->() const {return (pointer)__i_.operator->();} |
| 584 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 585 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 586 | __hash_map_const_iterator& operator++() {++__i_; return *this;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 587 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 588 | __hash_map_const_iterator operator++(int) |
| 589 | { |
| 590 | __hash_map_const_iterator __t(*this); |
| 591 | ++(*this); |
| 592 | return __t; |
| 593 | } |
| 594 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 595 | friend _LIBCPP_INLINE_VISIBILITY |
| 596 | 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] | 597 | {return __x.__i_ == __y.__i_;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 598 | friend _LIBCPP_INLINE_VISIBILITY |
| 599 | 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] | 600 | {return __x.__i_ != __y.__i_;} |
| 601 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 602 | template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_map; |
| 603 | template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_multimap; |
| 604 | template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator; |
| 605 | template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 606 | }; |
| 607 | |
| 608 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 609 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 610 | class _LIBCPP_VISIBLE unordered_map |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 611 | { |
| 612 | public: |
| 613 | // types |
| 614 | typedef _Key key_type; |
| 615 | typedef _Tp mapped_type; |
| 616 | typedef _Hash hasher; |
| 617 | typedef _Pred key_equal; |
| 618 | typedef _Alloc allocator_type; |
| 619 | typedef pair<const key_type, mapped_type> value_type; |
| 620 | typedef value_type& reference; |
| 621 | typedef const value_type& const_reference; |
| 622 | |
| 623 | private: |
| 624 | typedef pair<key_type, mapped_type> __value_type; |
| 625 | typedef __unordered_map_hasher<__value_type, hasher> __hasher; |
| 626 | typedef __unordered_map_equal<__value_type, key_equal> __key_equal; |
| 627 | typedef typename allocator_traits<allocator_type>::template |
| 628 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 629 | rebind_alloc<__value_type> |
| 630 | #else |
| 631 | rebind_alloc<__value_type>::other |
| 632 | #endif |
| 633 | __allocator_type; |
| 634 | |
| 635 | typedef __hash_table<__value_type, __hasher, |
| 636 | __key_equal, __allocator_type> __table; |
| 637 | |
| 638 | __table __table_; |
| 639 | |
| 640 | typedef typename __table::__node_pointer __node_pointer; |
| 641 | typedef typename __table::__node_const_pointer __node_const_pointer; |
| 642 | typedef typename __table::__node_traits __node_traits; |
| 643 | typedef typename __table::__node_allocator __node_allocator; |
| 644 | typedef typename __table::__node __node; |
| 645 | typedef __hash_map_node_destructor<__node_allocator> _D; |
| 646 | typedef unique_ptr<__node, _D> __node_holder; |
| 647 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 648 | public: |
| 649 | typedef typename __alloc_traits::pointer pointer; |
| 650 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 651 | typedef typename __alloc_traits::size_type size_type; |
| 652 | typedef typename __alloc_traits::difference_type difference_type; |
| 653 | |
| 654 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 655 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 656 | typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; |
| 657 | typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; |
| 658 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 659 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 660 | unordered_map() |
| 661 | _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) |
| 662 | {} // = default; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 663 | explicit unordered_map(size_type __n, const hasher& __hf = hasher(), |
| 664 | const key_equal& __eql = key_equal()); |
| 665 | unordered_map(size_type __n, const hasher& __hf, |
| 666 | const key_equal& __eql, |
| 667 | const allocator_type& __a); |
| 668 | template <class _InputIterator> |
| 669 | unordered_map(_InputIterator __first, _InputIterator __last); |
| 670 | template <class _InputIterator> |
| 671 | unordered_map(_InputIterator __first, _InputIterator __last, |
| 672 | size_type __n, const hasher& __hf = hasher(), |
| 673 | const key_equal& __eql = key_equal()); |
| 674 | template <class _InputIterator> |
| 675 | unordered_map(_InputIterator __first, _InputIterator __last, |
| 676 | size_type __n, const hasher& __hf, |
| 677 | const key_equal& __eql, |
| 678 | const allocator_type& __a); |
| 679 | explicit unordered_map(const allocator_type& __a); |
| 680 | unordered_map(const unordered_map& __u); |
| 681 | unordered_map(const unordered_map& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 682 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 683 | unordered_map(unordered_map&& __u) |
| 684 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 685 | unordered_map(unordered_map&& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 686 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 687 | unordered_map(initializer_list<value_type> __il); |
| 688 | unordered_map(initializer_list<value_type> __il, size_type __n, |
| 689 | const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); |
| 690 | unordered_map(initializer_list<value_type> __il, size_type __n, |
| 691 | const hasher& __hf, const key_equal& __eql, |
| 692 | const allocator_type& __a); |
| 693 | // ~unordered_map() = default; |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame^] | 694 | _LIBCPP_INLINE_VISIBILITY |
| 695 | unordered_map& operator=(const unordered_map& __u) |
| 696 | { |
| 697 | __table_ = __u.__table_; |
| 698 | return *this; |
| 699 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 700 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 701 | unordered_map& operator=(unordered_map&& __u) |
| 702 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 703 | #endif |
| 704 | unordered_map& operator=(initializer_list<value_type> __il); |
| 705 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 706 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 707 | allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 708 | {return allocator_type(__table_.__node_alloc());} |
| 709 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 710 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 711 | bool empty() const _NOEXCEPT {return __table_.size() == 0;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 712 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 713 | size_type size() const _NOEXCEPT {return __table_.size();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 714 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 715 | size_type max_size() const _NOEXCEPT {return __table_.max_size();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 716 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 717 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 718 | iterator begin() _NOEXCEPT {return __table_.begin();} |
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 | iterator end() _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 721 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 722 | const_iterator begin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 723 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 724 | const_iterator end() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 725 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 726 | const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 727 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 728 | const_iterator cend() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 729 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 730 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 731 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 732 | pair<iterator, bool> emplace() |
| 733 | {return __table_.__emplace_unique();} |
| 734 | |
| 735 | template <class _A0, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 736 | class = typename enable_if<is_constructible<value_type, _A0>::value>::type> |
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 | pair<iterator, bool> emplace(_A0&& __a0) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 739 | {return __table_.__emplace_unique(_VSTD::forward<_A0>(__a0));} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 740 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 741 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 742 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 743 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 744 | class = typename enable_if<is_constructible<key_type, _A0>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 745 | pair<iterator, bool> emplace(_A0&& __a0, _Args&&... __args); |
| 746 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 747 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 748 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 749 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 750 | iterator emplace_hint(const_iterator) |
| 751 | {return __table_.__emplace_unique().first;} |
| 752 | |
| 753 | template <class _A0, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 754 | class = typename enable_if<is_constructible<value_type, _A0>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 755 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 756 | iterator emplace_hint(const_iterator, _A0&& __a0) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 757 | {return __table_.__emplace_unique(_VSTD::forward<_A0>(__a0)).first;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 758 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 759 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 760 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 761 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 762 | class = typename enable_if<is_constructible<key_type, _A0>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 763 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 764 | iterator emplace_hint(const_iterator, _A0&& __a0, _Args&&... __args) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 765 | {return emplace(_VSTD::forward<_A0>(__a0), |
| 766 | _VSTD::forward<_Args>(__args)...).first;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 767 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 768 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 769 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 770 | pair<iterator, bool> insert(const value_type& __x) |
| 771 | {return __table_.__insert_unique(__x);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 772 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 773 | template <class _P, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 774 | class = typename enable_if<is_constructible<value_type, _P>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 775 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 776 | pair<iterator, bool> insert(_P&& __x) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 777 | {return __table_.__insert_unique(_VSTD::forward<_P>(__x));} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 778 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 779 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 780 | iterator insert(const_iterator, const value_type& __x) |
| 781 | {return insert(__x).first;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 782 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 783 | template <class _P, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 784 | class = typename enable_if<is_constructible<value_type, _P>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 785 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 786 | iterator insert(const_iterator, _P&& __x) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 787 | {return insert(_VSTD::forward<_P>(__x)).first;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 788 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 789 | template <class _InputIterator> |
| 790 | void insert(_InputIterator __first, _InputIterator __last); |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 791 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 792 | void insert(initializer_list<value_type> __il) |
| 793 | {insert(__il.begin(), __il.end());} |
| 794 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 795 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 796 | iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 797 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 798 | size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 799 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 800 | iterator erase(const_iterator __first, const_iterator __last) |
| 801 | {return __table_.erase(__first.__i_, __last.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 803 | void clear() _NOEXCEPT {__table_.clear();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 804 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 805 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 806 | void swap(unordered_map& __u) |
| 807 | _NOEXCEPT_(__is_nothrow_swappable<__table>::value) |
| 808 | {__table_.swap(__u.__table_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 809 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 810 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 811 | hasher hash_function() const |
| 812 | {return __table_.hash_function().hash_function();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 813 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 814 | key_equal key_eq() const |
| 815 | {return __table_.key_eq().key_eq();} |
| 816 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 817 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 818 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 819 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 820 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 821 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 822 | 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] | 823 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 824 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 825 | {return __table_.__equal_range_unique(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 826 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 827 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 828 | {return __table_.__equal_range_unique(__k);} |
| 829 | |
| 830 | mapped_type& operator[](const key_type& __k); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 831 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 832 | mapped_type& operator[](key_type&& __k); |
| 833 | #endif |
| 834 | |
| 835 | mapped_type& at(const key_type& __k); |
| 836 | const mapped_type& at(const key_type& __k) const; |
| 837 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 838 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 839 | size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 840 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 841 | size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 842 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 843 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 844 | size_type bucket_size(size_type __n) const |
| 845 | {return __table_.bucket_size(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 846 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 847 | size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} |
| 848 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 849 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 850 | local_iterator begin(size_type __n) {return __table_.begin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 851 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 852 | local_iterator end(size_type __n) {return __table_.end(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 853 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 854 | const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 855 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 856 | const_local_iterator end(size_type __n) const {return __table_.cend(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 857 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 858 | const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 859 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 860 | const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} |
| 861 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 862 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 863 | float load_factor() const _NOEXCEPT {return __table_.load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 864 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 865 | float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 866 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 867 | void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 868 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 869 | void rehash(size_type __n) {__table_.rehash(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 870 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 871 | void reserve(size_type __n) {__table_.reserve(__n);} |
| 872 | |
| 873 | private: |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 874 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 875 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 876 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 877 | class = typename enable_if<is_constructible<key_type, _A0>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 878 | __node_holder __construct_node(_A0&& __a0, _Args&&... __args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 879 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 880 | template <class _A0, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 881 | class = typename enable_if<is_constructible<value_type, _A0>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 882 | __node_holder __construct_node(_A0&& __a0); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 883 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | __node_holder __construct_node(const key_type& __k); |
| 885 | #endif |
| 886 | }; |
| 887 | |
| 888 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 889 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 890 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 891 | : __table_(__hf, __eql) |
| 892 | { |
| 893 | __table_.rehash(__n); |
| 894 | } |
| 895 | |
| 896 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 897 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 898 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 899 | const allocator_type& __a) |
| 900 | : __table_(__hf, __eql, __a) |
| 901 | { |
| 902 | __table_.rehash(__n); |
| 903 | } |
| 904 | |
| 905 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 906 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 907 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 908 | const allocator_type& __a) |
| 909 | : __table_(__a) |
| 910 | { |
| 911 | } |
| 912 | |
| 913 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 914 | template <class _InputIterator> |
| 915 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 916 | _InputIterator __first, _InputIterator __last) |
| 917 | { |
| 918 | insert(__first, __last); |
| 919 | } |
| 920 | |
| 921 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 922 | template <class _InputIterator> |
| 923 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 924 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 925 | const hasher& __hf, const key_equal& __eql) |
| 926 | : __table_(__hf, __eql) |
| 927 | { |
| 928 | __table_.rehash(__n); |
| 929 | insert(__first, __last); |
| 930 | } |
| 931 | |
| 932 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 933 | template <class _InputIterator> |
| 934 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 935 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 936 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 937 | : __table_(__hf, __eql, __a) |
| 938 | { |
| 939 | __table_.rehash(__n); |
| 940 | insert(__first, __last); |
| 941 | } |
| 942 | |
| 943 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 944 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 945 | const unordered_map& __u) |
| 946 | : __table_(__u.__table_) |
| 947 | { |
| 948 | __table_.rehash(__u.bucket_count()); |
| 949 | insert(__u.begin(), __u.end()); |
| 950 | } |
| 951 | |
| 952 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 953 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 954 | const unordered_map& __u, const allocator_type& __a) |
| 955 | : __table_(__u.__table_, __a) |
| 956 | { |
| 957 | __table_.rehash(__u.bucket_count()); |
| 958 | insert(__u.begin(), __u.end()); |
| 959 | } |
| 960 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 961 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 962 | |
| 963 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 964 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 965 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 966 | unordered_map&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 967 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 968 | : __table_(_VSTD::move(__u.__table_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 969 | { |
| 970 | } |
| 971 | |
| 972 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 973 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 974 | unordered_map&& __u, const allocator_type& __a) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 975 | : __table_(_VSTD::move(__u.__table_), __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 976 | { |
| 977 | if (__a != __u.get_allocator()) |
| 978 | { |
| 979 | iterator __i = __u.begin(); |
| 980 | while (__u.size() != 0) |
| 981 | __table_.__insert_unique( |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 982 | _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 983 | ); |
| 984 | } |
| 985 | } |
| 986 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 987 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 988 | |
| 989 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 990 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 991 | initializer_list<value_type> __il) |
| 992 | { |
| 993 | insert(__il.begin(), __il.end()); |
| 994 | } |
| 995 | |
| 996 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 997 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 998 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 999 | const key_equal& __eql) |
| 1000 | : __table_(__hf, __eql) |
| 1001 | { |
| 1002 | __table_.rehash(__n); |
| 1003 | insert(__il.begin(), __il.end()); |
| 1004 | } |
| 1005 | |
| 1006 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1007 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( |
| 1008 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1009 | const key_equal& __eql, const allocator_type& __a) |
| 1010 | : __table_(__hf, __eql, __a) |
| 1011 | { |
| 1012 | __table_.rehash(__n); |
| 1013 | insert(__il.begin(), __il.end()); |
| 1014 | } |
| 1015 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1016 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1017 | |
| 1018 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1019 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1020 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1021 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1022 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1023 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1024 | __table_ = _VSTD::move(__u.__table_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1025 | return *this; |
| 1026 | } |
| 1027 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1028 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1029 | |
| 1030 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1031 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1032 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1033 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( |
| 1034 | initializer_list<value_type> __il) |
| 1035 | { |
| 1036 | __table_.__assign_unique(__il.begin(), __il.end()); |
| 1037 | return *this; |
| 1038 | } |
| 1039 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1040 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1041 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1042 | |
| 1043 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1044 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1045 | class // = typename enable_if<is_constructible<key_type, _A0>::value>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1046 | > |
| 1047 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 1048 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0, |
| 1049 | _Args&&... __args) |
| 1050 | { |
| 1051 | __node_allocator& __na = __table_.__node_alloc(); |
| 1052 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1053 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), |
| 1054 | _VSTD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1055 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1056 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), |
| 1057 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1058 | __h.get_deleter().__second_constructed = true; |
| 1059 | return __h; |
| 1060 | } |
| 1061 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1062 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1063 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1064 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1065 | template <class _A0, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1066 | class // = typename enable_if<is_constructible<value_type, _A0>::value>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1067 | > |
| 1068 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 1069 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) |
| 1070 | { |
| 1071 | __node_allocator& __na = __table_.__node_alloc(); |
| 1072 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1073 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_), |
| 1074 | _VSTD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1075 | __h.get_deleter().__first_constructed = true; |
| 1076 | __h.get_deleter().__second_constructed = true; |
| 1077 | return __h; |
| 1078 | } |
| 1079 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1080 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1081 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1082 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1083 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1084 | class // = typename enable_if<is_constructible<key_type, _A0>::value>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1085 | > |
| 1086 | pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool> |
| 1087 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args) |
| 1088 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1089 | __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), |
| 1090 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1091 | pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); |
| 1092 | if (__r.second) |
| 1093 | __h.release(); |
| 1094 | return __r; |
| 1095 | } |
| 1096 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1097 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1098 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1099 | |
| 1100 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1101 | typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 1102 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k) |
| 1103 | { |
| 1104 | __node_allocator& __na = __table_.__node_alloc(); |
| 1105 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1106 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1107 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1108 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1109 | __h.get_deleter().__second_constructed = true; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1110 | return _VSTD::move(__h); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1113 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1114 | |
| 1115 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1116 | template <class _InputIterator> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1117 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1118 | void |
| 1119 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 1120 | _InputIterator __last) |
| 1121 | { |
| 1122 | for (; __first != __last; ++__first) |
| 1123 | __table_.__insert_unique(*__first); |
| 1124 | } |
| 1125 | |
| 1126 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1127 | _Tp& |
| 1128 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) |
| 1129 | { |
| 1130 | iterator __i = find(__k); |
| 1131 | if (__i != end()) |
| 1132 | return __i->second; |
| 1133 | __node_holder __h = __construct_node(__k); |
| 1134 | pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); |
| 1135 | __h.release(); |
| 1136 | return __r.first->second; |
| 1137 | } |
| 1138 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1139 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1140 | |
| 1141 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1142 | _Tp& |
| 1143 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k) |
| 1144 | { |
| 1145 | iterator __i = find(__k); |
| 1146 | if (__i != end()) |
| 1147 | return __i->second; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1148 | __node_holder __h = __construct_node(_VSTD::move(__k)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1149 | pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); |
| 1150 | __h.release(); |
| 1151 | return __r.first->second; |
| 1152 | } |
| 1153 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1154 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1155 | |
| 1156 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1157 | _Tp& |
| 1158 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) |
| 1159 | { |
| 1160 | iterator __i = find(__k); |
| 1161 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1162 | if (__i == end()) |
| 1163 | throw out_of_range("unordered_map::at: key not found"); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1164 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1165 | return __i->second; |
| 1166 | } |
| 1167 | |
| 1168 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1169 | const _Tp& |
| 1170 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const |
| 1171 | { |
| 1172 | const_iterator __i = find(__k); |
| 1173 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1174 | if (__i == end()) |
| 1175 | throw out_of_range("unordered_map::at: key not found"); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1176 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1177 | return __i->second; |
| 1178 | } |
| 1179 | |
| 1180 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1181 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1182 | void |
| 1183 | swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1184 | unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1185 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1186 | { |
| 1187 | __x.swap(__y); |
| 1188 | } |
| 1189 | |
| 1190 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1191 | bool |
| 1192 | operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1193 | const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1194 | { |
| 1195 | if (__x.size() != __y.size()) |
| 1196 | return false; |
| 1197 | typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 1198 | const_iterator; |
| 1199 | for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); |
| 1200 | __i != __ex; ++__i) |
| 1201 | { |
| 1202 | const_iterator __j = __y.find(__i->first); |
| 1203 | if (__j == __ey || !(*__i == *__j)) |
| 1204 | return false; |
| 1205 | } |
| 1206 | return true; |
| 1207 | } |
| 1208 | |
| 1209 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1210 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1211 | bool |
| 1212 | operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1213 | const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1214 | { |
| 1215 | return !(__x == __y); |
| 1216 | } |
| 1217 | |
| 1218 | template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, |
| 1219 | class _Alloc = allocator<pair<const _Key, _Tp> > > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1220 | class _LIBCPP_VISIBLE unordered_multimap |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1221 | { |
| 1222 | public: |
| 1223 | // types |
| 1224 | typedef _Key key_type; |
| 1225 | typedef _Tp mapped_type; |
| 1226 | typedef _Hash hasher; |
| 1227 | typedef _Pred key_equal; |
| 1228 | typedef _Alloc allocator_type; |
| 1229 | typedef pair<const key_type, mapped_type> value_type; |
| 1230 | typedef value_type& reference; |
| 1231 | typedef const value_type& const_reference; |
| 1232 | |
| 1233 | private: |
| 1234 | typedef pair<key_type, mapped_type> __value_type; |
| 1235 | typedef __unordered_map_hasher<__value_type, hasher> __hasher; |
| 1236 | typedef __unordered_map_equal<__value_type, key_equal> __key_equal; |
| 1237 | typedef typename allocator_traits<allocator_type>::template |
| 1238 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1239 | rebind_alloc<__value_type> |
| 1240 | #else |
| 1241 | rebind_alloc<__value_type>::other |
| 1242 | #endif |
| 1243 | __allocator_type; |
| 1244 | |
| 1245 | typedef __hash_table<__value_type, __hasher, |
| 1246 | __key_equal, __allocator_type> __table; |
| 1247 | |
| 1248 | __table __table_; |
| 1249 | |
| 1250 | typedef typename __table::__node_traits __node_traits; |
| 1251 | typedef typename __table::__node_allocator __node_allocator; |
| 1252 | typedef typename __table::__node __node; |
| 1253 | typedef __hash_map_node_destructor<__node_allocator> _D; |
| 1254 | typedef unique_ptr<__node, _D> __node_holder; |
| 1255 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 1256 | public: |
| 1257 | typedef typename __alloc_traits::pointer pointer; |
| 1258 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 1259 | typedef typename __alloc_traits::size_type size_type; |
| 1260 | typedef typename __alloc_traits::difference_type difference_type; |
| 1261 | |
| 1262 | typedef __hash_map_iterator<typename __table::iterator> iterator; |
| 1263 | typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; |
| 1264 | typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; |
| 1265 | typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; |
| 1266 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1267 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1268 | unordered_multimap() |
| 1269 | _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) |
| 1270 | {} // = default; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1271 | explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(), |
| 1272 | const key_equal& __eql = key_equal()); |
| 1273 | unordered_multimap(size_type __n, const hasher& __hf, |
| 1274 | const key_equal& __eql, |
| 1275 | const allocator_type& __a); |
| 1276 | template <class _InputIterator> |
| 1277 | unordered_multimap(_InputIterator __first, _InputIterator __last); |
| 1278 | template <class _InputIterator> |
| 1279 | unordered_multimap(_InputIterator __first, _InputIterator __last, |
| 1280 | size_type __n, const hasher& __hf = hasher(), |
| 1281 | const key_equal& __eql = key_equal()); |
| 1282 | template <class _InputIterator> |
| 1283 | unordered_multimap(_InputIterator __first, _InputIterator __last, |
| 1284 | size_type __n, const hasher& __hf, |
| 1285 | const key_equal& __eql, |
| 1286 | const allocator_type& __a); |
| 1287 | explicit unordered_multimap(const allocator_type& __a); |
| 1288 | unordered_multimap(const unordered_multimap& __u); |
| 1289 | unordered_multimap(const unordered_multimap& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1290 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1291 | unordered_multimap(unordered_multimap&& __u) |
| 1292 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1293 | unordered_multimap(unordered_multimap&& __u, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1294 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1295 | unordered_multimap(initializer_list<value_type> __il); |
| 1296 | unordered_multimap(initializer_list<value_type> __il, size_type __n, |
| 1297 | const hasher& __hf = hasher(), |
| 1298 | const key_equal& __eql = key_equal()); |
| 1299 | unordered_multimap(initializer_list<value_type> __il, size_type __n, |
| 1300 | const hasher& __hf, const key_equal& __eql, |
| 1301 | const allocator_type& __a); |
| 1302 | // ~unordered_multimap() = default; |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame^] | 1303 | _LIBCPP_INLINE_VISIBILITY |
| 1304 | unordered_multimap& operator=(const unordered_multimap& __u) |
| 1305 | { |
| 1306 | __table_ = __u.__table_; |
| 1307 | return *this; |
| 1308 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1309 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1310 | unordered_multimap& operator=(unordered_multimap&& __u) |
| 1311 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1312 | #endif |
| 1313 | unordered_multimap& operator=(initializer_list<value_type> __il); |
| 1314 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1316 | allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1317 | {return allocator_type(__table_.__node_alloc());} |
| 1318 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1319 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1320 | bool empty() const _NOEXCEPT {return __table_.size() == 0;} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1321 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1322 | size_type size() const _NOEXCEPT {return __table_.size();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1323 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1324 | size_type max_size() const _NOEXCEPT {return __table_.max_size();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1326 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1327 | iterator begin() _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1328 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1329 | iterator end() _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1330 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1331 | const_iterator begin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1332 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1333 | const_iterator end() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1334 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1335 | const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1336 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1337 | const_iterator cend() const _NOEXCEPT {return __table_.end();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1339 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1340 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1341 | iterator emplace() |
| 1342 | {return __table_.__emplace_multi();} |
| 1343 | |
| 1344 | template <class _A0, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1345 | class = typename enable_if<is_constructible<value_type, _A0>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1346 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1347 | iterator emplace(_A0&& __a0) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1348 | {return __table_.__emplace_multi(_VSTD::forward<_A0>(__a0));} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1349 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1350 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1351 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1352 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1353 | class = typename enable_if<is_constructible<key_type, _A0>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1354 | iterator emplace(_A0&& __a0, _Args&&... __args); |
| 1355 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1356 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1357 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1358 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1359 | iterator emplace_hint(const_iterator __p) |
| 1360 | {return __table_.__emplace_hint_multi(__p.__i_);} |
| 1361 | |
| 1362 | template <class _A0, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1363 | class = typename enable_if<is_constructible<value_type, _A0>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1364 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1365 | iterator emplace_hint(const_iterator __p, _A0&& __a0) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1366 | {return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_A0>(__a0));} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1367 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1368 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1369 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1370 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1371 | class = typename enable_if<is_constructible<key_type, _A0>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1372 | iterator emplace_hint(const_iterator __p, _A0&& __a0, _Args&&... __args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1373 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1374 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1375 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1376 | iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1377 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1378 | template <class _P, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1379 | class = typename enable_if<is_constructible<value_type, _P>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1380 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1381 | iterator insert(_P&& __x) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1382 | {return __table_.__insert_multi(_VSTD::forward<_P>(__x));} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1383 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1384 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1385 | iterator insert(const_iterator __p, const value_type& __x) |
| 1386 | {return __table_.__insert_multi(__p.__i_, __x);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1387 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1388 | template <class _P, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1389 | class = typename enable_if<is_constructible<value_type, _P>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1390 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1391 | iterator insert(const_iterator __p, _P&& __x) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1392 | {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_P>(__x));} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1393 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1394 | template <class _InputIterator> |
| 1395 | void insert(_InputIterator __first, _InputIterator __last); |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1396 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1397 | void insert(initializer_list<value_type> __il) |
| 1398 | {insert(__il.begin(), __il.end());} |
| 1399 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1400 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1401 | iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1402 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1403 | size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1404 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1405 | iterator erase(const_iterator __first, const_iterator __last) |
| 1406 | {return __table_.erase(__first.__i_, __last.__i_);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1407 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1408 | void clear() _NOEXCEPT {__table_.clear();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1409 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1410 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1411 | void swap(unordered_multimap& __u) |
| 1412 | _NOEXCEPT_(__is_nothrow_swappable<__table>::value) |
| 1413 | {__table_.swap(__u.__table_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1414 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1415 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1416 | hasher hash_function() const |
| 1417 | {return __table_.hash_function().hash_function();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1418 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1419 | key_equal key_eq() const |
| 1420 | {return __table_.key_eq().key_eq();} |
| 1421 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1422 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1424 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1425 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1426 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1427 | 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] | 1428 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1429 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 1430 | {return __table_.__equal_range_multi(__k);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1431 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1432 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 1433 | {return __table_.__equal_range_multi(__k);} |
| 1434 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1435 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1436 | size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1437 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1438 | size_type max_bucket_count() const _NOEXCEPT |
| 1439 | {return __table_.max_bucket_count();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1440 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1441 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1442 | size_type bucket_size(size_type __n) const |
| 1443 | {return __table_.bucket_size(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1444 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1445 | size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} |
| 1446 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1447 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1448 | local_iterator begin(size_type __n) {return __table_.begin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1449 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1450 | local_iterator end(size_type __n) {return __table_.end(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1451 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1452 | const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1453 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1454 | const_local_iterator end(size_type __n) const {return __table_.cend(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1455 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1456 | const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1457 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1458 | const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} |
| 1459 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1460 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1461 | float load_factor() const _NOEXCEPT {return __table_.load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1462 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1463 | float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1464 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1465 | void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1466 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1467 | void rehash(size_type __n) {__table_.rehash(__n);} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1468 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1469 | void reserve(size_type __n) {__table_.reserve(__n);} |
| 1470 | |
| 1471 | private: |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1472 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1473 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1474 | class = typename enable_if<is_constructible<key_type, _A0>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1475 | __node_holder __construct_node(_A0&& __a0, _Args&&... __args); |
| 1476 | template <class _A0, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1477 | class = typename enable_if<is_constructible<value_type, _A0>::value>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1478 | __node_holder __construct_node(_A0&& __a0); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1479 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1480 | }; |
| 1481 | |
| 1482 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1483 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1484 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 1485 | : __table_(__hf, __eql) |
| 1486 | { |
| 1487 | __table_.rehash(__n); |
| 1488 | } |
| 1489 | |
| 1490 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1491 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1492 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 1493 | const allocator_type& __a) |
| 1494 | : __table_(__hf, __eql, __a) |
| 1495 | { |
| 1496 | __table_.rehash(__n); |
| 1497 | } |
| 1498 | |
| 1499 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1500 | template <class _InputIterator> |
| 1501 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1502 | _InputIterator __first, _InputIterator __last) |
| 1503 | { |
| 1504 | insert(__first, __last); |
| 1505 | } |
| 1506 | |
| 1507 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1508 | template <class _InputIterator> |
| 1509 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1510 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1511 | const hasher& __hf, const key_equal& __eql) |
| 1512 | : __table_(__hf, __eql) |
| 1513 | { |
| 1514 | __table_.rehash(__n); |
| 1515 | insert(__first, __last); |
| 1516 | } |
| 1517 | |
| 1518 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1519 | template <class _InputIterator> |
| 1520 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1521 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 1522 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 1523 | : __table_(__hf, __eql, __a) |
| 1524 | { |
| 1525 | __table_.rehash(__n); |
| 1526 | insert(__first, __last); |
| 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> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1530 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1531 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1532 | const allocator_type& __a) |
| 1533 | : __table_(__a) |
| 1534 | { |
| 1535 | } |
| 1536 | |
| 1537 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1538 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1539 | const unordered_multimap& __u) |
| 1540 | : __table_(__u.__table_) |
| 1541 | { |
| 1542 | __table_.rehash(__u.bucket_count()); |
| 1543 | insert(__u.begin(), __u.end()); |
| 1544 | } |
| 1545 | |
| 1546 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1547 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1548 | const unordered_multimap& __u, const allocator_type& __a) |
| 1549 | : __table_(__u.__table_, __a) |
| 1550 | { |
| 1551 | __table_.rehash(__u.bucket_count()); |
| 1552 | insert(__u.begin(), __u.end()); |
| 1553 | } |
| 1554 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1555 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1556 | |
| 1557 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1558 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1559 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1560 | unordered_multimap&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1561 | _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1562 | : __table_(_VSTD::move(__u.__table_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1563 | { |
| 1564 | } |
| 1565 | |
| 1566 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1567 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1568 | unordered_multimap&& __u, const allocator_type& __a) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1569 | : __table_(_VSTD::move(__u.__table_), __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1570 | { |
| 1571 | if (__a != __u.get_allocator()) |
| 1572 | { |
| 1573 | iterator __i = __u.begin(); |
| 1574 | while (__u.size() != 0) |
| 1575 | { |
| 1576 | __table_.__insert_multi( |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1577 | _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1578 | ); |
| 1579 | } |
| 1580 | } |
| 1581 | } |
| 1582 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1583 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1584 | |
| 1585 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1586 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1587 | initializer_list<value_type> __il) |
| 1588 | { |
| 1589 | insert(__il.begin(), __il.end()); |
| 1590 | } |
| 1591 | |
| 1592 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1593 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1594 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1595 | const key_equal& __eql) |
| 1596 | : __table_(__hf, __eql) |
| 1597 | { |
| 1598 | __table_.rehash(__n); |
| 1599 | insert(__il.begin(), __il.end()); |
| 1600 | } |
| 1601 | |
| 1602 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1603 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( |
| 1604 | initializer_list<value_type> __il, size_type __n, const hasher& __hf, |
| 1605 | const key_equal& __eql, const allocator_type& __a) |
| 1606 | : __table_(__hf, __eql, __a) |
| 1607 | { |
| 1608 | __table_.rehash(__n); |
| 1609 | insert(__il.begin(), __il.end()); |
| 1610 | } |
| 1611 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1612 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1613 | |
| 1614 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1615 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1616 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1617 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1618 | _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1619 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1620 | __table_ = _VSTD::move(__u.__table_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1621 | return *this; |
| 1622 | } |
| 1623 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1624 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1625 | |
| 1626 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1627 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1628 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& |
| 1629 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( |
| 1630 | initializer_list<value_type> __il) |
| 1631 | { |
| 1632 | __table_.__assign_multi(__il.begin(), __il.end()); |
| 1633 | return *this; |
| 1634 | } |
| 1635 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1636 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1637 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1638 | |
| 1639 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1640 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1641 | class // = typename enable_if<is_constructible<key_type, _A0>::value>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1642 | > |
| 1643 | typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 1644 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node( |
| 1645 | _A0&& __a0, _Args&&... __args) |
| 1646 | { |
| 1647 | __node_allocator& __na = __table_.__node_alloc(); |
| 1648 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1649 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), |
| 1650 | _VSTD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1651 | __h.get_deleter().__first_constructed = true; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1652 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), |
| 1653 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1654 | __h.get_deleter().__second_constructed = true; |
| 1655 | return __h; |
| 1656 | } |
| 1657 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1658 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1659 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1660 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1661 | template <class _A0, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1662 | class // = typename enable_if<is_constructible<value_type, _A0>::value>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1663 | > |
| 1664 | typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder |
| 1665 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) |
| 1666 | { |
| 1667 | __node_allocator& __na = __table_.__node_alloc(); |
| 1668 | __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1669 | __node_traits::construct(__na, _VSTD::addressof(__h->__value_), |
| 1670 | _VSTD::forward<_A0>(__a0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1671 | __h.get_deleter().__first_constructed = true; |
| 1672 | __h.get_deleter().__second_constructed = true; |
| 1673 | return __h; |
| 1674 | } |
| 1675 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1676 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1677 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1678 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1679 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1680 | class // = typename enable_if<is_constructible<key_type, _A0>::value>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1681 | > |
| 1682 | typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator |
| 1683 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args) |
| 1684 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1685 | __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), |
| 1686 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1687 | iterator __r = __table_.__node_insert_multi(__h.get()); |
| 1688 | __h.release(); |
| 1689 | return __r; |
| 1690 | } |
| 1691 | |
| 1692 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1693 | template <class _A0, class... _Args, |
Howard Hinnant | 7604fea | 2011-06-19 21:45:00 +0000 | [diff] [blame] | 1694 | class // = typename enable_if<is_constructible<key_type, _A0>::value>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1695 | > |
| 1696 | typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator |
| 1697 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint( |
| 1698 | const_iterator __p, _A0&& __a0, _Args&&... __args) |
| 1699 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1700 | __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), |
| 1701 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1702 | iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get()); |
| 1703 | __h.release(); |
| 1704 | return __r; |
| 1705 | } |
| 1706 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1707 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1708 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1709 | |
| 1710 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1711 | template <class _InputIterator> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1712 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1713 | void |
| 1714 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 1715 | _InputIterator __last) |
| 1716 | { |
| 1717 | for (; __first != __last; ++__first) |
| 1718 | __table_.__insert_multi(*__first); |
| 1719 | } |
| 1720 | |
| 1721 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1722 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1723 | void |
| 1724 | swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1725 | unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
Howard Hinnant | 5f2f14c | 2011-06-04 18:54:24 +0000 | [diff] [blame] | 1726 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1727 | { |
| 1728 | __x.swap(__y); |
| 1729 | } |
| 1730 | |
| 1731 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
| 1732 | bool |
| 1733 | operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1734 | const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1735 | { |
| 1736 | if (__x.size() != __y.size()) |
| 1737 | return false; |
| 1738 | typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator |
| 1739 | const_iterator; |
| 1740 | typedef pair<const_iterator, const_iterator> _EqRng; |
| 1741 | for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) |
| 1742 | { |
| 1743 | _EqRng __xeq = __x.equal_range(__i->first); |
| 1744 | _EqRng __yeq = __y.equal_range(__i->first); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1745 | if (_VSTD::distance(__xeq.first, __xeq.second) != |
| 1746 | _VSTD::distance(__yeq.first, __yeq.second) || |
| 1747 | !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1748 | return false; |
| 1749 | __i = __xeq.second; |
| 1750 | } |
| 1751 | return true; |
| 1752 | } |
| 1753 | |
| 1754 | template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1755 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1756 | bool |
| 1757 | operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, |
| 1758 | const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) |
| 1759 | { |
| 1760 | return !(__x == __y); |
| 1761 | } |
| 1762 | |
| 1763 | _LIBCPP_END_NAMESPACE_STD |
| 1764 | |
| 1765 | #endif // _LIBCPP_UNORDERED_MAP |