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