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 <__algorithm/is_permutation.h> 463#include <__assert> 464#include <__config> 465#include <__debug> 466#include <__functional/is_transparent.h> 467#include <__hash_table> 468#include <__memory/addressof.h> 469#include <__node_handle> 470#include <__utility/forward.h> 471#include <compare> 472#include <functional> 473#include <iterator> // __libcpp_erase_if_container 474#include <version> 475 476#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 477# pragma GCC system_header 478#endif 479 480_LIBCPP_BEGIN_NAMESPACE_STD 481 482template <class _Value, class _Hash, class _Pred, class _Alloc> 483class unordered_multiset; 484 485template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, 486 class _Alloc = allocator<_Value> > 487class _LIBCPP_TEMPLATE_VIS unordered_set 488{ 489public: 490 // types 491 typedef _Value key_type; 492 typedef key_type value_type; 493 typedef __identity_t<_Hash> hasher; 494 typedef __identity_t<_Pred> key_equal; 495 typedef __identity_t<_Alloc> allocator_type; 496 typedef value_type& reference; 497 typedef const value_type& const_reference; 498 static_assert((is_same<value_type, typename allocator_type::value_type>::value), 499 "Invalid allocator::value_type"); 500 501private: 502 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; 503 504 __table __table_; 505 506public: 507 typedef typename __table::pointer pointer; 508 typedef typename __table::const_pointer const_pointer; 509 typedef typename __table::size_type size_type; 510 typedef typename __table::difference_type difference_type; 511 512 typedef typename __table::const_iterator iterator; 513 typedef typename __table::const_iterator const_iterator; 514 typedef typename __table::const_local_iterator local_iterator; 515 typedef typename __table::const_local_iterator const_local_iterator; 516 517#if _LIBCPP_STD_VER > 14 518 typedef __set_node_handle<typename __table::__node, allocator_type> node_type; 519 typedef __insert_return_type<iterator, node_type> insert_return_type; 520#endif 521 522 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 523 friend class _LIBCPP_TEMPLATE_VIS unordered_set; 524 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 525 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset; 526 527 _LIBCPP_INLINE_VISIBILITY 528 unordered_set() 529 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) 530 { 531 _VSTD::__debug_db_insert_c(this); 532 } 533 explicit unordered_set(size_type __n, const hasher& __hf = hasher(), 534 const key_equal& __eql = key_equal()); 535#if _LIBCPP_STD_VER > 11 536 inline _LIBCPP_INLINE_VISIBILITY 537 unordered_set(size_type __n, const allocator_type& __a) 538 : unordered_set(__n, hasher(), key_equal(), __a) {} 539 inline _LIBCPP_INLINE_VISIBILITY 540 unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a) 541 : unordered_set(__n, __hf, key_equal(), __a) {} 542#endif 543 unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql, 544 const allocator_type& __a); 545 template <class _InputIterator> 546 unordered_set(_InputIterator __first, _InputIterator __last); 547 template <class _InputIterator> 548 unordered_set(_InputIterator __first, _InputIterator __last, 549 size_type __n, const hasher& __hf = hasher(), 550 const key_equal& __eql = key_equal()); 551 template <class _InputIterator> 552 unordered_set(_InputIterator __first, _InputIterator __last, 553 size_type __n, const hasher& __hf, const key_equal& __eql, 554 const allocator_type& __a); 555#if _LIBCPP_STD_VER > 11 556 template <class _InputIterator> 557 inline _LIBCPP_INLINE_VISIBILITY 558 unordered_set(_InputIterator __first, _InputIterator __last, 559 size_type __n, const allocator_type& __a) 560 : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {} 561 template <class _InputIterator> 562 unordered_set(_InputIterator __first, _InputIterator __last, 563 size_type __n, const hasher& __hf, const allocator_type& __a) 564 : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {} 565#endif 566 _LIBCPP_INLINE_VISIBILITY 567 explicit unordered_set(const allocator_type& __a); 568 unordered_set(const unordered_set& __u); 569 unordered_set(const unordered_set& __u, const allocator_type& __a); 570#ifndef _LIBCPP_CXX03_LANG 571 _LIBCPP_INLINE_VISIBILITY 572 unordered_set(unordered_set&& __u) 573 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); 574 unordered_set(unordered_set&& __u, const allocator_type& __a); 575 unordered_set(initializer_list<value_type> __il); 576 unordered_set(initializer_list<value_type> __il, size_type __n, 577 const hasher& __hf = hasher(), 578 const key_equal& __eql = key_equal()); 579 unordered_set(initializer_list<value_type> __il, size_type __n, 580 const hasher& __hf, const key_equal& __eql, 581 const allocator_type& __a); 582#if _LIBCPP_STD_VER > 11 583 inline _LIBCPP_INLINE_VISIBILITY 584 unordered_set(initializer_list<value_type> __il, size_type __n, 585 const allocator_type& __a) 586 : unordered_set(__il, __n, hasher(), key_equal(), __a) {} 587 inline _LIBCPP_INLINE_VISIBILITY 588 unordered_set(initializer_list<value_type> __il, size_type __n, 589 const hasher& __hf, const allocator_type& __a) 590 : unordered_set(__il, __n, __hf, key_equal(), __a) {} 591#endif 592#endif // _LIBCPP_CXX03_LANG 593 _LIBCPP_INLINE_VISIBILITY 594 ~unordered_set() { 595 static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); 596 } 597 598 _LIBCPP_INLINE_VISIBILITY 599 unordered_set& operator=(const unordered_set& __u) 600 { 601 __table_ = __u.__table_; 602 return *this; 603 } 604#ifndef _LIBCPP_CXX03_LANG 605 _LIBCPP_INLINE_VISIBILITY 606 unordered_set& operator=(unordered_set&& __u) 607 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); 608 _LIBCPP_INLINE_VISIBILITY 609 unordered_set& operator=(initializer_list<value_type> __il); 610#endif // _LIBCPP_CXX03_LANG 611 612 _LIBCPP_INLINE_VISIBILITY 613 allocator_type get_allocator() const _NOEXCEPT 614 {return allocator_type(__table_.__node_alloc());} 615 616 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 617 bool empty() const _NOEXCEPT {return __table_.size() == 0;} 618 _LIBCPP_INLINE_VISIBILITY 619 size_type size() const _NOEXCEPT {return __table_.size();} 620 _LIBCPP_INLINE_VISIBILITY 621 size_type max_size() const _NOEXCEPT {return __table_.max_size();} 622 623 _LIBCPP_INLINE_VISIBILITY 624 iterator begin() _NOEXCEPT {return __table_.begin();} 625 _LIBCPP_INLINE_VISIBILITY 626 iterator end() _NOEXCEPT {return __table_.end();} 627 _LIBCPP_INLINE_VISIBILITY 628 const_iterator begin() const _NOEXCEPT {return __table_.begin();} 629 _LIBCPP_INLINE_VISIBILITY 630 const_iterator end() const _NOEXCEPT {return __table_.end();} 631 _LIBCPP_INLINE_VISIBILITY 632 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} 633 _LIBCPP_INLINE_VISIBILITY 634 const_iterator cend() const _NOEXCEPT {return __table_.end();} 635 636#ifndef _LIBCPP_CXX03_LANG 637 template <class... _Args> 638 _LIBCPP_INLINE_VISIBILITY 639 pair<iterator, bool> emplace(_Args&&... __args) 640 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);} 641 template <class... _Args> 642 _LIBCPP_INLINE_VISIBILITY 643#if _LIBCPP_DEBUG_LEVEL == 2 644 iterator emplace_hint(const_iterator __p, _Args&&... __args) 645 { 646 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 647 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not" 648 " referring to this unordered_set"); 649 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first; 650 } 651#else 652 iterator emplace_hint(const_iterator, _Args&&... __args) 653 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;} 654#endif 655 656 _LIBCPP_INLINE_VISIBILITY 657 pair<iterator, bool> insert(value_type&& __x) 658 {return __table_.__insert_unique(_VSTD::move(__x));} 659 _LIBCPP_INLINE_VISIBILITY 660#if _LIBCPP_DEBUG_LEVEL == 2 661 iterator insert(const_iterator __p, value_type&& __x) 662 { 663 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 664 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not" 665 " referring to this unordered_set"); 666 return insert(_VSTD::move(__x)).first; 667 } 668#else 669 iterator insert(const_iterator, value_type&& __x) 670 {return insert(_VSTD::move(__x)).first;} 671#endif 672 _LIBCPP_INLINE_VISIBILITY 673 void insert(initializer_list<value_type> __il) 674 {insert(__il.begin(), __il.end());} 675#endif // _LIBCPP_CXX03_LANG 676 _LIBCPP_INLINE_VISIBILITY 677 pair<iterator, bool> insert(const value_type& __x) 678 {return __table_.__insert_unique(__x);} 679 680 _LIBCPP_INLINE_VISIBILITY 681#if _LIBCPP_DEBUG_LEVEL == 2 682 iterator insert(const_iterator __p, const value_type& __x) 683 { 684 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 685 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not" 686 " referring to this unordered_set"); 687 return insert(__x).first; 688 } 689#else 690 iterator insert(const_iterator, const value_type& __x) 691 {return insert(__x).first;} 692#endif 693 template <class _InputIterator> 694 _LIBCPP_INLINE_VISIBILITY 695 void insert(_InputIterator __first, _InputIterator __last); 696 697 _LIBCPP_INLINE_VISIBILITY 698 iterator erase(const_iterator __p) {return __table_.erase(__p);} 699 _LIBCPP_INLINE_VISIBILITY 700 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} 701 _LIBCPP_INLINE_VISIBILITY 702 iterator erase(const_iterator __first, const_iterator __last) 703 {return __table_.erase(__first, __last);} 704 _LIBCPP_INLINE_VISIBILITY 705 void clear() _NOEXCEPT {__table_.clear();} 706 707#if _LIBCPP_STD_VER > 14 708 _LIBCPP_INLINE_VISIBILITY 709 insert_return_type insert(node_type&& __nh) 710 { 711 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 712 "node_type with incompatible allocator passed to unordered_set::insert()"); 713 return __table_.template __node_handle_insert_unique< 714 node_type, insert_return_type>(_VSTD::move(__nh)); 715 } 716 _LIBCPP_INLINE_VISIBILITY 717 iterator insert(const_iterator __h, node_type&& __nh) 718 { 719 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 720 "node_type with incompatible allocator passed to unordered_set::insert()"); 721 return __table_.template __node_handle_insert_unique<node_type>( 722 __h, _VSTD::move(__nh)); 723 } 724 _LIBCPP_INLINE_VISIBILITY 725 node_type extract(key_type const& __key) 726 { 727 return __table_.template __node_handle_extract<node_type>(__key); 728 } 729 _LIBCPP_INLINE_VISIBILITY 730 node_type extract(const_iterator __it) 731 { 732 return __table_.template __node_handle_extract<node_type>(__it); 733 } 734 735 template<class _H2, class _P2> 736 _LIBCPP_INLINE_VISIBILITY 737 void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source) 738 { 739 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 740 "merging container with incompatible allocator"); 741 __table_.__node_handle_merge_unique(__source.__table_); 742 } 743 template<class _H2, class _P2> 744 _LIBCPP_INLINE_VISIBILITY 745 void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source) 746 { 747 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 748 "merging container with incompatible allocator"); 749 __table_.__node_handle_merge_unique(__source.__table_); 750 } 751 template<class _H2, class _P2> 752 _LIBCPP_INLINE_VISIBILITY 753 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source) 754 { 755 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 756 "merging container with incompatible allocator"); 757 __table_.__node_handle_merge_unique(__source.__table_); 758 } 759 template<class _H2, class _P2> 760 _LIBCPP_INLINE_VISIBILITY 761 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source) 762 { 763 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 764 "merging container with incompatible allocator"); 765 __table_.__node_handle_merge_unique(__source.__table_); 766 } 767#endif 768 769 _LIBCPP_INLINE_VISIBILITY 770 void swap(unordered_set& __u) 771 _NOEXCEPT_(__is_nothrow_swappable<__table>::value) 772 {__table_.swap(__u.__table_);} 773 774 _LIBCPP_INLINE_VISIBILITY 775 hasher hash_function() const {return __table_.hash_function();} 776 _LIBCPP_INLINE_VISIBILITY 777 key_equal key_eq() const {return __table_.key_eq();} 778 779 _LIBCPP_INLINE_VISIBILITY 780 iterator find(const key_type& __k) {return __table_.find(__k);} 781 _LIBCPP_INLINE_VISIBILITY 782 const_iterator find(const key_type& __k) const {return __table_.find(__k);} 783#if _LIBCPP_STD_VER > 17 784 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 785 _LIBCPP_INLINE_VISIBILITY 786 iterator find(const _K2& __k) {return __table_.find(__k);} 787 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 788 _LIBCPP_INLINE_VISIBILITY 789 const_iterator find(const _K2& __k) const {return __table_.find(__k);} 790#endif // _LIBCPP_STD_VER > 17 791 792 _LIBCPP_INLINE_VISIBILITY 793 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} 794#if _LIBCPP_STD_VER > 17 795 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 796 _LIBCPP_INLINE_VISIBILITY 797 size_type count(const _K2& __k) const {return __table_.__count_unique(__k);} 798#endif // _LIBCPP_STD_VER > 17 799 800#if _LIBCPP_STD_VER > 17 801 _LIBCPP_INLINE_VISIBILITY 802 bool contains(const key_type& __k) const {return find(__k) != end();} 803 804 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 805 _LIBCPP_INLINE_VISIBILITY 806 bool contains(const _K2& __k) const {return find(__k) != end();} 807#endif // _LIBCPP_STD_VER > 17 808 809 _LIBCPP_INLINE_VISIBILITY 810 pair<iterator, iterator> equal_range(const key_type& __k) 811 {return __table_.__equal_range_unique(__k);} 812 _LIBCPP_INLINE_VISIBILITY 813 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const 814 {return __table_.__equal_range_unique(__k);} 815#if _LIBCPP_STD_VER > 17 816 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 817 _LIBCPP_INLINE_VISIBILITY 818 pair<iterator, iterator> equal_range(const _K2& __k) 819 {return __table_.__equal_range_unique(__k);} 820 template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 821 _LIBCPP_INLINE_VISIBILITY 822 pair<const_iterator, const_iterator> equal_range(const _K2& __k) const 823 {return __table_.__equal_range_unique(__k);} 824#endif // _LIBCPP_STD_VER > 17 825 826 _LIBCPP_INLINE_VISIBILITY 827 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} 828 _LIBCPP_INLINE_VISIBILITY 829 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} 830 831 _LIBCPP_INLINE_VISIBILITY 832 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);} 833 _LIBCPP_INLINE_VISIBILITY 834 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} 835 836 _LIBCPP_INLINE_VISIBILITY 837 local_iterator begin(size_type __n) {return __table_.begin(__n);} 838 _LIBCPP_INLINE_VISIBILITY 839 local_iterator end(size_type __n) {return __table_.end(__n);} 840 _LIBCPP_INLINE_VISIBILITY 841 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} 842 _LIBCPP_INLINE_VISIBILITY 843 const_local_iterator end(size_type __n) const {return __table_.cend(__n);} 844 _LIBCPP_INLINE_VISIBILITY 845 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} 846 _LIBCPP_INLINE_VISIBILITY 847 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} 848 849 _LIBCPP_INLINE_VISIBILITY 850 float load_factor() const _NOEXCEPT {return __table_.load_factor();} 851 _LIBCPP_INLINE_VISIBILITY 852 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} 853 _LIBCPP_INLINE_VISIBILITY 854 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} 855 _LIBCPP_INLINE_VISIBILITY 856 void rehash(size_type __n) {__table_.rehash(__n);} 857 _LIBCPP_INLINE_VISIBILITY 858 void reserve(size_type __n) {__table_.reserve(__n);} 859 860#if _LIBCPP_DEBUG_LEVEL == 2 861 862 bool __dereferenceable(const const_iterator* __i) const 863 {return __table_.__dereferenceable(__i);} 864 bool __decrementable(const const_iterator* __i) const 865 {return __table_.__decrementable(__i);} 866 bool __addable(const const_iterator* __i, ptrdiff_t __n) const 867 {return __table_.__addable(__i, __n);} 868 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const 869 {return __table_.__addable(__i, __n);} 870 871#endif // _LIBCPP_DEBUG_LEVEL == 2 872 873}; 874 875#if _LIBCPP_STD_VER >= 17 876template<class _InputIterator, 877 class _Hash = hash<__iter_value_type<_InputIterator>>, 878 class _Pred = equal_to<__iter_value_type<_InputIterator>>, 879 class _Allocator = allocator<__iter_value_type<_InputIterator>>, 880 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 881 class = enable_if_t<!__is_allocator<_Hash>::value>, 882 class = enable_if_t<!is_integral<_Hash>::value>, 883 class = enable_if_t<!__is_allocator<_Pred>::value>, 884 class = enable_if_t<__is_allocator<_Allocator>::value>> 885unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, 886 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) 887 -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>; 888 889template<class _Tp, class _Hash = hash<_Tp>, 890 class _Pred = equal_to<_Tp>, 891 class _Allocator = allocator<_Tp>, 892 class = enable_if_t<!__is_allocator<_Hash>::value>, 893 class = enable_if_t<!is_integral<_Hash>::value>, 894 class = enable_if_t<!__is_allocator<_Pred>::value>, 895 class = enable_if_t<__is_allocator<_Allocator>::value>> 896unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0, 897 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) 898 -> unordered_set<_Tp, _Hash, _Pred, _Allocator>; 899 900template<class _InputIterator, class _Allocator, 901 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 902 class = enable_if_t<__is_allocator<_Allocator>::value>> 903unordered_set(_InputIterator, _InputIterator, 904 typename allocator_traits<_Allocator>::size_type, _Allocator) 905 -> unordered_set<__iter_value_type<_InputIterator>, 906 hash<__iter_value_type<_InputIterator>>, 907 equal_to<__iter_value_type<_InputIterator>>, 908 _Allocator>; 909 910template<class _InputIterator, class _Hash, class _Allocator, 911 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 912 class = enable_if_t<!__is_allocator<_Hash>::value>, 913 class = enable_if_t<!is_integral<_Hash>::value>, 914 class = enable_if_t<__is_allocator<_Allocator>::value>> 915unordered_set(_InputIterator, _InputIterator, 916 typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) 917 -> unordered_set<__iter_value_type<_InputIterator>, _Hash, 918 equal_to<__iter_value_type<_InputIterator>>, 919 _Allocator>; 920 921template<class _Tp, class _Allocator, 922 class = enable_if_t<__is_allocator<_Allocator>::value>> 923unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator) 924 -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>; 925 926template<class _Tp, class _Hash, class _Allocator, 927 class = enable_if_t<!__is_allocator<_Hash>::value>, 928 class = enable_if_t<!is_integral<_Hash>::value>, 929 class = enable_if_t<__is_allocator<_Allocator>::value>> 930unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) 931 -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>; 932#endif 933 934template <class _Value, class _Hash, class _Pred, class _Alloc> 935unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n, 936 const hasher& __hf, const key_equal& __eql) 937 : __table_(__hf, __eql) 938{ 939 _VSTD::__debug_db_insert_c(this); 940 __table_.rehash(__n); 941} 942 943template <class _Value, class _Hash, class _Pred, class _Alloc> 944unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n, 945 const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 946 : __table_(__hf, __eql, __a) 947{ 948 _VSTD::__debug_db_insert_c(this); 949 __table_.rehash(__n); 950} 951 952template <class _Value, class _Hash, class _Pred, class _Alloc> 953template <class _InputIterator> 954unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 955 _InputIterator __first, _InputIterator __last) 956{ 957 _VSTD::__debug_db_insert_c(this); 958 insert(__first, __last); 959} 960 961template <class _Value, class _Hash, class _Pred, class _Alloc> 962template <class _InputIterator> 963unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 964 _InputIterator __first, _InputIterator __last, size_type __n, 965 const hasher& __hf, const key_equal& __eql) 966 : __table_(__hf, __eql) 967{ 968 _VSTD::__debug_db_insert_c(this); 969 __table_.rehash(__n); 970 insert(__first, __last); 971} 972 973template <class _Value, class _Hash, class _Pred, class _Alloc> 974template <class _InputIterator> 975unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 976 _InputIterator __first, _InputIterator __last, size_type __n, 977 const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 978 : __table_(__hf, __eql, __a) 979{ 980 _VSTD::__debug_db_insert_c(this); 981 __table_.rehash(__n); 982 insert(__first, __last); 983} 984 985template <class _Value, class _Hash, class _Pred, class _Alloc> 986inline 987unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 988 const allocator_type& __a) 989 : __table_(__a) 990{ 991 _VSTD::__debug_db_insert_c(this); 992} 993 994template <class _Value, class _Hash, class _Pred, class _Alloc> 995unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 996 const unordered_set& __u) 997 : __table_(__u.__table_) 998{ 999 _VSTD::__debug_db_insert_c(this); 1000 __table_.rehash(__u.bucket_count()); 1001 insert(__u.begin(), __u.end()); 1002} 1003 1004template <class _Value, class _Hash, class _Pred, class _Alloc> 1005unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1006 const unordered_set& __u, const allocator_type& __a) 1007 : __table_(__u.__table_, __a) 1008{ 1009 _VSTD::__debug_db_insert_c(this); 1010 __table_.rehash(__u.bucket_count()); 1011 insert(__u.begin(), __u.end()); 1012} 1013 1014#ifndef _LIBCPP_CXX03_LANG 1015 1016template <class _Value, class _Hash, class _Pred, class _Alloc> 1017inline 1018unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1019 unordered_set&& __u) 1020 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) 1021 : __table_(_VSTD::move(__u.__table_)) 1022{ 1023 _VSTD::__debug_db_insert_c(this); 1024#if _LIBCPP_DEBUG_LEVEL == 2 1025 __get_db()->swap(this, _VSTD::addressof(__u)); 1026#endif 1027} 1028 1029template <class _Value, class _Hash, class _Pred, class _Alloc> 1030unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1031 unordered_set&& __u, const allocator_type& __a) 1032 : __table_(_VSTD::move(__u.__table_), __a) 1033{ 1034 _VSTD::__debug_db_insert_c(this); 1035 if (__a != __u.get_allocator()) 1036 { 1037 iterator __i = __u.begin(); 1038 while (__u.size() != 0) 1039 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_)); 1040 } 1041#if _LIBCPP_DEBUG_LEVEL == 2 1042 else 1043 __get_db()->swap(this, _VSTD::addressof(__u)); 1044#endif 1045} 1046 1047template <class _Value, class _Hash, class _Pred, class _Alloc> 1048unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1049 initializer_list<value_type> __il) 1050{ 1051 _VSTD::__debug_db_insert_c(this); 1052 insert(__il.begin(), __il.end()); 1053} 1054 1055template <class _Value, class _Hash, class _Pred, class _Alloc> 1056unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1057 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1058 const key_equal& __eql) 1059 : __table_(__hf, __eql) 1060{ 1061 _VSTD::__debug_db_insert_c(this); 1062 __table_.rehash(__n); 1063 insert(__il.begin(), __il.end()); 1064} 1065 1066template <class _Value, class _Hash, class _Pred, class _Alloc> 1067unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1068 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1069 const key_equal& __eql, const allocator_type& __a) 1070 : __table_(__hf, __eql, __a) 1071{ 1072 _VSTD::__debug_db_insert_c(this); 1073 __table_.rehash(__n); 1074 insert(__il.begin(), __il.end()); 1075} 1076 1077template <class _Value, class _Hash, class _Pred, class _Alloc> 1078inline 1079unordered_set<_Value, _Hash, _Pred, _Alloc>& 1080unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u) 1081 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) 1082{ 1083 __table_ = _VSTD::move(__u.__table_); 1084 return *this; 1085} 1086 1087template <class _Value, class _Hash, class _Pred, class _Alloc> 1088inline 1089unordered_set<_Value, _Hash, _Pred, _Alloc>& 1090unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=( 1091 initializer_list<value_type> __il) 1092{ 1093 __table_.__assign_unique(__il.begin(), __il.end()); 1094 return *this; 1095} 1096 1097#endif // _LIBCPP_CXX03_LANG 1098 1099template <class _Value, class _Hash, class _Pred, class _Alloc> 1100template <class _InputIterator> 1101inline 1102void 1103unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 1104 _InputIterator __last) 1105{ 1106 for (; __first != __last; ++__first) 1107 __table_.__insert_unique(*__first); 1108} 1109 1110template <class _Value, class _Hash, class _Pred, class _Alloc> 1111inline _LIBCPP_INLINE_VISIBILITY 1112void 1113swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, 1114 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) 1115 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 1116{ 1117 __x.swap(__y); 1118} 1119 1120#if _LIBCPP_STD_VER > 17 1121template <class _Value, class _Hash, class _Pred, class _Alloc, 1122 class _Predicate> 1123inline _LIBCPP_INLINE_VISIBILITY 1124 typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type 1125 erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c, 1126 _Predicate __pred) { 1127 return _VSTD::__libcpp_erase_if_container(__c, __pred); 1128} 1129#endif 1130 1131template <class _Value, class _Hash, class _Pred, class _Alloc> 1132bool 1133operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, 1134 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) 1135{ 1136 if (__x.size() != __y.size()) 1137 return false; 1138 typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator 1139 const_iterator; 1140 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); 1141 __i != __ex; ++__i) 1142 { 1143 const_iterator __j = __y.find(*__i); 1144 if (__j == __ey || !(*__i == *__j)) 1145 return false; 1146 } 1147 return true; 1148} 1149 1150template <class _Value, class _Hash, class _Pred, class _Alloc> 1151inline _LIBCPP_INLINE_VISIBILITY 1152bool 1153operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, 1154 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) 1155{ 1156 return !(__x == __y); 1157} 1158 1159template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, 1160 class _Alloc = allocator<_Value> > 1161class _LIBCPP_TEMPLATE_VIS unordered_multiset 1162{ 1163public: 1164 // types 1165 typedef _Value key_type; 1166 typedef key_type value_type; 1167 typedef __identity_t<_Hash> hasher; 1168 typedef __identity_t<_Pred> key_equal; 1169 typedef __identity_t<_Alloc> allocator_type; 1170 typedef value_type& reference; 1171 typedef const value_type& const_reference; 1172 static_assert((is_same<value_type, typename allocator_type::value_type>::value), 1173 "Invalid allocator::value_type"); 1174 1175private: 1176 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; 1177 1178 __table __table_; 1179 1180public: 1181 typedef typename __table::pointer pointer; 1182 typedef typename __table::const_pointer const_pointer; 1183 typedef typename __table::size_type size_type; 1184 typedef typename __table::difference_type difference_type; 1185 1186 typedef typename __table::const_iterator iterator; 1187 typedef typename __table::const_iterator const_iterator; 1188 typedef typename __table::const_local_iterator local_iterator; 1189 typedef typename __table::const_local_iterator const_local_iterator; 1190 1191#if _LIBCPP_STD_VER > 14 1192 typedef __set_node_handle<typename __table::__node, allocator_type> node_type; 1193#endif 1194 1195 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 1196 friend class _LIBCPP_TEMPLATE_VIS unordered_set; 1197 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 1198 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset; 1199 1200 _LIBCPP_INLINE_VISIBILITY 1201 unordered_multiset() 1202 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) 1203 { 1204 _VSTD::__debug_db_insert_c(this); 1205 } 1206 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(), 1207 const key_equal& __eql = key_equal()); 1208 unordered_multiset(size_type __n, const hasher& __hf, 1209 const key_equal& __eql, const allocator_type& __a); 1210#if _LIBCPP_STD_VER > 11 1211 inline _LIBCPP_INLINE_VISIBILITY 1212 unordered_multiset(size_type __n, const allocator_type& __a) 1213 : unordered_multiset(__n, hasher(), key_equal(), __a) {} 1214 inline _LIBCPP_INLINE_VISIBILITY 1215 unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a) 1216 : unordered_multiset(__n, __hf, key_equal(), __a) {} 1217#endif 1218 template <class _InputIterator> 1219 unordered_multiset(_InputIterator __first, _InputIterator __last); 1220 template <class _InputIterator> 1221 unordered_multiset(_InputIterator __first, _InputIterator __last, 1222 size_type __n, const hasher& __hf = hasher(), 1223 const key_equal& __eql = key_equal()); 1224 template <class _InputIterator> 1225 unordered_multiset(_InputIterator __first, _InputIterator __last, 1226 size_type __n , const hasher& __hf, 1227 const key_equal& __eql, const allocator_type& __a); 1228#if _LIBCPP_STD_VER > 11 1229 template <class _InputIterator> 1230 inline _LIBCPP_INLINE_VISIBILITY 1231 unordered_multiset(_InputIterator __first, _InputIterator __last, 1232 size_type __n, const allocator_type& __a) 1233 : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {} 1234 template <class _InputIterator> 1235 inline _LIBCPP_INLINE_VISIBILITY 1236 unordered_multiset(_InputIterator __first, _InputIterator __last, 1237 size_type __n, const hasher& __hf, const allocator_type& __a) 1238 : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {} 1239#endif 1240 _LIBCPP_INLINE_VISIBILITY 1241 explicit unordered_multiset(const allocator_type& __a); 1242 unordered_multiset(const unordered_multiset& __u); 1243 unordered_multiset(const unordered_multiset& __u, const allocator_type& __a); 1244#ifndef _LIBCPP_CXX03_LANG 1245 _LIBCPP_INLINE_VISIBILITY 1246 unordered_multiset(unordered_multiset&& __u) 1247 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); 1248 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a); 1249 unordered_multiset(initializer_list<value_type> __il); 1250 unordered_multiset(initializer_list<value_type> __il, size_type __n, 1251 const hasher& __hf = hasher(), 1252 const key_equal& __eql = key_equal()); 1253 unordered_multiset(initializer_list<value_type> __il, size_type __n, 1254 const hasher& __hf, const key_equal& __eql, 1255 const allocator_type& __a); 1256#if _LIBCPP_STD_VER > 11 1257 inline _LIBCPP_INLINE_VISIBILITY 1258 unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) 1259 : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {} 1260 inline _LIBCPP_INLINE_VISIBILITY 1261 unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a) 1262 : unordered_multiset(__il, __n, __hf, key_equal(), __a) {} 1263#endif 1264#endif // _LIBCPP_CXX03_LANG 1265 _LIBCPP_INLINE_VISIBILITY 1266 ~unordered_multiset() { 1267 static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); 1268 } 1269 1270 _LIBCPP_INLINE_VISIBILITY 1271 unordered_multiset& operator=(const unordered_multiset& __u) 1272 { 1273 __table_ = __u.__table_; 1274 return *this; 1275 } 1276#ifndef _LIBCPP_CXX03_LANG 1277 _LIBCPP_INLINE_VISIBILITY 1278 unordered_multiset& operator=(unordered_multiset&& __u) 1279 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); 1280 unordered_multiset& operator=(initializer_list<value_type> __il); 1281#endif // _LIBCPP_CXX03_LANG 1282 1283 _LIBCPP_INLINE_VISIBILITY 1284 allocator_type get_allocator() const _NOEXCEPT 1285 {return allocator_type(__table_.__node_alloc());} 1286 1287 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 1288 bool empty() const _NOEXCEPT {return __table_.size() == 0;} 1289 _LIBCPP_INLINE_VISIBILITY 1290 size_type size() const _NOEXCEPT {return __table_.size();} 1291 _LIBCPP_INLINE_VISIBILITY 1292 size_type max_size() const _NOEXCEPT {return __table_.max_size();} 1293 1294 _LIBCPP_INLINE_VISIBILITY 1295 iterator begin() _NOEXCEPT {return __table_.begin();} 1296 _LIBCPP_INLINE_VISIBILITY 1297 iterator end() _NOEXCEPT {return __table_.end();} 1298 _LIBCPP_INLINE_VISIBILITY 1299 const_iterator begin() const _NOEXCEPT {return __table_.begin();} 1300 _LIBCPP_INLINE_VISIBILITY 1301 const_iterator end() const _NOEXCEPT {return __table_.end();} 1302 _LIBCPP_INLINE_VISIBILITY 1303 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} 1304 _LIBCPP_INLINE_VISIBILITY 1305 const_iterator cend() const _NOEXCEPT {return __table_.end();} 1306 1307#ifndef _LIBCPP_CXX03_LANG 1308 template <class... _Args> 1309 _LIBCPP_INLINE_VISIBILITY 1310 iterator emplace(_Args&&... __args) 1311 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);} 1312 template <class... _Args> 1313 _LIBCPP_INLINE_VISIBILITY 1314 iterator emplace_hint(const_iterator __p, _Args&&... __args) 1315 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);} 1316 1317 _LIBCPP_INLINE_VISIBILITY 1318 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));} 1319 _LIBCPP_INLINE_VISIBILITY 1320 iterator insert(const_iterator __p, value_type&& __x) 1321 {return __table_.__insert_multi(__p, _VSTD::move(__x));} 1322 _LIBCPP_INLINE_VISIBILITY 1323 void insert(initializer_list<value_type> __il) 1324 {insert(__il.begin(), __il.end());} 1325#endif // _LIBCPP_CXX03_LANG 1326 1327 _LIBCPP_INLINE_VISIBILITY 1328 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} 1329 1330 _LIBCPP_INLINE_VISIBILITY 1331 iterator insert(const_iterator __p, const value_type& __x) 1332 {return __table_.__insert_multi(__p, __x);} 1333 1334 template <class _InputIterator> 1335 _LIBCPP_INLINE_VISIBILITY 1336 void insert(_InputIterator __first, _InputIterator __last); 1337 1338#if _LIBCPP_STD_VER > 14 1339 _LIBCPP_INLINE_VISIBILITY 1340 iterator insert(node_type&& __nh) 1341 { 1342 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 1343 "node_type with incompatible allocator passed to unordered_multiset::insert()"); 1344 return __table_.template __node_handle_insert_multi<node_type>( 1345 _VSTD::move(__nh)); 1346 } 1347 _LIBCPP_INLINE_VISIBILITY 1348 iterator insert(const_iterator __hint, node_type&& __nh) 1349 { 1350 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 1351 "node_type with incompatible allocator passed to unordered_multiset::insert()"); 1352 return __table_.template __node_handle_insert_multi<node_type>( 1353 __hint, _VSTD::move(__nh)); 1354 } 1355 _LIBCPP_INLINE_VISIBILITY 1356 node_type extract(const_iterator __position) 1357 { 1358 return __table_.template __node_handle_extract<node_type>( 1359 __position); 1360 } 1361 _LIBCPP_INLINE_VISIBILITY 1362 node_type extract(key_type const& __key) 1363 { 1364 return __table_.template __node_handle_extract<node_type>(__key); 1365 } 1366 1367 template <class _H2, class _P2> 1368 _LIBCPP_INLINE_VISIBILITY 1369 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source) 1370 { 1371 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1372 "merging container with incompatible allocator"); 1373 return __table_.__node_handle_merge_multi(__source.__table_); 1374 } 1375 template <class _H2, class _P2> 1376 _LIBCPP_INLINE_VISIBILITY 1377 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source) 1378 { 1379 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1380 "merging container with incompatible allocator"); 1381 return __table_.__node_handle_merge_multi(__source.__table_); 1382 } 1383 template <class _H2, class _P2> 1384 _LIBCPP_INLINE_VISIBILITY 1385 void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source) 1386 { 1387 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1388 "merging container with incompatible allocator"); 1389 return __table_.__node_handle_merge_multi(__source.__table_); 1390 } 1391 template <class _H2, class _P2> 1392 _LIBCPP_INLINE_VISIBILITY 1393 void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source) 1394 { 1395 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1396 "merging container with incompatible allocator"); 1397 return __table_.__node_handle_merge_multi(__source.__table_); 1398 } 1399#endif 1400 1401 _LIBCPP_INLINE_VISIBILITY 1402 iterator erase(const_iterator __p) {return __table_.erase(__p);} 1403 _LIBCPP_INLINE_VISIBILITY 1404 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} 1405 _LIBCPP_INLINE_VISIBILITY 1406 iterator erase(const_iterator __first, const_iterator __last) 1407 {return __table_.erase(__first, __last);} 1408 _LIBCPP_INLINE_VISIBILITY 1409 void clear() _NOEXCEPT {__table_.clear();} 1410 1411 _LIBCPP_INLINE_VISIBILITY 1412 void swap(unordered_multiset& __u) 1413 _NOEXCEPT_(__is_nothrow_swappable<__table>::value) 1414 {__table_.swap(__u.__table_);} 1415 1416 _LIBCPP_INLINE_VISIBILITY 1417 hasher hash_function() const {return __table_.hash_function();} 1418 _LIBCPP_INLINE_VISIBILITY 1419 key_equal key_eq() const {return __table_.key_eq();} 1420 1421 _LIBCPP_INLINE_VISIBILITY 1422 iterator find(const key_type& __k) {return __table_.find(__k);} 1423 _LIBCPP_INLINE_VISIBILITY 1424 const_iterator find(const key_type& __k) const {return __table_.find(__k);} 1425#if _LIBCPP_STD_VER > 17 1426 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1427 _LIBCPP_INLINE_VISIBILITY 1428 iterator find(const _K2& __k) {return __table_.find(__k);} 1429 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1430 _LIBCPP_INLINE_VISIBILITY 1431 const_iterator find(const _K2& __k) const {return __table_.find(__k);} 1432#endif // _LIBCPP_STD_VER > 17 1433 1434 _LIBCPP_INLINE_VISIBILITY 1435 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} 1436#if _LIBCPP_STD_VER > 17 1437 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1438 _LIBCPP_INLINE_VISIBILITY 1439 size_type count(const _K2& __k) const {return __table_.__count_multi(__k);} 1440#endif // _LIBCPP_STD_VER > 17 1441 1442#if _LIBCPP_STD_VER > 17 1443 _LIBCPP_INLINE_VISIBILITY 1444 bool contains(const key_type& __k) const {return find(__k) != end();} 1445 1446 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1447 _LIBCPP_INLINE_VISIBILITY 1448 bool contains(const _K2& __k) const {return find(__k) != end();} 1449#endif // _LIBCPP_STD_VER > 17 1450 1451 _LIBCPP_INLINE_VISIBILITY 1452 pair<iterator, iterator> equal_range(const key_type& __k) 1453 {return __table_.__equal_range_multi(__k);} 1454 _LIBCPP_INLINE_VISIBILITY 1455 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const 1456 {return __table_.__equal_range_multi(__k);} 1457#if _LIBCPP_STD_VER > 17 1458 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1459 _LIBCPP_INLINE_VISIBILITY 1460 pair<iterator, iterator> equal_range(const _K2& __k) 1461 {return __table_.__equal_range_multi(__k);} 1462 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1463 _LIBCPP_INLINE_VISIBILITY 1464 pair<const_iterator, const_iterator> equal_range(const _K2& __k) const 1465 {return __table_.__equal_range_multi(__k);} 1466#endif // _LIBCPP_STD_VER > 17 1467 1468 _LIBCPP_INLINE_VISIBILITY 1469 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} 1470 _LIBCPP_INLINE_VISIBILITY 1471 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} 1472 1473 _LIBCPP_INLINE_VISIBILITY 1474 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);} 1475 _LIBCPP_INLINE_VISIBILITY 1476 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} 1477 1478 _LIBCPP_INLINE_VISIBILITY 1479 local_iterator begin(size_type __n) {return __table_.begin(__n);} 1480 _LIBCPP_INLINE_VISIBILITY 1481 local_iterator end(size_type __n) {return __table_.end(__n);} 1482 _LIBCPP_INLINE_VISIBILITY 1483 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} 1484 _LIBCPP_INLINE_VISIBILITY 1485 const_local_iterator end(size_type __n) const {return __table_.cend(__n);} 1486 _LIBCPP_INLINE_VISIBILITY 1487 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} 1488 _LIBCPP_INLINE_VISIBILITY 1489 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} 1490 1491 _LIBCPP_INLINE_VISIBILITY 1492 float load_factor() const _NOEXCEPT {return __table_.load_factor();} 1493 _LIBCPP_INLINE_VISIBILITY 1494 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} 1495 _LIBCPP_INLINE_VISIBILITY 1496 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} 1497 _LIBCPP_INLINE_VISIBILITY 1498 void rehash(size_type __n) {__table_.rehash(__n);} 1499 _LIBCPP_INLINE_VISIBILITY 1500 void reserve(size_type __n) {__table_.reserve(__n);} 1501 1502#if _LIBCPP_DEBUG_LEVEL == 2 1503 1504 bool __dereferenceable(const const_iterator* __i) const 1505 {return __table_.__dereferenceable(__i);} 1506 bool __decrementable(const const_iterator* __i) const 1507 {return __table_.__decrementable(__i);} 1508 bool __addable(const const_iterator* __i, ptrdiff_t __n) const 1509 {return __table_.__addable(__i, __n);} 1510 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const 1511 {return __table_.__addable(__i, __n);} 1512 1513#endif // _LIBCPP_DEBUG_LEVEL == 2 1514 1515}; 1516 1517#if _LIBCPP_STD_VER >= 17 1518template<class _InputIterator, 1519 class _Hash = hash<__iter_value_type<_InputIterator>>, 1520 class _Pred = equal_to<__iter_value_type<_InputIterator>>, 1521 class _Allocator = allocator<__iter_value_type<_InputIterator>>, 1522 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1523 class = enable_if_t<!__is_allocator<_Hash>::value>, 1524 class = enable_if_t<!is_integral<_Hash>::value>, 1525 class = enable_if_t<!__is_allocator<_Pred>::value>, 1526 class = enable_if_t<__is_allocator<_Allocator>::value>> 1527unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, 1528 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) 1529 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>; 1530 1531template<class _Tp, class _Hash = hash<_Tp>, 1532 class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>, 1533 class = enable_if_t<!__is_allocator<_Hash>::value>, 1534 class = enable_if_t<!is_integral<_Hash>::value>, 1535 class = enable_if_t<!__is_allocator<_Pred>::value>, 1536 class = enable_if_t<__is_allocator<_Allocator>::value>> 1537unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0, 1538 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) 1539 -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>; 1540 1541template<class _InputIterator, class _Allocator, 1542 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1543 class = enable_if_t<__is_allocator<_Allocator>::value>> 1544unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) 1545 -> unordered_multiset<__iter_value_type<_InputIterator>, 1546 hash<__iter_value_type<_InputIterator>>, 1547 equal_to<__iter_value_type<_InputIterator>>, 1548 _Allocator>; 1549 1550template<class _InputIterator, class _Hash, class _Allocator, 1551 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1552 class = enable_if_t<!__is_allocator<_Hash>::value>, 1553 class = enable_if_t<!is_integral<_Hash>::value>, 1554 class = enable_if_t<__is_allocator<_Allocator>::value>> 1555unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, 1556 _Hash, _Allocator) 1557 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, 1558 equal_to<__iter_value_type<_InputIterator>>, 1559 _Allocator>; 1560 1561template<class _Tp, class _Allocator, 1562 class = enable_if_t<__is_allocator<_Allocator>::value>> 1563unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator) 1564 -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>; 1565 1566template<class _Tp, class _Hash, class _Allocator, 1567 class = enable_if_t<!__is_allocator<_Hash>::value>, 1568 class = enable_if_t<!is_integral<_Hash>::value>, 1569 class = enable_if_t<__is_allocator<_Allocator>::value>> 1570unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) 1571 -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>; 1572#endif 1573 1574template <class _Value, class _Hash, class _Pred, class _Alloc> 1575unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1576 size_type __n, const hasher& __hf, const key_equal& __eql) 1577 : __table_(__hf, __eql) 1578{ 1579 _VSTD::__debug_db_insert_c(this); 1580 __table_.rehash(__n); 1581} 1582 1583template <class _Value, class _Hash, class _Pred, class _Alloc> 1584unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1585 size_type __n, const hasher& __hf, const key_equal& __eql, 1586 const allocator_type& __a) 1587 : __table_(__hf, __eql, __a) 1588{ 1589 _VSTD::__debug_db_insert_c(this); 1590 __table_.rehash(__n); 1591} 1592 1593template <class _Value, class _Hash, class _Pred, class _Alloc> 1594template <class _InputIterator> 1595unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1596 _InputIterator __first, _InputIterator __last) 1597{ 1598 _VSTD::__debug_db_insert_c(this); 1599 insert(__first, __last); 1600} 1601 1602template <class _Value, class _Hash, class _Pred, class _Alloc> 1603template <class _InputIterator> 1604unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1605 _InputIterator __first, _InputIterator __last, size_type __n, 1606 const hasher& __hf, const key_equal& __eql) 1607 : __table_(__hf, __eql) 1608{ 1609 _VSTD::__debug_db_insert_c(this); 1610 __table_.rehash(__n); 1611 insert(__first, __last); 1612} 1613 1614template <class _Value, class _Hash, class _Pred, class _Alloc> 1615template <class _InputIterator> 1616unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1617 _InputIterator __first, _InputIterator __last, size_type __n, 1618 const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 1619 : __table_(__hf, __eql, __a) 1620{ 1621 _VSTD::__debug_db_insert_c(this); 1622 __table_.rehash(__n); 1623 insert(__first, __last); 1624} 1625 1626template <class _Value, class _Hash, class _Pred, class _Alloc> 1627inline 1628unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1629 const allocator_type& __a) 1630 : __table_(__a) 1631{ 1632 _VSTD::__debug_db_insert_c(this); 1633} 1634 1635template <class _Value, class _Hash, class _Pred, class _Alloc> 1636unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1637 const unordered_multiset& __u) 1638 : __table_(__u.__table_) 1639{ 1640 _VSTD::__debug_db_insert_c(this); 1641 __table_.rehash(__u.bucket_count()); 1642 insert(__u.begin(), __u.end()); 1643} 1644 1645template <class _Value, class _Hash, class _Pred, class _Alloc> 1646unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1647 const unordered_multiset& __u, const allocator_type& __a) 1648 : __table_(__u.__table_, __a) 1649{ 1650 _VSTD::__debug_db_insert_c(this); 1651 __table_.rehash(__u.bucket_count()); 1652 insert(__u.begin(), __u.end()); 1653} 1654 1655#ifndef _LIBCPP_CXX03_LANG 1656 1657template <class _Value, class _Hash, class _Pred, class _Alloc> 1658inline 1659unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1660 unordered_multiset&& __u) 1661 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) 1662 : __table_(_VSTD::move(__u.__table_)) 1663{ 1664 _VSTD::__debug_db_insert_c(this); 1665#if _LIBCPP_DEBUG_LEVEL == 2 1666 __get_db()->swap(this, _VSTD::addressof(__u)); 1667#endif 1668} 1669 1670template <class _Value, class _Hash, class _Pred, class _Alloc> 1671unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1672 unordered_multiset&& __u, const allocator_type& __a) 1673 : __table_(_VSTD::move(__u.__table_), __a) 1674{ 1675 _VSTD::__debug_db_insert_c(this); 1676 if (__a != __u.get_allocator()) 1677 { 1678 iterator __i = __u.begin(); 1679 while (__u.size() != 0) 1680 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_)); 1681 } 1682#if _LIBCPP_DEBUG_LEVEL == 2 1683 else 1684 __get_db()->swap(this, _VSTD::addressof(__u)); 1685#endif 1686} 1687 1688template <class _Value, class _Hash, class _Pred, class _Alloc> 1689unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1690 initializer_list<value_type> __il) 1691{ 1692 _VSTD::__debug_db_insert_c(this); 1693 insert(__il.begin(), __il.end()); 1694} 1695 1696template <class _Value, class _Hash, class _Pred, class _Alloc> 1697unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1698 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1699 const key_equal& __eql) 1700 : __table_(__hf, __eql) 1701{ 1702 _VSTD::__debug_db_insert_c(this); 1703 __table_.rehash(__n); 1704 insert(__il.begin(), __il.end()); 1705} 1706 1707template <class _Value, class _Hash, class _Pred, class _Alloc> 1708unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1709 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1710 const key_equal& __eql, const allocator_type& __a) 1711 : __table_(__hf, __eql, __a) 1712{ 1713 _VSTD::__debug_db_insert_c(this); 1714 __table_.rehash(__n); 1715 insert(__il.begin(), __il.end()); 1716} 1717 1718template <class _Value, class _Hash, class _Pred, class _Alloc> 1719inline 1720unordered_multiset<_Value, _Hash, _Pred, _Alloc>& 1721unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( 1722 unordered_multiset&& __u) 1723 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) 1724{ 1725 __table_ = _VSTD::move(__u.__table_); 1726 return *this; 1727} 1728 1729template <class _Value, class _Hash, class _Pred, class _Alloc> 1730inline 1731unordered_multiset<_Value, _Hash, _Pred, _Alloc>& 1732unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( 1733 initializer_list<value_type> __il) 1734{ 1735 __table_.__assign_multi(__il.begin(), __il.end()); 1736 return *this; 1737} 1738 1739#endif // _LIBCPP_CXX03_LANG 1740 1741template <class _Value, class _Hash, class _Pred, class _Alloc> 1742template <class _InputIterator> 1743inline 1744void 1745unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 1746 _InputIterator __last) 1747{ 1748 for (; __first != __last; ++__first) 1749 __table_.__insert_multi(*__first); 1750} 1751 1752template <class _Value, class _Hash, class _Pred, class _Alloc> 1753inline _LIBCPP_INLINE_VISIBILITY 1754void 1755swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, 1756 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) 1757 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 1758{ 1759 __x.swap(__y); 1760} 1761 1762#if _LIBCPP_STD_VER > 17 1763template <class _Value, class _Hash, class _Pred, class _Alloc, 1764 class _Predicate> 1765inline _LIBCPP_INLINE_VISIBILITY 1766 typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type 1767 erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c, 1768 _Predicate __pred) { 1769 return _VSTD::__libcpp_erase_if_container(__c, __pred); 1770} 1771#endif 1772 1773template <class _Value, class _Hash, class _Pred, class _Alloc> 1774bool 1775operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, 1776 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) 1777{ 1778 if (__x.size() != __y.size()) 1779 return false; 1780 typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator 1781 const_iterator; 1782 typedef pair<const_iterator, const_iterator> _EqRng; 1783 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) 1784 { 1785 _EqRng __xeq = __x.equal_range(*__i); 1786 _EqRng __yeq = __y.equal_range(*__i); 1787 if (_VSTD::distance(__xeq.first, __xeq.second) != 1788 _VSTD::distance(__yeq.first, __yeq.second) || 1789 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) 1790 return false; 1791 __i = __xeq.second; 1792 } 1793 return true; 1794} 1795 1796template <class _Value, class _Hash, class _Pred, class _Alloc> 1797inline _LIBCPP_INLINE_VISIBILITY 1798bool 1799operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, 1800 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) 1801{ 1802 return !(__x == __y); 1803} 1804 1805_LIBCPP_END_NAMESPACE_STD 1806 1807#endif // _LIBCPP_UNORDERED_SET 1808