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