unordered_set 84 KB

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