unordered_set 86 KB

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