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#if _LIBCPP_DEBUG_LEVEL == 2 1010 __get_db()->swap(this, _VSTD::addressof(__u)); 1011#endif 1012} 1013 1014template <class _Value, class _Hash, class _Pred, class _Alloc> 1015unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1016 unordered_set&& __u, const allocator_type& __a) 1017 : __table_(_VSTD::move(__u.__table_), __a) 1018{ 1019 _VSTD::__debug_db_insert_c(this); 1020 if (__a != __u.get_allocator()) 1021 { 1022 iterator __i = __u.begin(); 1023 while (__u.size() != 0) 1024 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_)); 1025 } 1026#if _LIBCPP_DEBUG_LEVEL == 2 1027 else 1028 __get_db()->swap(this, _VSTD::addressof(__u)); 1029#endif 1030} 1031 1032template <class _Value, class _Hash, class _Pred, class _Alloc> 1033unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1034 initializer_list<value_type> __il) 1035{ 1036 _VSTD::__debug_db_insert_c(this); 1037 insert(__il.begin(), __il.end()); 1038} 1039 1040template <class _Value, class _Hash, class _Pred, class _Alloc> 1041unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set( 1042 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1043 const key_equal& __eql) 1044 : __table_(__hf, __eql) 1045{ 1046 _VSTD::__debug_db_insert_c(this); 1047 __table_.rehash(__n); 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, const allocator_type& __a) 1055 : __table_(__hf, __eql, __a) 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> 1063inline 1064unordered_set<_Value, _Hash, _Pred, _Alloc>& 1065unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u) 1066 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) 1067{ 1068 __table_ = _VSTD::move(__u.__table_); 1069 return *this; 1070} 1071 1072template <class _Value, class _Hash, class _Pred, class _Alloc> 1073inline 1074unordered_set<_Value, _Hash, _Pred, _Alloc>& 1075unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=( 1076 initializer_list<value_type> __il) 1077{ 1078 __table_.__assign_unique(__il.begin(), __il.end()); 1079 return *this; 1080} 1081 1082#endif // _LIBCPP_CXX03_LANG 1083 1084template <class _Value, class _Hash, class _Pred, class _Alloc> 1085template <class _InputIterator> 1086inline 1087void 1088unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 1089 _InputIterator __last) 1090{ 1091 for (; __first != __last; ++__first) 1092 __table_.__insert_unique(*__first); 1093} 1094 1095template <class _Value, class _Hash, class _Pred, class _Alloc> 1096inline _LIBCPP_INLINE_VISIBILITY 1097void 1098swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, 1099 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) 1100 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 1101{ 1102 __x.swap(__y); 1103} 1104 1105#if _LIBCPP_STD_VER > 17 1106template <class _Value, class _Hash, class _Pred, class _Alloc, 1107 class _Predicate> 1108inline _LIBCPP_INLINE_VISIBILITY 1109 typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type 1110 erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c, 1111 _Predicate __pred) { 1112 return _VSTD::__libcpp_erase_if_container(__c, __pred); 1113} 1114#endif 1115 1116template <class _Value, class _Hash, class _Pred, class _Alloc> 1117bool 1118operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, 1119 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) 1120{ 1121 if (__x.size() != __y.size()) 1122 return false; 1123 typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator 1124 const_iterator; 1125 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); 1126 __i != __ex; ++__i) 1127 { 1128 const_iterator __j = __y.find(*__i); 1129 if (__j == __ey || !(*__i == *__j)) 1130 return false; 1131 } 1132 return true; 1133} 1134 1135template <class _Value, class _Hash, class _Pred, class _Alloc> 1136inline _LIBCPP_INLINE_VISIBILITY 1137bool 1138operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, 1139 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) 1140{ 1141 return !(__x == __y); 1142} 1143 1144template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, 1145 class _Alloc = allocator<_Value> > 1146class _LIBCPP_TEMPLATE_VIS unordered_multiset 1147{ 1148public: 1149 // types 1150 typedef _Value key_type; 1151 typedef key_type value_type; 1152 typedef __type_identity_t<_Hash> hasher; 1153 typedef __type_identity_t<_Pred> key_equal; 1154 typedef __type_identity_t<_Alloc> allocator_type; 1155 typedef value_type& reference; 1156 typedef const value_type& const_reference; 1157 static_assert((is_same<value_type, typename allocator_type::value_type>::value), 1158 "Invalid allocator::value_type"); 1159 1160private: 1161 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; 1162 1163 __table __table_; 1164 1165public: 1166 typedef typename __table::pointer pointer; 1167 typedef typename __table::const_pointer const_pointer; 1168 typedef typename __table::size_type size_type; 1169 typedef typename __table::difference_type difference_type; 1170 1171 typedef typename __table::const_iterator iterator; 1172 typedef typename __table::const_iterator const_iterator; 1173 typedef typename __table::const_local_iterator local_iterator; 1174 typedef typename __table::const_local_iterator const_local_iterator; 1175 1176#if _LIBCPP_STD_VER > 14 1177 typedef __set_node_handle<typename __table::__node, allocator_type> node_type; 1178#endif 1179 1180 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 1181 friend class _LIBCPP_TEMPLATE_VIS unordered_set; 1182 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2> 1183 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset; 1184 1185 _LIBCPP_INLINE_VISIBILITY 1186 unordered_multiset() 1187 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) 1188 { 1189 _VSTD::__debug_db_insert_c(this); 1190 } 1191 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(), 1192 const key_equal& __eql = key_equal()); 1193 unordered_multiset(size_type __n, const hasher& __hf, 1194 const key_equal& __eql, const allocator_type& __a); 1195#if _LIBCPP_STD_VER > 11 1196 inline _LIBCPP_INLINE_VISIBILITY 1197 unordered_multiset(size_type __n, const allocator_type& __a) 1198 : unordered_multiset(__n, hasher(), key_equal(), __a) {} 1199 inline _LIBCPP_INLINE_VISIBILITY 1200 unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a) 1201 : unordered_multiset(__n, __hf, key_equal(), __a) {} 1202#endif 1203 template <class _InputIterator> 1204 unordered_multiset(_InputIterator __first, _InputIterator __last); 1205 template <class _InputIterator> 1206 unordered_multiset(_InputIterator __first, _InputIterator __last, 1207 size_type __n, const hasher& __hf = hasher(), 1208 const key_equal& __eql = key_equal()); 1209 template <class _InputIterator> 1210 unordered_multiset(_InputIterator __first, _InputIterator __last, 1211 size_type __n , const hasher& __hf, 1212 const key_equal& __eql, const allocator_type& __a); 1213#if _LIBCPP_STD_VER > 11 1214 template <class _InputIterator> 1215 inline _LIBCPP_INLINE_VISIBILITY 1216 unordered_multiset(_InputIterator __first, _InputIterator __last, 1217 size_type __n, const allocator_type& __a) 1218 : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {} 1219 template <class _InputIterator> 1220 inline _LIBCPP_INLINE_VISIBILITY 1221 unordered_multiset(_InputIterator __first, _InputIterator __last, 1222 size_type __n, const hasher& __hf, const allocator_type& __a) 1223 : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {} 1224#endif 1225 _LIBCPP_INLINE_VISIBILITY 1226 explicit unordered_multiset(const allocator_type& __a); 1227 unordered_multiset(const unordered_multiset& __u); 1228 unordered_multiset(const unordered_multiset& __u, const allocator_type& __a); 1229#ifndef _LIBCPP_CXX03_LANG 1230 _LIBCPP_INLINE_VISIBILITY 1231 unordered_multiset(unordered_multiset&& __u) 1232 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value); 1233 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a); 1234 unordered_multiset(initializer_list<value_type> __il); 1235 unordered_multiset(initializer_list<value_type> __il, size_type __n, 1236 const hasher& __hf = hasher(), 1237 const key_equal& __eql = key_equal()); 1238 unordered_multiset(initializer_list<value_type> __il, size_type __n, 1239 const hasher& __hf, const key_equal& __eql, 1240 const allocator_type& __a); 1241#if _LIBCPP_STD_VER > 11 1242 inline _LIBCPP_INLINE_VISIBILITY 1243 unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) 1244 : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {} 1245 inline _LIBCPP_INLINE_VISIBILITY 1246 unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a) 1247 : unordered_multiset(__il, __n, __hf, key_equal(), __a) {} 1248#endif 1249#endif // _LIBCPP_CXX03_LANG 1250 _LIBCPP_INLINE_VISIBILITY 1251 ~unordered_multiset() { 1252 static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); 1253 } 1254 1255 _LIBCPP_INLINE_VISIBILITY 1256 unordered_multiset& operator=(const unordered_multiset& __u) 1257 { 1258 __table_ = __u.__table_; 1259 return *this; 1260 } 1261#ifndef _LIBCPP_CXX03_LANG 1262 _LIBCPP_INLINE_VISIBILITY 1263 unordered_multiset& operator=(unordered_multiset&& __u) 1264 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value); 1265 unordered_multiset& operator=(initializer_list<value_type> __il); 1266#endif // _LIBCPP_CXX03_LANG 1267 1268 _LIBCPP_INLINE_VISIBILITY 1269 allocator_type get_allocator() const _NOEXCEPT 1270 {return allocator_type(__table_.__node_alloc());} 1271 1272 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 1273 bool empty() const _NOEXCEPT {return __table_.size() == 0;} 1274 _LIBCPP_INLINE_VISIBILITY 1275 size_type size() const _NOEXCEPT {return __table_.size();} 1276 _LIBCPP_INLINE_VISIBILITY 1277 size_type max_size() const _NOEXCEPT {return __table_.max_size();} 1278 1279 _LIBCPP_INLINE_VISIBILITY 1280 iterator begin() _NOEXCEPT {return __table_.begin();} 1281 _LIBCPP_INLINE_VISIBILITY 1282 iterator end() _NOEXCEPT {return __table_.end();} 1283 _LIBCPP_INLINE_VISIBILITY 1284 const_iterator begin() const _NOEXCEPT {return __table_.begin();} 1285 _LIBCPP_INLINE_VISIBILITY 1286 const_iterator end() const _NOEXCEPT {return __table_.end();} 1287 _LIBCPP_INLINE_VISIBILITY 1288 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();} 1289 _LIBCPP_INLINE_VISIBILITY 1290 const_iterator cend() const _NOEXCEPT {return __table_.end();} 1291 1292#ifndef _LIBCPP_CXX03_LANG 1293 template <class... _Args> 1294 _LIBCPP_INLINE_VISIBILITY 1295 iterator emplace(_Args&&... __args) 1296 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);} 1297 template <class... _Args> 1298 _LIBCPP_INLINE_VISIBILITY 1299 iterator emplace_hint(const_iterator __p, _Args&&... __args) 1300 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);} 1301 1302 _LIBCPP_INLINE_VISIBILITY 1303 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));} 1304 _LIBCPP_INLINE_VISIBILITY 1305 iterator insert(const_iterator __p, value_type&& __x) 1306 {return __table_.__insert_multi(__p, _VSTD::move(__x));} 1307 _LIBCPP_INLINE_VISIBILITY 1308 void insert(initializer_list<value_type> __il) 1309 {insert(__il.begin(), __il.end());} 1310#endif // _LIBCPP_CXX03_LANG 1311 1312 _LIBCPP_INLINE_VISIBILITY 1313 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} 1314 1315 _LIBCPP_INLINE_VISIBILITY 1316 iterator insert(const_iterator __p, const value_type& __x) 1317 {return __table_.__insert_multi(__p, __x);} 1318 1319 template <class _InputIterator> 1320 _LIBCPP_INLINE_VISIBILITY 1321 void insert(_InputIterator __first, _InputIterator __last); 1322 1323#if _LIBCPP_STD_VER > 14 1324 _LIBCPP_INLINE_VISIBILITY 1325 iterator insert(node_type&& __nh) 1326 { 1327 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 1328 "node_type with incompatible allocator passed to unordered_multiset::insert()"); 1329 return __table_.template __node_handle_insert_multi<node_type>( 1330 _VSTD::move(__nh)); 1331 } 1332 _LIBCPP_INLINE_VISIBILITY 1333 iterator insert(const_iterator __hint, node_type&& __nh) 1334 { 1335 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(), 1336 "node_type with incompatible allocator passed to unordered_multiset::insert()"); 1337 return __table_.template __node_handle_insert_multi<node_type>( 1338 __hint, _VSTD::move(__nh)); 1339 } 1340 _LIBCPP_INLINE_VISIBILITY 1341 node_type extract(const_iterator __position) 1342 { 1343 return __table_.template __node_handle_extract<node_type>( 1344 __position); 1345 } 1346 _LIBCPP_INLINE_VISIBILITY 1347 node_type extract(key_type const& __key) 1348 { 1349 return __table_.template __node_handle_extract<node_type>(__key); 1350 } 1351 1352 template <class _H2, class _P2> 1353 _LIBCPP_INLINE_VISIBILITY 1354 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source) 1355 { 1356 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1357 "merging container with incompatible allocator"); 1358 return __table_.__node_handle_merge_multi(__source.__table_); 1359 } 1360 template <class _H2, class _P2> 1361 _LIBCPP_INLINE_VISIBILITY 1362 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source) 1363 { 1364 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1365 "merging container with incompatible allocator"); 1366 return __table_.__node_handle_merge_multi(__source.__table_); 1367 } 1368 template <class _H2, class _P2> 1369 _LIBCPP_INLINE_VISIBILITY 1370 void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source) 1371 { 1372 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1373 "merging container with incompatible allocator"); 1374 return __table_.__node_handle_merge_multi(__source.__table_); 1375 } 1376 template <class _H2, class _P2> 1377 _LIBCPP_INLINE_VISIBILITY 1378 void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source) 1379 { 1380 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(), 1381 "merging container with incompatible allocator"); 1382 return __table_.__node_handle_merge_multi(__source.__table_); 1383 } 1384#endif 1385 1386 _LIBCPP_INLINE_VISIBILITY 1387 iterator erase(const_iterator __p) {return __table_.erase(__p);} 1388 _LIBCPP_INLINE_VISIBILITY 1389 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} 1390 _LIBCPP_INLINE_VISIBILITY 1391 iterator erase(const_iterator __first, const_iterator __last) 1392 {return __table_.erase(__first, __last);} 1393 _LIBCPP_INLINE_VISIBILITY 1394 void clear() _NOEXCEPT {__table_.clear();} 1395 1396 _LIBCPP_INLINE_VISIBILITY 1397 void swap(unordered_multiset& __u) 1398 _NOEXCEPT_(__is_nothrow_swappable<__table>::value) 1399 {__table_.swap(__u.__table_);} 1400 1401 _LIBCPP_INLINE_VISIBILITY 1402 hasher hash_function() const {return __table_.hash_function();} 1403 _LIBCPP_INLINE_VISIBILITY 1404 key_equal key_eq() const {return __table_.key_eq();} 1405 1406 _LIBCPP_INLINE_VISIBILITY 1407 iterator find(const key_type& __k) {return __table_.find(__k);} 1408 _LIBCPP_INLINE_VISIBILITY 1409 const_iterator find(const key_type& __k) const {return __table_.find(__k);} 1410#if _LIBCPP_STD_VER > 17 1411 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1412 _LIBCPP_INLINE_VISIBILITY 1413 iterator find(const _K2& __k) {return __table_.find(__k);} 1414 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1415 _LIBCPP_INLINE_VISIBILITY 1416 const_iterator find(const _K2& __k) const {return __table_.find(__k);} 1417#endif // _LIBCPP_STD_VER > 17 1418 1419 _LIBCPP_INLINE_VISIBILITY 1420 size_type count(const key_type& __k) const {return __table_.__count_multi(__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 size_type count(const _K2& __k) const {return __table_.__count_multi(__k);} 1425#endif // _LIBCPP_STD_VER > 17 1426 1427#if _LIBCPP_STD_VER > 17 1428 _LIBCPP_INLINE_VISIBILITY 1429 bool contains(const key_type& __k) const {return find(__k) != end();} 1430 1431 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1432 _LIBCPP_INLINE_VISIBILITY 1433 bool contains(const _K2& __k) const {return find(__k) != end();} 1434#endif // _LIBCPP_STD_VER > 17 1435 1436 _LIBCPP_INLINE_VISIBILITY 1437 pair<iterator, iterator> equal_range(const key_type& __k) 1438 {return __table_.__equal_range_multi(__k);} 1439 _LIBCPP_INLINE_VISIBILITY 1440 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const 1441 {return __table_.__equal_range_multi(__k);} 1442#if _LIBCPP_STD_VER > 17 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<iterator, iterator> equal_range(const _K2& __k) 1446 {return __table_.__equal_range_multi(__k);} 1447 template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr> 1448 _LIBCPP_INLINE_VISIBILITY 1449 pair<const_iterator, const_iterator> equal_range(const _K2& __k) const 1450 {return __table_.__equal_range_multi(__k);} 1451#endif // _LIBCPP_STD_VER > 17 1452 1453 _LIBCPP_INLINE_VISIBILITY 1454 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();} 1455 _LIBCPP_INLINE_VISIBILITY 1456 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();} 1457 1458 _LIBCPP_INLINE_VISIBILITY 1459 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);} 1460 _LIBCPP_INLINE_VISIBILITY 1461 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} 1462 1463 _LIBCPP_INLINE_VISIBILITY 1464 local_iterator begin(size_type __n) {return __table_.begin(__n);} 1465 _LIBCPP_INLINE_VISIBILITY 1466 local_iterator end(size_type __n) {return __table_.end(__n);} 1467 _LIBCPP_INLINE_VISIBILITY 1468 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} 1469 _LIBCPP_INLINE_VISIBILITY 1470 const_local_iterator end(size_type __n) const {return __table_.cend(__n);} 1471 _LIBCPP_INLINE_VISIBILITY 1472 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} 1473 _LIBCPP_INLINE_VISIBILITY 1474 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} 1475 1476 _LIBCPP_INLINE_VISIBILITY 1477 float load_factor() const _NOEXCEPT {return __table_.load_factor();} 1478 _LIBCPP_INLINE_VISIBILITY 1479 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();} 1480 _LIBCPP_INLINE_VISIBILITY 1481 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} 1482 _LIBCPP_INLINE_VISIBILITY 1483 void rehash(size_type __n) {__table_.rehash(__n);} 1484 _LIBCPP_INLINE_VISIBILITY 1485 void reserve(size_type __n) {__table_.reserve(__n);} 1486 1487#if _LIBCPP_DEBUG_LEVEL == 2 1488 1489 bool __dereferenceable(const const_iterator* __i) const 1490 {return __table_.__dereferenceable(__i);} 1491 bool __decrementable(const const_iterator* __i) const 1492 {return __table_.__decrementable(__i);} 1493 bool __addable(const const_iterator* __i, ptrdiff_t __n) const 1494 {return __table_.__addable(__i, __n);} 1495 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const 1496 {return __table_.__addable(__i, __n);} 1497 1498#endif // _LIBCPP_DEBUG_LEVEL == 2 1499 1500}; 1501 1502#if _LIBCPP_STD_VER >= 17 1503template<class _InputIterator, 1504 class _Hash = hash<__iter_value_type<_InputIterator>>, 1505 class _Pred = equal_to<__iter_value_type<_InputIterator>>, 1506 class _Allocator = allocator<__iter_value_type<_InputIterator>>, 1507 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1508 class = enable_if_t<!__is_allocator<_Hash>::value>, 1509 class = enable_if_t<!is_integral<_Hash>::value>, 1510 class = enable_if_t<!__is_allocator<_Pred>::value>, 1511 class = enable_if_t<__is_allocator<_Allocator>::value>> 1512unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, 1513 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) 1514 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>; 1515 1516template<class _Tp, class _Hash = hash<_Tp>, 1517 class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>, 1518 class = enable_if_t<!__is_allocator<_Hash>::value>, 1519 class = enable_if_t<!is_integral<_Hash>::value>, 1520 class = enable_if_t<!__is_allocator<_Pred>::value>, 1521 class = enable_if_t<__is_allocator<_Allocator>::value>> 1522unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0, 1523 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) 1524 -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>; 1525 1526template<class _InputIterator, class _Allocator, 1527 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1528 class = enable_if_t<__is_allocator<_Allocator>::value>> 1529unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) 1530 -> unordered_multiset<__iter_value_type<_InputIterator>, 1531 hash<__iter_value_type<_InputIterator>>, 1532 equal_to<__iter_value_type<_InputIterator>>, 1533 _Allocator>; 1534 1535template<class _InputIterator, class _Hash, class _Allocator, 1536 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1537 class = enable_if_t<!__is_allocator<_Hash>::value>, 1538 class = enable_if_t<!is_integral<_Hash>::value>, 1539 class = enable_if_t<__is_allocator<_Allocator>::value>> 1540unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, 1541 _Hash, _Allocator) 1542 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, 1543 equal_to<__iter_value_type<_InputIterator>>, 1544 _Allocator>; 1545 1546template<class _Tp, class _Allocator, 1547 class = enable_if_t<__is_allocator<_Allocator>::value>> 1548unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator) 1549 -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>; 1550 1551template<class _Tp, class _Hash, class _Allocator, 1552 class = enable_if_t<!__is_allocator<_Hash>::value>, 1553 class = enable_if_t<!is_integral<_Hash>::value>, 1554 class = enable_if_t<__is_allocator<_Allocator>::value>> 1555unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) 1556 -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>; 1557#endif 1558 1559template <class _Value, class _Hash, class _Pred, class _Alloc> 1560unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1561 size_type __n, const hasher& __hf, const key_equal& __eql) 1562 : __table_(__hf, __eql) 1563{ 1564 _VSTD::__debug_db_insert_c(this); 1565 __table_.rehash(__n); 1566} 1567 1568template <class _Value, class _Hash, class _Pred, class _Alloc> 1569unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1570 size_type __n, const hasher& __hf, const key_equal& __eql, 1571 const allocator_type& __a) 1572 : __table_(__hf, __eql, __a) 1573{ 1574 _VSTD::__debug_db_insert_c(this); 1575 __table_.rehash(__n); 1576} 1577 1578template <class _Value, class _Hash, class _Pred, class _Alloc> 1579template <class _InputIterator> 1580unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1581 _InputIterator __first, _InputIterator __last) 1582{ 1583 _VSTD::__debug_db_insert_c(this); 1584 insert(__first, __last); 1585} 1586 1587template <class _Value, class _Hash, class _Pred, class _Alloc> 1588template <class _InputIterator> 1589unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1590 _InputIterator __first, _InputIterator __last, size_type __n, 1591 const hasher& __hf, const key_equal& __eql) 1592 : __table_(__hf, __eql) 1593{ 1594 _VSTD::__debug_db_insert_c(this); 1595 __table_.rehash(__n); 1596 insert(__first, __last); 1597} 1598 1599template <class _Value, class _Hash, class _Pred, class _Alloc> 1600template <class _InputIterator> 1601unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1602 _InputIterator __first, _InputIterator __last, size_type __n, 1603 const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 1604 : __table_(__hf, __eql, __a) 1605{ 1606 _VSTD::__debug_db_insert_c(this); 1607 __table_.rehash(__n); 1608 insert(__first, __last); 1609} 1610 1611template <class _Value, class _Hash, class _Pred, class _Alloc> 1612inline 1613unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1614 const allocator_type& __a) 1615 : __table_(__a) 1616{ 1617 _VSTD::__debug_db_insert_c(this); 1618} 1619 1620template <class _Value, class _Hash, class _Pred, class _Alloc> 1621unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1622 const unordered_multiset& __u) 1623 : __table_(__u.__table_) 1624{ 1625 _VSTD::__debug_db_insert_c(this); 1626 __table_.rehash(__u.bucket_count()); 1627 insert(__u.begin(), __u.end()); 1628} 1629 1630template <class _Value, class _Hash, class _Pred, class _Alloc> 1631unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1632 const unordered_multiset& __u, const allocator_type& __a) 1633 : __table_(__u.__table_, __a) 1634{ 1635 _VSTD::__debug_db_insert_c(this); 1636 __table_.rehash(__u.bucket_count()); 1637 insert(__u.begin(), __u.end()); 1638} 1639 1640#ifndef _LIBCPP_CXX03_LANG 1641 1642template <class _Value, class _Hash, class _Pred, class _Alloc> 1643inline 1644unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1645 unordered_multiset&& __u) 1646 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value) 1647 : __table_(_VSTD::move(__u.__table_)) 1648{ 1649 _VSTD::__debug_db_insert_c(this); 1650#if _LIBCPP_DEBUG_LEVEL == 2 1651 __get_db()->swap(this, _VSTD::addressof(__u)); 1652#endif 1653} 1654 1655template <class _Value, class _Hash, class _Pred, class _Alloc> 1656unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1657 unordered_multiset&& __u, const allocator_type& __a) 1658 : __table_(_VSTD::move(__u.__table_), __a) 1659{ 1660 _VSTD::__debug_db_insert_c(this); 1661 if (__a != __u.get_allocator()) 1662 { 1663 iterator __i = __u.begin(); 1664 while (__u.size() != 0) 1665 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_)); 1666 } 1667#if _LIBCPP_DEBUG_LEVEL == 2 1668 else 1669 __get_db()->swap(this, _VSTD::addressof(__u)); 1670#endif 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) 1676{ 1677 _VSTD::__debug_db_insert_c(this); 1678 insert(__il.begin(), __il.end()); 1679} 1680 1681template <class _Value, class _Hash, class _Pred, class _Alloc> 1682unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1683 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1684 const key_equal& __eql) 1685 : __table_(__hf, __eql) 1686{ 1687 _VSTD::__debug_db_insert_c(this); 1688 __table_.rehash(__n); 1689 insert(__il.begin(), __il.end()); 1690} 1691 1692template <class _Value, class _Hash, class _Pred, class _Alloc> 1693unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( 1694 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1695 const key_equal& __eql, const allocator_type& __a) 1696 : __table_(__hf, __eql, __a) 1697{ 1698 _VSTD::__debug_db_insert_c(this); 1699 __table_.rehash(__n); 1700 insert(__il.begin(), __il.end()); 1701} 1702 1703template <class _Value, class _Hash, class _Pred, class _Alloc> 1704inline 1705unordered_multiset<_Value, _Hash, _Pred, _Alloc>& 1706unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( 1707 unordered_multiset&& __u) 1708 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) 1709{ 1710 __table_ = _VSTD::move(__u.__table_); 1711 return *this; 1712} 1713 1714template <class _Value, class _Hash, class _Pred, class _Alloc> 1715inline 1716unordered_multiset<_Value, _Hash, _Pred, _Alloc>& 1717unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=( 1718 initializer_list<value_type> __il) 1719{ 1720 __table_.__assign_multi(__il.begin(), __il.end()); 1721 return *this; 1722} 1723 1724#endif // _LIBCPP_CXX03_LANG 1725 1726template <class _Value, class _Hash, class _Pred, class _Alloc> 1727template <class _InputIterator> 1728inline 1729void 1730unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 1731 _InputIterator __last) 1732{ 1733 for (; __first != __last; ++__first) 1734 __table_.__insert_multi(*__first); 1735} 1736 1737template <class _Value, class _Hash, class _Pred, class _Alloc> 1738inline _LIBCPP_INLINE_VISIBILITY 1739void 1740swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, 1741 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) 1742 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 1743{ 1744 __x.swap(__y); 1745} 1746 1747#if _LIBCPP_STD_VER > 17 1748template <class _Value, class _Hash, class _Pred, class _Alloc, 1749 class _Predicate> 1750inline _LIBCPP_INLINE_VISIBILITY 1751 typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type 1752 erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c, 1753 _Predicate __pred) { 1754 return _VSTD::__libcpp_erase_if_container(__c, __pred); 1755} 1756#endif 1757 1758template <class _Value, class _Hash, class _Pred, class _Alloc> 1759bool 1760operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, 1761 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) 1762{ 1763 if (__x.size() != __y.size()) 1764 return false; 1765 typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator 1766 const_iterator; 1767 typedef pair<const_iterator, const_iterator> _EqRng; 1768 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) 1769 { 1770 _EqRng __xeq = __x.equal_range(*__i); 1771 _EqRng __yeq = __y.equal_range(*__i); 1772 if (_VSTD::distance(__xeq.first, __xeq.second) != 1773 _VSTD::distance(__yeq.first, __yeq.second) || 1774 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) 1775 return false; 1776 __i = __xeq.second; 1777 } 1778 return true; 1779} 1780 1781template <class _Value, class _Hash, class _Pred, class _Alloc> 1782inline _LIBCPP_INLINE_VISIBILITY 1783bool 1784operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, 1785 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) 1786{ 1787 return !(__x == __y); 1788} 1789 1790_LIBCPP_END_NAMESPACE_STD 1791 1792#endif // _LIBCPP_UNORDERED_SET 1793