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 <__functional/operations.h> 468#include <__hash_table> 469#include <__iterator/distance.h> 470#include <__iterator/erase_if_container.h> 471#include <__iterator/iterator_traits.h> 472#include <__memory/addressof.h> 473#include <__node_handle> 474#include <__utility/forward.h> 475#include <version> 476 477// standard-mandated includes 478 479// [iterator.range] 480#include <__iterator/access.h> 481#include <__iterator/data.h> 482#include <__iterator/empty.h> 483#include <__iterator/reverse_access.h> 484#include <__iterator/size.h> 485 486// [unord.set.syn] 487#include <compare> 488#include <initializer_list> 489 490#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 491# pragma GCC system_header 492#endif 493 494_LIBCPP_BEGIN_NAMESPACE_STD 495 496template <class _Value, class _Hash, class _Pred, class _Alloc> 497class unordered_multiset; 498 499template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, 500 class _Alloc = allocator<_Value> > 501class _LIBCPP_TEMPLATE_VIS unordered_set 502{ 503public: 504 // types 505 typedef _Value key_type; 506 typedef key_type value_type; 507 typedef __type_identity_t<_Hash> hasher; 508 typedef __type_identity_t<_Pred> key_equal; 509 typedef __type_identity_t<_Alloc> allocator_type; 510 typedef value_type& reference; 511 typedef const value_type& const_reference; 512 static_assert((is_same<value_type, typename allocator_type::value_type>::value), 513 "Invalid allocator::value_type"); 514 515private: 516 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; 517 518 __table __table_; 519 520public: 521 typedef typename __table::pointer pointer; 522 typedef typename __table::const_pointer const_pointer; 523 typedef typename __table::size_type size_type; 524 typedef typename __table::difference_type difference_type; 525 526 typedef typename __table::const_iterator iterator; 527 typedef typename __table::const_iterator const_iterator; 528 typedef typename __table::const_local_iterator local_iterator; 529 typedef typename __table::const_local_iterator const_local_iterator; 530 531#if _LIBCPP_STD_VER > 14 532 typedef __set_node_handle<typename __table::__node, allocator_type> node_type; 533 typedef __insert_return_type<iterator, node_type> insert_return_type; 534#endif 535 536 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 537 friend class _LIBCPP_TEMPLATE_VIS unordered_set; 538 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 539 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset; 540 541 _LIBCPP_INLINE_VISIBILITY 542 unordered_set() 543 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) 544 { 545 _VSTD::__debug_db_insert_c(this); 546 } 547 explicit unordered_set(size_type __n, const hasher& __hf = hasher(), 548 const key_equal& __eql = key_equal()); 549#if _LIBCPP_STD_VER > 11 550 inline _LIBCPP_INLINE_VISIBILITY 551 unordered_set(size_type __n, const allocator_type& __a) 552 : unordered_set(__n, hasher(), key_equal(), __a) {} 553 inline _LIBCPP_INLINE_VISIBILITY 554 unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a) 555 : unordered_set(__n, __hf, key_equal(), __a) {} 556#endif 557 unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql, 558 const allocator_type& __a); 559 template <class _InputIterator> 560 unordered_set(_InputIterator __first, _InputIterator __last); 561 template <class _InputIterator> 562 unordered_set(_InputIterator __first, _InputIterator __last, 563 size_type __n, const hasher& __hf = hasher(), 564 const key_equal& __eql = key_equal()); 565 template <class _InputIterator> 566 unordered_set(_InputIterator __first, _InputIterator __last, 567 size_type __n, const hasher& __hf, const key_equal& __eql, 568 const allocator_type& __a); 569#if _LIBCPP_STD_VER > 11 570 template <class _InputIterator> 571 inline _LIBCPP_INLINE_VISIBILITY 572 unordered_set(_InputIterator __first, _InputIterator __last, 573 size_type __n, const allocator_type& __a) 574 : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {} 575 template <class _InputIterator> 576 unordered_set(_InputIterator __first, _InputIterator __last, 577 size_type __n, const hasher& __hf, const allocator_type& __a) 578 : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {} 579#endif 580 _LIBCPP_INLINE_VISIBILITY 581 explicit unordered_set(const allocator_type& __a); 582 unordered_set(const unordered_set& __u); 583 unordered_set(const unordered_set& __u, const allocator_type& __a); 584#ifndef _LIBCPP_CXX03_LANG 585 _LIBCPP_INLINE_VISIBILITY 586 unordered_set(unordered_set&& __u) 587 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); 588 unordered_set(unordered_set&& __u, const allocator_type& __a); 589 unordered_set(initializer_list<value_type> __il); 590 unordered_set(initializer_list<value_type> __il, size_type __n, 591 const hasher& __hf = hasher(), 592 const key_equal& __eql = key_equal()); 593 unordered_set(initializer_list<value_type> __il, size_type __n, 594 const hasher& __hf, const key_equal& __eql, 595 const allocator_type& __a); 596#if _LIBCPP_STD_VER > 11 597 inline _LIBCPP_INLINE_VISIBILITY 598 unordered_set(initializer_list<value_type> __il, size_type __n, 599 const allocator_type& __a) 600 : unordered_set(__il, __n, hasher(), key_equal(), __a) {} 601 inline _LIBCPP_INLINE_VISIBILITY 602 unordered_set(initializer_list<value_type> __il, size_type __n, 603 const hasher& __hf, const allocator_type& __a) 604 : unordered_set(__il, __n, __hf, key_equal(), __a) {} 605#endif 606#endif // _LIBCPP_CXX03_LANG 607 _LIBCPP_INLINE_VISIBILITY 608 ~unordered_set() { 609 static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); 610 } 611 612 _LIBCPP_INLINE_VISIBILITY 613 unordered_set& operator=(const unordered_set& __u) 614 { 615 __table_ = __u.__table_; 616 return *this; 617 } 618#ifndef _LIBCPP_CXX03_LANG 619 _LIBCPP_INLINE_VISIBILITY 620 unordered_set& operator=(unordered_set&& __u) 621 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); 622 _LIBCPP_INLINE_VISIBILITY 623 unordered_set& operator=(initializer_list<value_type> __il); 624#endif // _LIBCPP_CXX03_LANG 625 626 _LIBCPP_INLINE_VISIBILITY 627 allocator_type get_allocator() const _NOEXCEPT 628 {return allocator_type(__table_.__node_alloc());} 629 630 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 631 bool empty() const _NOEXCEPT {return __table_.size() == 0;} 632 _LIBCPP_INLINE_VISIBILITY 633 size_type size() const _NOEXCEPT {return __table_.size();} 634 _LIBCPP_INLINE_VISIBILITY 635 size_type max_size() const _NOEXCEPT {return __table_.max_size();} 636 637 _LIBCPP_INLINE_VISIBILITY 638 iterator begin() _NOEXCEPT {return __table_.begin();} 639 _LIBCPP_INLINE_VISIBILITY 640 iterator end() _NOEXCEPT {return __table_.end();} 641 _LIBCPP_INLINE_VISIBILITY 642 const_iterator begin() const _NOEXCEPT {return __table_.begin();} 643 _LIBCPP_INLINE_VISIBILITY 644 const_iterator end() const _NOEXCEPT {return __table_.end();} 645 _LIBCPP_INLINE_VISIBILITY 646 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} 647 _LIBCPP_INLINE_VISIBILITY 648 const_iterator cend() const _NOEXCEPT {return __table_.end();} 649 650#ifndef _LIBCPP_CXX03_LANG 651 template <class... _Args> 652 _LIBCPP_INLINE_VISIBILITY 653 pair<iterator, bool> emplace(_Args&&... __args) 654 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);} 655 template <class... _Args> 656 _LIBCPP_INLINE_VISIBILITY 657 iterator emplace_hint(const_iterator __p, _Args&&... __args) { 658 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this, 659 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not" 660 " referring to this unordered_set"); 661 (void)__p; 662 return __table_.__emplace_unique(std::forward<_Args>(__args)...).first; 663 } 664 665 _LIBCPP_INLINE_VISIBILITY 666 pair<iterator, bool> insert(value_type&& __x) 667 {return __table_.__insert_unique(_VSTD::move(__x));} 668 _LIBCPP_INLINE_VISIBILITY 669 iterator insert(const_iterator __p, value_type&& __x) { 670 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this, 671 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not" 672 " referring to this unordered_set"); 673 (void)__p; 674 return insert(std::move(__x)).first; 675 } 676 677 _LIBCPP_INLINE_VISIBILITY 678 void insert(initializer_list<value_type> __il) 679 {insert(__il.begin(), __il.end());} 680#endif // _LIBCPP_CXX03_LANG 681 _LIBCPP_INLINE_VISIBILITY 682 pair<iterator, bool> insert(const value_type& __x) 683 {return __table_.__insert_unique(__x);} 684 685 _LIBCPP_INLINE_VISIBILITY 686 iterator insert(const_iterator __p, const value_type& __x) { 687 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this, 688 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not" 689 " referring to this unordered_set"); 690 (void)__p; 691 return insert(__x).first; 692 } 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#ifdef _LIBCPP_ENABLE_DEBUG_MODE 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_ENABLE_DEBUG_MODE 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 std::__debug_db_swap(this, std::addressof(__u)); 1025} 1026 1027template <class _Value, class _Hash, class _Pred, class _Alloc> 1028unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1029 unordered_set&& __u, const allocator_type& __a) 1030 : __table_(_VSTD::move(__u.__table_), __a) 1031{ 1032 _VSTD::__debug_db_insert_c(this); 1033 if (__a != __u.get_allocator()) 1034 { 1035 iterator __i = __u.begin(); 1036 while (__u.size() != 0) 1037 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_)); 1038 } 1039 else 1040 std::__debug_db_swap(this, std::addressof(__u)); 1041} 1042 1043template <class _Value, class _Hash, class _Pred, class _Alloc> 1044unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1045 initializer_list<value_type> __il) 1046{ 1047 _VSTD::__debug_db_insert_c(this); 1048 insert(__il.begin(), __il.end()); 1049} 1050 1051template <class _Value, class _Hash, class _Pred, class _Alloc> 1052unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1053 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1054 const key_equal& __eql) 1055 : __table_(__hf, __eql) 1056{ 1057 _VSTD::__debug_db_insert_c(this); 1058 __table_.rehash(__n); 1059 insert(__il.begin(), __il.end()); 1060} 1061 1062template <class _Value, class _Hash, class _Pred, class _Alloc> 1063unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1064 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1065 const key_equal& __eql, const allocator_type& __a) 1066 : __table_(__hf, __eql, __a) 1067{ 1068 _VSTD::__debug_db_insert_c(this); 1069 __table_.rehash(__n); 1070 insert(__il.begin(), __il.end()); 1071} 1072 1073template <class _Value, class _Hash, class _Pred, class _Alloc> 1074inline 1075unordered_set<_Value, _Hash, _Pred, _Alloc>& 1076unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u) 1077 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) 1078{ 1079 __table_ = _VSTD::move(__u.__table_); 1080 return *this; 1081} 1082 1083template <class _Value, class _Hash, class _Pred, class _Alloc> 1084inline 1085unordered_set<_Value, _Hash, _Pred, _Alloc>& 1086unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=( 1087 initializer_list<value_type> __il) 1088{ 1089 __table_.__assign_unique(__il.begin(), __il.end()); 1090 return *this; 1091} 1092 1093#endif // _LIBCPP_CXX03_LANG 1094 1095template <class _Value, class _Hash, class _Pred, class _Alloc> 1096template <class _InputIterator> 1097inline 1098void 1099unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 1100 _InputIterator __last) 1101{ 1102 for (; __first != __last; ++__first) 1103 __table_.__insert_unique(*__first); 1104} 1105 1106template <class _Value, class _Hash, class _Pred, class _Alloc> 1107inline _LIBCPP_INLINE_VISIBILITY 1108void 1109swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, 1110 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) 1111 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 1112{ 1113 __x.swap(__y); 1114} 1115 1116#if _LIBCPP_STD_VER > 17 1117template <class _Value, class _Hash, class _Pred, class _Alloc, 1118 class _Predicate> 1119inline _LIBCPP_INLINE_VISIBILITY 1120 typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type 1121 erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c, 1122 _Predicate __pred) { 1123 return _VSTD::__libcpp_erase_if_container(__c, __pred); 1124} 1125#endif 1126 1127template <class _Value, class _Hash, class _Pred, class _Alloc> 1128bool 1129operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, 1130 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) 1131{ 1132 if (__x.size() != __y.size()) 1133 return false; 1134 typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator 1135 const_iterator; 1136 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); 1137 __i != __ex; ++__i) 1138 { 1139 const_iterator __j = __y.find(*__i); 1140 if (__j == __ey || !(*__i == *__j)) 1141 return false; 1142 } 1143 return true; 1144} 1145 1146template <class _Value, class _Hash, class _Pred, class _Alloc> 1147inline _LIBCPP_INLINE_VISIBILITY 1148bool 1149operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, 1150 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) 1151{ 1152 return !(__x == __y); 1153} 1154 1155template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, 1156 class _Alloc = allocator<_Value> > 1157class _LIBCPP_TEMPLATE_VIS unordered_multiset 1158{ 1159public: 1160 // types 1161 typedef _Value key_type; 1162 typedef key_type value_type; 1163 typedef __type_identity_t<_Hash> hasher; 1164 typedef __type_identity_t<_Pred> key_equal; 1165 typedef __type_identity_t<_Alloc> allocator_type; 1166 typedef value_type& reference; 1167 typedef const value_type& const_reference; 1168 static_assert((is_same<value_type, typename allocator_type::value_type>::value), 1169 "Invalid allocator::value_type"); 1170 1171private: 1172 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; 1173 1174 __table __table_; 1175 1176public: 1177 typedef typename __table::pointer pointer; 1178 typedef typename __table::const_pointer const_pointer; 1179 typedef typename __table::size_type size_type; 1180 typedef typename __table::difference_type difference_type; 1181 1182 typedef typename __table::const_iterator iterator; 1183 typedef typename __table::const_iterator const_iterator; 1184 typedef typename __table::const_local_iterator local_iterator; 1185 typedef typename __table::const_local_iterator const_local_iterator; 1186 1187#if _LIBCPP_STD_VER > 14 1188 typedef __set_node_handle<typename __table::__node, allocator_type> node_type; 1189#endif 1190 1191 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 1192 friend class _LIBCPP_TEMPLATE_VIS unordered_set; 1193 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 1194 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset; 1195 1196 _LIBCPP_INLINE_VISIBILITY 1197 unordered_multiset() 1198 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) 1199 { 1200 _VSTD::__debug_db_insert_c(this); 1201 } 1202 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(), 1203 const key_equal& __eql = key_equal()); 1204 unordered_multiset(size_type __n, const hasher& __hf, 1205 const key_equal& __eql, const allocator_type& __a); 1206#if _LIBCPP_STD_VER > 11 1207 inline _LIBCPP_INLINE_VISIBILITY 1208 unordered_multiset(size_type __n, const allocator_type& __a) 1209 : unordered_multiset(__n, hasher(), key_equal(), __a) {} 1210 inline _LIBCPP_INLINE_VISIBILITY 1211 unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a) 1212 : unordered_multiset(__n, __hf, key_equal(), __a) {} 1213#endif 1214 template <class _InputIterator> 1215 unordered_multiset(_InputIterator __first, _InputIterator __last); 1216 template <class _InputIterator> 1217 unordered_multiset(_InputIterator __first, _InputIterator __last, 1218 size_type __n, const hasher& __hf = hasher(), 1219 const key_equal& __eql = key_equal()); 1220 template <class _InputIterator> 1221 unordered_multiset(_InputIterator __first, _InputIterator __last, 1222 size_type __n , const hasher& __hf, 1223 const key_equal& __eql, const allocator_type& __a); 1224#if _LIBCPP_STD_VER > 11 1225 template <class _InputIterator> 1226 inline _LIBCPP_INLINE_VISIBILITY 1227 unordered_multiset(_InputIterator __first, _InputIterator __last, 1228 size_type __n, const allocator_type& __a) 1229 : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {} 1230 template <class _InputIterator> 1231 inline _LIBCPP_INLINE_VISIBILITY 1232 unordered_multiset(_InputIterator __first, _InputIterator __last, 1233 size_type __n, const hasher& __hf, const allocator_type& __a) 1234 : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {} 1235#endif 1236 _LIBCPP_INLINE_VISIBILITY 1237 explicit unordered_multiset(const allocator_type& __a); 1238 unordered_multiset(const unordered_multiset& __u); 1239 unordered_multiset(const unordered_multiset& __u, const allocator_type& __a); 1240#ifndef _LIBCPP_CXX03_LANG 1241 _LIBCPP_INLINE_VISIBILITY 1242 unordered_multiset(unordered_multiset&& __u) 1243 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); 1244 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a); 1245 unordered_multiset(initializer_list<value_type> __il); 1246 unordered_multiset(initializer_list<value_type> __il, size_type __n, 1247 const hasher& __hf = hasher(), 1248 const key_equal& __eql = key_equal()); 1249 unordered_multiset(initializer_list<value_type> __il, size_type __n, 1250 const hasher& __hf, const key_equal& __eql, 1251 const allocator_type& __a); 1252#if _LIBCPP_STD_VER > 11 1253 inline _LIBCPP_INLINE_VISIBILITY 1254 unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) 1255 : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {} 1256 inline _LIBCPP_INLINE_VISIBILITY 1257 unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a) 1258 : unordered_multiset(__il, __n, __hf, key_equal(), __a) {} 1259#endif 1260#endif // _LIBCPP_CXX03_LANG 1261 _LIBCPP_INLINE_VISIBILITY 1262 ~unordered_multiset() { 1263 static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); 1264 } 1265 1266 _LIBCPP_INLINE_VISIBILITY 1267 unordered_multiset& operator=(const unordered_multiset& __u) 1268 { 1269 __table_ = __u.__table_; 1270 return *this; 1271 } 1272#ifndef _LIBCPP_CXX03_LANG 1273 _LIBCPP_INLINE_VISIBILITY 1274 unordered_multiset& operator=(unordered_multiset&& __u) 1275 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); 1276 unordered_multiset& operator=(initializer_list<value_type> __il); 1277#endif // _LIBCPP_CXX03_LANG 1278 1279 _LIBCPP_INLINE_VISIBILITY 1280 allocator_type get_allocator() const _NOEXCEPT 1281 {return allocator_type(__table_.__node_alloc());} 1282 1283 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 1284 bool empty() const _NOEXCEPT {return __table_.size() == 0;} 1285 _LIBCPP_INLINE_VISIBILITY 1286 size_type size() const _NOEXCEPT {return __table_.size();} 1287 _LIBCPP_INLINE_VISIBILITY 1288 size_type max_size() const _NOEXCEPT {return __table_.max_size();} 1289 1290 _LIBCPP_INLINE_VISIBILITY 1291 iterator begin() _NOEXCEPT {return __table_.begin();} 1292 _LIBCPP_INLINE_VISIBILITY 1293 iterator end() _NOEXCEPT {return __table_.end();} 1294 _LIBCPP_INLINE_VISIBILITY 1295 const_iterator begin() const _NOEXCEPT {return __table_.begin();} 1296 _LIBCPP_INLINE_VISIBILITY 1297 const_iterator end() const _NOEXCEPT {return __table_.end();} 1298 _LIBCPP_INLINE_VISIBILITY 1299 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} 1300 _LIBCPP_INLINE_VISIBILITY 1301 const_iterator cend() const _NOEXCEPT {return __table_.end();} 1302 1303#ifndef _LIBCPP_CXX03_LANG 1304 template <class... _Args> 1305 _LIBCPP_INLINE_VISIBILITY 1306 iterator emplace(_Args&&... __args) 1307 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);} 1308 template <class... _Args> 1309 _LIBCPP_INLINE_VISIBILITY 1310 iterator emplace_hint(const_iterator __p, _Args&&... __args) 1311 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);} 1312 1313 _LIBCPP_INLINE_VISIBILITY 1314 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));} 1315 _LIBCPP_INLINE_VISIBILITY 1316 iterator insert(const_iterator __p, value_type&& __x) 1317 {return __table_.__insert_multi(__p, _VSTD::move(__x));} 1318 _LIBCPP_INLINE_VISIBILITY 1319 void insert(initializer_list<value_type> __il) 1320 {insert(__il.begin(), __il.end());} 1321#endif // _LIBCPP_CXX03_LANG 1322 1323 _LIBCPP_INLINE_VISIBILITY 1324 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} 1325 1326 _LIBCPP_INLINE_VISIBILITY 1327 iterator insert(const_iterator __p, const value_type& __x) 1328 {return __table_.__insert_multi(__p, __x);} 1329 1330 template <class _InputIterator> 1331 _LIBCPP_INLINE_VISIBILITY 1332 void insert(_InputIterator __first, _InputIterator __last); 1333 1334#if _LIBCPP_STD_VER > 14 1335 _LIBCPP_INLINE_VISIBILITY 1336 iterator insert(node_type&& __nh) 1337 { 1338 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 1339 "node_type with incompatible allocator passed to unordered_multiset::insert()"); 1340 return __table_.template __node_handle_insert_multi<node_type>( 1341 _VSTD::move(__nh)); 1342 } 1343 _LIBCPP_INLINE_VISIBILITY 1344 iterator insert(const_iterator __hint, node_type&& __nh) 1345 { 1346 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 1347 "node_type with incompatible allocator passed to unordered_multiset::insert()"); 1348 return __table_.template __node_handle_insert_multi<node_type>( 1349 __hint, _VSTD::move(__nh)); 1350 } 1351 _LIBCPP_INLINE_VISIBILITY 1352 node_type extract(const_iterator __position) 1353 { 1354 return __table_.template __node_handle_extract<node_type>( 1355 __position); 1356 } 1357 _LIBCPP_INLINE_VISIBILITY 1358 node_type extract(key_type const& __key) 1359 { 1360 return __table_.template __node_handle_extract<node_type>(__key); 1361 } 1362 1363 template <class _H2, class _P2> 1364 _LIBCPP_INLINE_VISIBILITY 1365 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source) 1366 { 1367 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1368 "merging container with incompatible allocator"); 1369 return __table_.__node_handle_merge_multi(__source.__table_); 1370 } 1371 template <class _H2, class _P2> 1372 _LIBCPP_INLINE_VISIBILITY 1373 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source) 1374 { 1375 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1376 "merging container with incompatible allocator"); 1377 return __table_.__node_handle_merge_multi(__source.__table_); 1378 } 1379 template <class _H2, class _P2> 1380 _LIBCPP_INLINE_VISIBILITY 1381 void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source) 1382 { 1383 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1384 "merging container with incompatible allocator"); 1385 return __table_.__node_handle_merge_multi(__source.__table_); 1386 } 1387 template <class _H2, class _P2> 1388 _LIBCPP_INLINE_VISIBILITY 1389 void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source) 1390 { 1391 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1392 "merging container with incompatible allocator"); 1393 return __table_.__node_handle_merge_multi(__source.__table_); 1394 } 1395#endif 1396 1397 _LIBCPP_INLINE_VISIBILITY 1398 iterator erase(const_iterator __p) {return __table_.erase(__p);} 1399 _LIBCPP_INLINE_VISIBILITY 1400 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} 1401 _LIBCPP_INLINE_VISIBILITY 1402 iterator erase(const_iterator __first, const_iterator __last) 1403 {return __table_.erase(__first, __last);} 1404 _LIBCPP_INLINE_VISIBILITY 1405 void clear() _NOEXCEPT {__table_.clear();} 1406 1407 _LIBCPP_INLINE_VISIBILITY 1408 void swap(unordered_multiset& __u) 1409 _NOEXCEPT_(__is_nothrow_swappable<__table>::value) 1410 {__table_.swap(__u.__table_);} 1411 1412 _LIBCPP_INLINE_VISIBILITY 1413 hasher hash_function() const {return __table_.hash_function();} 1414 _LIBCPP_INLINE_VISIBILITY 1415 key_equal key_eq() const {return __table_.key_eq();} 1416 1417 _LIBCPP_INLINE_VISIBILITY 1418 iterator find(const key_type& __k) {return __table_.find(__k);} 1419 _LIBCPP_INLINE_VISIBILITY 1420 const_iterator find(const key_type& __k) const {return __table_.find(__k);} 1421#if _LIBCPP_STD_VER > 17 1422 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1423 _LIBCPP_INLINE_VISIBILITY 1424 iterator find(const _K2& __k) {return __table_.find(__k);} 1425 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1426 _LIBCPP_INLINE_VISIBILITY 1427 const_iterator find(const _K2& __k) const {return __table_.find(__k);} 1428#endif // _LIBCPP_STD_VER > 17 1429 1430 _LIBCPP_INLINE_VISIBILITY 1431 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} 1432#if _LIBCPP_STD_VER > 17 1433 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1434 _LIBCPP_INLINE_VISIBILITY 1435 size_type count(const _K2& __k) const {return __table_.__count_multi(__k);} 1436#endif // _LIBCPP_STD_VER > 17 1437 1438#if _LIBCPP_STD_VER > 17 1439 _LIBCPP_INLINE_VISIBILITY 1440 bool contains(const key_type& __k) const {return find(__k) != end();} 1441 1442 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1443 _LIBCPP_INLINE_VISIBILITY 1444 bool contains(const _K2& __k) const {return find(__k) != end();} 1445#endif // _LIBCPP_STD_VER > 17 1446 1447 _LIBCPP_INLINE_VISIBILITY 1448 pair<iterator, iterator> equal_range(const key_type& __k) 1449 {return __table_.__equal_range_multi(__k);} 1450 _LIBCPP_INLINE_VISIBILITY 1451 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const 1452 {return __table_.__equal_range_multi(__k);} 1453#if _LIBCPP_STD_VER > 17 1454 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1455 _LIBCPP_INLINE_VISIBILITY 1456 pair<iterator, iterator> equal_range(const _K2& __k) 1457 {return __table_.__equal_range_multi(__k);} 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<const_iterator, const_iterator> equal_range(const _K2& __k) const 1461 {return __table_.__equal_range_multi(__k);} 1462#endif // _LIBCPP_STD_VER > 17 1463 1464 _LIBCPP_INLINE_VISIBILITY 1465 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} 1466 _LIBCPP_INLINE_VISIBILITY 1467 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} 1468 1469 _LIBCPP_INLINE_VISIBILITY 1470 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);} 1471 _LIBCPP_INLINE_VISIBILITY 1472 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} 1473 1474 _LIBCPP_INLINE_VISIBILITY 1475 local_iterator begin(size_type __n) {return __table_.begin(__n);} 1476 _LIBCPP_INLINE_VISIBILITY 1477 local_iterator end(size_type __n) {return __table_.end(__n);} 1478 _LIBCPP_INLINE_VISIBILITY 1479 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} 1480 _LIBCPP_INLINE_VISIBILITY 1481 const_local_iterator end(size_type __n) const {return __table_.cend(__n);} 1482 _LIBCPP_INLINE_VISIBILITY 1483 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} 1484 _LIBCPP_INLINE_VISIBILITY 1485 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} 1486 1487 _LIBCPP_INLINE_VISIBILITY 1488 float load_factor() const _NOEXCEPT {return __table_.load_factor();} 1489 _LIBCPP_INLINE_VISIBILITY 1490 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} 1491 _LIBCPP_INLINE_VISIBILITY 1492 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} 1493 _LIBCPP_INLINE_VISIBILITY 1494 void rehash(size_type __n) {__table_.rehash(__n);} 1495 _LIBCPP_INLINE_VISIBILITY 1496 void reserve(size_type __n) {__table_.reserve(__n);} 1497 1498#ifdef _LIBCPP_ENABLE_DEBUG_MODE 1499 1500 bool __dereferenceable(const const_iterator* __i) const 1501 {return __table_.__dereferenceable(__i);} 1502 bool __decrementable(const const_iterator* __i) const 1503 {return __table_.__decrementable(__i);} 1504 bool __addable(const const_iterator* __i, ptrdiff_t __n) const 1505 {return __table_.__addable(__i, __n);} 1506 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const 1507 {return __table_.__addable(__i, __n);} 1508 1509#endif // _LIBCPP_ENABLE_DEBUG_MODE 1510 1511}; 1512 1513#if _LIBCPP_STD_VER >= 17 1514template<class _InputIterator, 1515 class _Hash = hash<__iter_value_type<_InputIterator>>, 1516 class _Pred = equal_to<__iter_value_type<_InputIterator>>, 1517 class _Allocator = allocator<__iter_value_type<_InputIterator>>, 1518 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1519 class = enable_if_t<!__is_allocator<_Hash>::value>, 1520 class = enable_if_t<!is_integral<_Hash>::value>, 1521 class = enable_if_t<!__is_allocator<_Pred>::value>, 1522 class = enable_if_t<__is_allocator<_Allocator>::value>> 1523unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, 1524 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) 1525 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>; 1526 1527template<class _Tp, class _Hash = hash<_Tp>, 1528 class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>, 1529 class = enable_if_t<!__is_allocator<_Hash>::value>, 1530 class = enable_if_t<!is_integral<_Hash>::value>, 1531 class = enable_if_t<!__is_allocator<_Pred>::value>, 1532 class = enable_if_t<__is_allocator<_Allocator>::value>> 1533unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0, 1534 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) 1535 -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>; 1536 1537template<class _InputIterator, class _Allocator, 1538 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1539 class = enable_if_t<__is_allocator<_Allocator>::value>> 1540unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) 1541 -> unordered_multiset<__iter_value_type<_InputIterator>, 1542 hash<__iter_value_type<_InputIterator>>, 1543 equal_to<__iter_value_type<_InputIterator>>, 1544 _Allocator>; 1545 1546template<class _InputIterator, class _Hash, class _Allocator, 1547 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1548 class = enable_if_t<!__is_allocator<_Hash>::value>, 1549 class = enable_if_t<!is_integral<_Hash>::value>, 1550 class = enable_if_t<__is_allocator<_Allocator>::value>> 1551unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, 1552 _Hash, _Allocator) 1553 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, 1554 equal_to<__iter_value_type<_InputIterator>>, 1555 _Allocator>; 1556 1557template<class _Tp, class _Allocator, 1558 class = enable_if_t<__is_allocator<_Allocator>::value>> 1559unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator) 1560 -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>; 1561 1562template<class _Tp, class _Hash, class _Allocator, 1563 class = enable_if_t<!__is_allocator<_Hash>::value>, 1564 class = enable_if_t<!is_integral<_Hash>::value>, 1565 class = enable_if_t<__is_allocator<_Allocator>::value>> 1566unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) 1567 -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>; 1568#endif 1569 1570template <class _Value, class _Hash, class _Pred, class _Alloc> 1571unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1572 size_type __n, const hasher& __hf, const key_equal& __eql) 1573 : __table_(__hf, __eql) 1574{ 1575 _VSTD::__debug_db_insert_c(this); 1576 __table_.rehash(__n); 1577} 1578 1579template <class _Value, class _Hash, class _Pred, class _Alloc> 1580unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1581 size_type __n, const hasher& __hf, const key_equal& __eql, 1582 const allocator_type& __a) 1583 : __table_(__hf, __eql, __a) 1584{ 1585 _VSTD::__debug_db_insert_c(this); 1586 __table_.rehash(__n); 1587} 1588 1589template <class _Value, class _Hash, class _Pred, class _Alloc> 1590template <class _InputIterator> 1591unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1592 _InputIterator __first, _InputIterator __last) 1593{ 1594 _VSTD::__debug_db_insert_c(this); 1595 insert(__first, __last); 1596} 1597 1598template <class _Value, class _Hash, class _Pred, class _Alloc> 1599template <class _InputIterator> 1600unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1601 _InputIterator __first, _InputIterator __last, size_type __n, 1602 const hasher& __hf, const key_equal& __eql) 1603 : __table_(__hf, __eql) 1604{ 1605 _VSTD::__debug_db_insert_c(this); 1606 __table_.rehash(__n); 1607 insert(__first, __last); 1608} 1609 1610template <class _Value, class _Hash, class _Pred, class _Alloc> 1611template <class _InputIterator> 1612unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1613 _InputIterator __first, _InputIterator __last, size_type __n, 1614 const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 1615 : __table_(__hf, __eql, __a) 1616{ 1617 _VSTD::__debug_db_insert_c(this); 1618 __table_.rehash(__n); 1619 insert(__first, __last); 1620} 1621 1622template <class _Value, class _Hash, class _Pred, class _Alloc> 1623inline 1624unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1625 const allocator_type& __a) 1626 : __table_(__a) 1627{ 1628 _VSTD::__debug_db_insert_c(this); 1629} 1630 1631template <class _Value, class _Hash, class _Pred, class _Alloc> 1632unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1633 const unordered_multiset& __u) 1634 : __table_(__u.__table_) 1635{ 1636 _VSTD::__debug_db_insert_c(this); 1637 __table_.rehash(__u.bucket_count()); 1638 insert(__u.begin(), __u.end()); 1639} 1640 1641template <class _Value, class _Hash, class _Pred, class _Alloc> 1642unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1643 const unordered_multiset& __u, const allocator_type& __a) 1644 : __table_(__u.__table_, __a) 1645{ 1646 _VSTD::__debug_db_insert_c(this); 1647 __table_.rehash(__u.bucket_count()); 1648 insert(__u.begin(), __u.end()); 1649} 1650 1651#ifndef _LIBCPP_CXX03_LANG 1652 1653template <class _Value, class _Hash, class _Pred, class _Alloc> 1654inline 1655unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1656 unordered_multiset&& __u) 1657 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) 1658 : __table_(_VSTD::move(__u.__table_)) 1659{ 1660 _VSTD::__debug_db_insert_c(this); 1661 std::__debug_db_swap(this, std::addressof(__u)); 1662} 1663 1664template <class _Value, class _Hash, class _Pred, class _Alloc> 1665unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1666 unordered_multiset&& __u, const allocator_type& __a) 1667 : __table_(_VSTD::move(__u.__table_), __a) 1668{ 1669 _VSTD::__debug_db_insert_c(this); 1670 if (__a != __u.get_allocator()) 1671 { 1672 iterator __i = __u.begin(); 1673 while (__u.size() != 0) 1674 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_)); 1675 } 1676 else 1677 std::__debug_db_swap(this, std::addressof(__u)); 1678} 1679 1680template <class _Value, class _Hash, class _Pred, class _Alloc> 1681unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1682 initializer_list<value_type> __il) 1683{ 1684 _VSTD::__debug_db_insert_c(this); 1685 insert(__il.begin(), __il.end()); 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, size_type __n, const hasher& __hf, 1691 const key_equal& __eql) 1692 : __table_(__hf, __eql) 1693{ 1694 _VSTD::__debug_db_insert_c(this); 1695 __table_.rehash(__n); 1696 insert(__il.begin(), __il.end()); 1697} 1698 1699template <class _Value, class _Hash, class _Pred, class _Alloc> 1700unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1701 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1702 const key_equal& __eql, const allocator_type& __a) 1703 : __table_(__hf, __eql, __a) 1704{ 1705 _VSTD::__debug_db_insert_c(this); 1706 __table_.rehash(__n); 1707 insert(__il.begin(), __il.end()); 1708} 1709 1710template <class _Value, class _Hash, class _Pred, class _Alloc> 1711inline 1712unordered_multiset<_Value, _Hash, _Pred, _Alloc>& 1713unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( 1714 unordered_multiset&& __u) 1715 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) 1716{ 1717 __table_ = _VSTD::move(__u.__table_); 1718 return *this; 1719} 1720 1721template <class _Value, class _Hash, class _Pred, class _Alloc> 1722inline 1723unordered_multiset<_Value, _Hash, _Pred, _Alloc>& 1724unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( 1725 initializer_list<value_type> __il) 1726{ 1727 __table_.__assign_multi(__il.begin(), __il.end()); 1728 return *this; 1729} 1730 1731#endif // _LIBCPP_CXX03_LANG 1732 1733template <class _Value, class _Hash, class _Pred, class _Alloc> 1734template <class _InputIterator> 1735inline 1736void 1737unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 1738 _InputIterator __last) 1739{ 1740 for (; __first != __last; ++__first) 1741 __table_.__insert_multi(*__first); 1742} 1743 1744template <class _Value, class _Hash, class _Pred, class _Alloc> 1745inline _LIBCPP_INLINE_VISIBILITY 1746void 1747swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, 1748 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) 1749 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 1750{ 1751 __x.swap(__y); 1752} 1753 1754#if _LIBCPP_STD_VER > 17 1755template <class _Value, class _Hash, class _Pred, class _Alloc, 1756 class _Predicate> 1757inline _LIBCPP_INLINE_VISIBILITY 1758 typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type 1759 erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c, 1760 _Predicate __pred) { 1761 return _VSTD::__libcpp_erase_if_container(__c, __pred); 1762} 1763#endif 1764 1765template <class _Value, class _Hash, class _Pred, class _Alloc> 1766bool 1767operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, 1768 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) 1769{ 1770 if (__x.size() != __y.size()) 1771 return false; 1772 typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator 1773 const_iterator; 1774 typedef pair<const_iterator, const_iterator> _EqRng; 1775 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) 1776 { 1777 _EqRng __xeq = __x.equal_range(*__i); 1778 _EqRng __yeq = __y.equal_range(*__i); 1779 if (_VSTD::distance(__xeq.first, __xeq.second) != 1780 _VSTD::distance(__yeq.first, __yeq.second) || 1781 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) 1782 return false; 1783 __i = __xeq.second; 1784 } 1785 return true; 1786} 1787 1788template <class _Value, class _Hash, class _Pred, class _Alloc> 1789inline _LIBCPP_INLINE_VISIBILITY 1790bool 1791operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, 1792 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) 1793{ 1794 return !(__x == __y); 1795} 1796 1797_LIBCPP_END_NAMESPACE_STD 1798 1799#endif // _LIBCPP_UNORDERED_SET 1800