unordered_map 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561
  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_MAP
  10. #define _LIBCPP_UNORDERED_MAP
  11. /*
  12. unordered_map synopsis
  13. #include <initializer_list>
  14. namespace std
  15. {
  16. template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
  17. class Alloc = allocator<pair<const Key, T>>>
  18. class unordered_map
  19. {
  20. public:
  21. // types
  22. typedef Key key_type;
  23. typedef T mapped_type;
  24. typedef Hash hasher;
  25. typedef Pred key_equal;
  26. typedef Alloc allocator_type;
  27. typedef pair<const key_type, mapped_type> value_type;
  28. typedef value_type& reference;
  29. typedef const value_type& const_reference;
  30. typedef typename allocator_traits<allocator_type>::pointer pointer;
  31. typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
  32. typedef typename allocator_traits<allocator_type>::size_type size_type;
  33. typedef typename allocator_traits<allocator_type>::difference_type difference_type;
  34. typedef /unspecified/ iterator;
  35. typedef /unspecified/ const_iterator;
  36. typedef /unspecified/ local_iterator;
  37. typedef /unspecified/ const_local_iterator;
  38. typedef unspecified node_type; // C++17
  39. typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
  40. unordered_map()
  41. noexcept(
  42. is_nothrow_default_constructible<hasher>::value &&
  43. is_nothrow_default_constructible<key_equal>::value &&
  44. is_nothrow_default_constructible<allocator_type>::value);
  45. explicit unordered_map(size_type n, const hasher& hf = hasher(),
  46. const key_equal& eql = key_equal(),
  47. const allocator_type& a = allocator_type());
  48. template <class InputIterator>
  49. unordered_map(InputIterator f, InputIterator l,
  50. size_type n = 0, const hasher& hf = hasher(),
  51. const key_equal& eql = key_equal(),
  52. const allocator_type& a = allocator_type());
  53. template<container-compatible-range<value_type> R>
  54. unordered_map(from_range_t, R&& rg, size_type n = see below,
  55. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  56. const allocator_type& a = allocator_type()); // C++23
  57. explicit unordered_map(const allocator_type&);
  58. unordered_map(const unordered_map&);
  59. unordered_map(const unordered_map&, const Allocator&);
  60. unordered_map(unordered_map&&)
  61. noexcept(
  62. is_nothrow_move_constructible<hasher>::value &&
  63. is_nothrow_move_constructible<key_equal>::value &&
  64. is_nothrow_move_constructible<allocator_type>::value);
  65. unordered_map(unordered_map&&, const Allocator&);
  66. unordered_map(initializer_list<value_type>, size_type n = 0,
  67. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  68. const allocator_type& a = allocator_type());
  69. unordered_map(size_type n, const allocator_type& a)
  70. : unordered_map(n, hasher(), key_equal(), a) {} // C++14
  71. unordered_map(size_type n, const hasher& hf, const allocator_type& a)
  72. : unordered_map(n, hf, key_equal(), a) {} // C++14
  73. template <class InputIterator>
  74. unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
  75. : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14
  76. template <class InputIterator>
  77. unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf,
  78. const allocator_type& a)
  79. : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14
  80. template<container-compatible-range<value_type> R>
  81. unordered_map(from_range_t, R&& rg, size_type n, const allocator_type& a)
  82. : unordered_map(from_range, std::forward<R>(rg), n, hasher(), key_equal(), a) { } // C++23
  83. template<container-compatible-range<value_type> R>
  84. unordered_map(from_range_t, R&& rg, size_type n, const hasher& hf, const allocator_type& a)
  85. : unordered_map(from_range, std::forward<R>(rg), n, hf, key_equal(), a) { } // C++23
  86. unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a)
  87. : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14
  88. unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
  89. const allocator_type& a)
  90. : unordered_map(il, n, hf, key_equal(), a) {} // C++14
  91. ~unordered_map();
  92. unordered_map& operator=(const unordered_map&);
  93. unordered_map& operator=(unordered_map&&)
  94. noexcept(
  95. allocator_type::propagate_on_container_move_assignment::value &&
  96. is_nothrow_move_assignable<allocator_type>::value &&
  97. is_nothrow_move_assignable<hasher>::value &&
  98. is_nothrow_move_assignable<key_equal>::value);
  99. unordered_map& operator=(initializer_list<value_type>);
  100. allocator_type get_allocator() const noexcept;
  101. bool empty() const noexcept;
  102. size_type size() const noexcept;
  103. size_type max_size() const noexcept;
  104. iterator begin() noexcept;
  105. iterator end() noexcept;
  106. const_iterator begin() const noexcept;
  107. const_iterator end() const noexcept;
  108. const_iterator cbegin() const noexcept;
  109. const_iterator cend() const noexcept;
  110. template <class... Args>
  111. pair<iterator, bool> emplace(Args&&... args);
  112. template <class... Args>
  113. iterator emplace_hint(const_iterator position, Args&&... args);
  114. pair<iterator, bool> insert(const value_type& obj);
  115. template <class P>
  116. pair<iterator, bool> insert(P&& obj);
  117. iterator insert(const_iterator hint, const value_type& obj);
  118. template <class P>
  119. iterator insert(const_iterator hint, P&& obj);
  120. template <class InputIterator>
  121. void insert(InputIterator first, InputIterator last);
  122. template<container-compatible-range<value_type> R>
  123. void insert_range(R&& rg); // C++23
  124. void insert(initializer_list<value_type>);
  125. node_type extract(const_iterator position); // C++17
  126. node_type extract(const key_type& x); // C++17
  127. insert_return_type insert(node_type&& nh); // C++17
  128. iterator insert(const_iterator hint, node_type&& nh); // C++17
  129. template <class... Args>
  130. pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
  131. template <class... Args>
  132. pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
  133. template <class... Args>
  134. iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
  135. template <class... Args>
  136. iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
  137. template <class M>
  138. pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
  139. template <class M>
  140. pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
  141. template <class M>
  142. iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
  143. template <class M>
  144. iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
  145. iterator erase(const_iterator position);
  146. iterator erase(iterator position); // C++14
  147. size_type erase(const key_type& k);
  148. iterator erase(const_iterator first, const_iterator last);
  149. void clear() noexcept;
  150. template<class H2, class P2>
  151. void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17
  152. template<class H2, class P2>
  153. void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17
  154. template<class H2, class P2>
  155. void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source); // C++17
  156. template<class H2, class P2>
  157. void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17
  158. void swap(unordered_map&)
  159. noexcept(
  160. (!allocator_type::propagate_on_container_swap::value ||
  161. __is_nothrow_swappable<allocator_type>::value) &&
  162. __is_nothrow_swappable<hasher>::value &&
  163. __is_nothrow_swappable<key_equal>::value);
  164. hasher hash_function() const;
  165. key_equal key_eq() const;
  166. iterator find(const key_type& k);
  167. const_iterator find(const key_type& k) const;
  168. template<typename K>
  169. iterator find(const K& x); // C++20
  170. template<typename K>
  171. const_iterator find(const K& x) const; // C++20
  172. size_type count(const key_type& k) const;
  173. template<typename K>
  174. size_type count(const K& k) const; // C++20
  175. bool contains(const key_type& k) const; // C++20
  176. template<typename K>
  177. bool contains(const K& k) const; // C++20
  178. pair<iterator, iterator> equal_range(const key_type& k);
  179. pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
  180. template<typename K>
  181. pair<iterator, iterator> equal_range(const K& k); // C++20
  182. template<typename K>
  183. pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
  184. mapped_type& operator[](const key_type& k);
  185. mapped_type& operator[](key_type&& k);
  186. mapped_type& at(const key_type& k);
  187. const mapped_type& at(const key_type& k) const;
  188. size_type bucket_count() const noexcept;
  189. size_type max_bucket_count() const noexcept;
  190. size_type bucket_size(size_type n) const;
  191. size_type bucket(const key_type& k) const;
  192. local_iterator begin(size_type n);
  193. local_iterator end(size_type n);
  194. const_local_iterator begin(size_type n) const;
  195. const_local_iterator end(size_type n) const;
  196. const_local_iterator cbegin(size_type n) const;
  197. const_local_iterator cend(size_type n) const;
  198. float load_factor() const noexcept;
  199. float max_load_factor() const noexcept;
  200. void max_load_factor(float z);
  201. void rehash(size_type n);
  202. void reserve(size_type n);
  203. };
  204. template<class InputIterator,
  205. class Hash = hash<iter_key_t<InputIterator>>, class Pred = equal_to<iter_key_t<InputIterator>>,
  206. class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
  207. unordered_map(InputIterator, InputIterator, typename see below::size_type = see below,
  208. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  209. -> unordered_map<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
  210. Allocator>; // C++17
  211. template<ranges::input_range R, class Hash = hash<range-key-type<R>>,
  212. class Pred = equal_to<range-key-type<R>>,
  213. class Allocator = allocator<range-to-alloc-type<R>>>
  214. unordered_map(from_range_t, R&&, typename see below::size_type = see below,
  215. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  216. -> unordered_map<range-key-type<R>, range-mapped-type<R>, Hash, Pred, Allocator>; // C++23
  217. template<class Key, class T, class Hash = hash<Key>,
  218. class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
  219. unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type = see below,
  220. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  221. -> unordered_map<Key, T, Hash, Pred, Allocator>; // C++17
  222. template<class InputIterator, class Allocator>
  223. unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator)
  224. -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
  225. hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
  226. template<class InputIterator, class Allocator>
  227. unordered_map(InputIterator, InputIterator, Allocator)
  228. -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
  229. hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
  230. template<class InputIterator, class Hash, class Allocator>
  231. unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
  232. -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
  233. equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
  234. template<ranges::input_range R, class Allocator>
  235. unordered_map(from_range_t, R&&, typename see below::size_type, Allocator)
  236. -> unordered_map<range-key-type<R>, range-mapped-type<R>, hash<range-key-type<R>>,
  237. equal_to<range-key-type<R>>, Allocator>; // C++23
  238. template<ranges::input_range R, class Allocator>
  239. unordered_map(from_range_t, R&&, Allocator)
  240. -> unordered_map<range-key-type<R>, range-mapped-type<R>, hash<range-key-type<R>>,
  241. equal_to<range-key-type<R>>, Allocator>; // C++23
  242. template<ranges::input_range R, class Hash, class Allocator>
  243. unordered_map(from_range_t, R&&, typename see below::size_type, Hash, Allocator)
  244. -> unordered_map<range-key-type<R>, range-mapped-type<R>, Hash,
  245. equal_to<range-key-type<R>>, Allocator>; // C++23
  246. template<class Key, class T, typename Allocator>
  247. unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type, Allocator)
  248. -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
  249. template<class Key, class T, typename Allocator>
  250. unordered_map(initializer_list<pair<const Key, T>>, Allocator)
  251. -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
  252. template<class Key, class T, class Hash, class Allocator>
  253. unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type, Hash, Allocator)
  254. -> unordered_map<Key, T, Hash, equal_to<Key>, Allocator>; // C++17
  255. template <class Key, class T, class Hash, class Pred, class Alloc>
  256. void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
  257. unordered_map<Key, T, Hash, Pred, Alloc>& y)
  258. noexcept(noexcept(x.swap(y)));
  259. template <class Key, class T, class Hash, class Pred, class Alloc>
  260. bool
  261. operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
  262. const unordered_map<Key, T, Hash, Pred, Alloc>& y);
  263. template <class Key, class T, class Hash, class Pred, class Alloc>
  264. bool
  265. operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
  266. const unordered_map<Key, T, Hash, Pred, Alloc>& y); // Removed in C++20
  267. template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
  268. class Alloc = allocator<pair<const Key, T>>>
  269. class unordered_multimap
  270. {
  271. public:
  272. // types
  273. typedef Key key_type;
  274. typedef T mapped_type;
  275. typedef Hash hasher;
  276. typedef Pred key_equal;
  277. typedef Alloc allocator_type;
  278. typedef pair<const key_type, mapped_type> value_type;
  279. typedef value_type& reference;
  280. typedef const value_type& const_reference;
  281. typedef typename allocator_traits<allocator_type>::pointer pointer;
  282. typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
  283. typedef typename allocator_traits<allocator_type>::size_type size_type;
  284. typedef typename allocator_traits<allocator_type>::difference_type difference_type;
  285. typedef /unspecified/ iterator;
  286. typedef /unspecified/ const_iterator;
  287. typedef /unspecified/ local_iterator;
  288. typedef /unspecified/ const_local_iterator;
  289. typedef unspecified node_type; // C++17
  290. unordered_multimap()
  291. noexcept(
  292. is_nothrow_default_constructible<hasher>::value &&
  293. is_nothrow_default_constructible<key_equal>::value &&
  294. is_nothrow_default_constructible<allocator_type>::value);
  295. explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
  296. const key_equal& eql = key_equal(),
  297. const allocator_type& a = allocator_type());
  298. template <class InputIterator>
  299. unordered_multimap(InputIterator f, InputIterator l,
  300. size_type n = 0, const hasher& hf = hasher(),
  301. const key_equal& eql = key_equal(),
  302. const allocator_type& a = allocator_type());
  303. template<container-compatible-range<value_type> R>
  304. unordered_multimap(from_range_t, R&& rg, size_type n = see below,
  305. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  306. const allocator_type& a = allocator_type()); // C++23
  307. explicit unordered_multimap(const allocator_type&);
  308. unordered_multimap(const unordered_multimap&);
  309. unordered_multimap(const unordered_multimap&, const Allocator&);
  310. unordered_multimap(unordered_multimap&&)
  311. noexcept(
  312. is_nothrow_move_constructible<hasher>::value &&
  313. is_nothrow_move_constructible<key_equal>::value &&
  314. is_nothrow_move_constructible<allocator_type>::value);
  315. unordered_multimap(unordered_multimap&&, const Allocator&);
  316. unordered_multimap(initializer_list<value_type>, size_type n = 0,
  317. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  318. const allocator_type& a = allocator_type());
  319. unordered_multimap(size_type n, const allocator_type& a)
  320. : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
  321. unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
  322. : unordered_multimap(n, hf, key_equal(), a) {} // C++14
  323. template <class InputIterator>
  324. unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
  325. : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
  326. template <class InputIterator>
  327. unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
  328. const allocator_type& a)
  329. : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
  330. template<container-compatible-range<value_type> R>
  331. unordered_multimap(from_range_t, R&& rg, size_type n, const allocator_type& a)
  332. : unordered_multimap(from_range, std::forward<R>(rg), n, hasher(), key_equal(), a) { } // C++23
  333. template<container-compatible-range<value_type> R>
  334. unordered_multimap(from_range_t, R&& rg, size_type n, const hasher& hf, const allocator_type& a)
  335. : unordered_multimap(from_range, std::forward<R>(rg), n, hf, key_equal(), a) { } // C++23
  336. unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
  337. : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
  338. unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
  339. const allocator_type& a)
  340. : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
  341. ~unordered_multimap();
  342. unordered_multimap& operator=(const unordered_multimap&);
  343. unordered_multimap& operator=(unordered_multimap&&)
  344. noexcept(
  345. allocator_type::propagate_on_container_move_assignment::value &&
  346. is_nothrow_move_assignable<allocator_type>::value &&
  347. is_nothrow_move_assignable<hasher>::value &&
  348. is_nothrow_move_assignable<key_equal>::value);
  349. unordered_multimap& operator=(initializer_list<value_type>);
  350. allocator_type get_allocator() const noexcept;
  351. bool empty() const noexcept;
  352. size_type size() const noexcept;
  353. size_type max_size() const noexcept;
  354. iterator begin() noexcept;
  355. iterator end() noexcept;
  356. const_iterator begin() const noexcept;
  357. const_iterator end() const noexcept;
  358. const_iterator cbegin() const noexcept;
  359. const_iterator cend() const noexcept;
  360. template <class... Args>
  361. iterator emplace(Args&&... args);
  362. template <class... Args>
  363. iterator emplace_hint(const_iterator position, Args&&... args);
  364. iterator insert(const value_type& obj);
  365. template <class P>
  366. iterator insert(P&& obj);
  367. iterator insert(const_iterator hint, const value_type& obj);
  368. template <class P>
  369. iterator insert(const_iterator hint, P&& obj);
  370. template <class InputIterator>
  371. void insert(InputIterator first, InputIterator last);
  372. template<container-compatible-range<value_type> R>
  373. void insert_range(R&& rg); // C++23
  374. void insert(initializer_list<value_type>);
  375. node_type extract(const_iterator position); // C++17
  376. node_type extract(const key_type& x); // C++17
  377. iterator insert(node_type&& nh); // C++17
  378. iterator insert(const_iterator hint, node_type&& nh); // C++17
  379. iterator erase(const_iterator position);
  380. iterator erase(iterator position); // C++14
  381. size_type erase(const key_type& k);
  382. iterator erase(const_iterator first, const_iterator last);
  383. void clear() noexcept;
  384. template<class H2, class P2>
  385. void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source); // C++17
  386. template<class H2, class P2>
  387. void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17
  388. template<class H2, class P2>
  389. void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17
  390. template<class H2, class P2>
  391. void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17
  392. void swap(unordered_multimap&)
  393. noexcept(
  394. (!allocator_type::propagate_on_container_swap::value ||
  395. __is_nothrow_swappable<allocator_type>::value) &&
  396. __is_nothrow_swappable<hasher>::value &&
  397. __is_nothrow_swappable<key_equal>::value);
  398. hasher hash_function() const;
  399. key_equal key_eq() const;
  400. iterator find(const key_type& k);
  401. const_iterator find(const key_type& k) const;
  402. template<typename K>
  403. iterator find(const K& x); // C++20
  404. template<typename K>
  405. const_iterator find(const K& x) const; // C++20
  406. size_type count(const key_type& k) const;
  407. template<typename K>
  408. size_type count(const K& k) const; // C++20
  409. bool contains(const key_type& k) const; // C++20
  410. template<typename K>
  411. bool contains(const K& k) const; // C++20
  412. pair<iterator, iterator> equal_range(const key_type& k);
  413. pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
  414. template<typename K>
  415. pair<iterator, iterator> equal_range(const K& k); // C++20
  416. template<typename K>
  417. pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
  418. size_type bucket_count() const noexcept;
  419. size_type max_bucket_count() const noexcept;
  420. size_type bucket_size(size_type n) const;
  421. size_type bucket(const key_type& k) const;
  422. local_iterator begin(size_type n);
  423. local_iterator end(size_type n);
  424. const_local_iterator begin(size_type n) const;
  425. const_local_iterator end(size_type n) const;
  426. const_local_iterator cbegin(size_type n) const;
  427. const_local_iterator cend(size_type n) const;
  428. float load_factor() const noexcept;
  429. float max_load_factor() const noexcept;
  430. void max_load_factor(float z);
  431. void rehash(size_type n);
  432. void reserve(size_type n);
  433. };
  434. template<class InputIterator,
  435. class Hash = hash<iter_key_t<InputIterator>>, class Pred = equal_to<iter_key_t<InputIterator>>,
  436. class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
  437. unordered_multimap(InputIterator, InputIterator, typename see below::size_type = see below,
  438. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  439. -> unordered_multimap<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
  440. Allocator>; // C++17
  441. template<ranges::input_range R, class Hash = hash<range-key-type<R>>,
  442. class Pred = equal_to<range-key-type<R>>,
  443. class Allocator = allocator<range-to-alloc-type<R>>>
  444. unordered_multimap(from_range_t, R&&, typename see below::size_type = see below,
  445. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  446. -> unordered_multimap<range-key-type<R>, range-mapped-type<R>, Hash, Pred, Allocator>; // C++23
  447. template<class Key, class T, class Hash = hash<Key>,
  448. class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
  449. unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type = see below,
  450. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  451. -> unordered_multimap<Key, T, Hash, Pred, Allocator>; // C++17
  452. template<class InputIterator, class Allocator>
  453. unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Allocator)
  454. -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
  455. hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
  456. template<class InputIterator, class Allocator>
  457. unordered_multimap(InputIterator, InputIterator, Allocator)
  458. -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
  459. hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
  460. template<class InputIterator, class Hash, class Allocator>
  461. unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
  462. -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
  463. equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
  464. template<ranges::input_range R, class Allocator>
  465. unordered_multimap(from_range_t, R&&, typename see below::size_type, Allocator)
  466. -> unordered_multimap<range-key-type<R>, range-mapped-type<R>, hash<range-key-type<R>>,
  467. equal_to<range-key-type<R>>, Allocator>; // C++23
  468. template<ranges::input_range R, class Allocator>
  469. unordered_multimap(from_range_t, R&&, Allocator)
  470. -> unordered_multimap<range-key-type<R>, range-mapped-type<R>, hash<range-key-type<R>>,
  471. equal_to<range-key-type<R>>, Allocator>; // C++23
  472. template<ranges::input_range R, class Hash, class Allocator>
  473. unordered_multimap(from_range_t, R&&, typename see below::size_type, Hash, Allocator)
  474. -> unordered_multimap<range-key-type<R>, range-mapped-type<R>, Hash,
  475. equal_to<range-key-type<R>>, Allocator>; // C++23
  476. template<class Key, class T, typename Allocator>
  477. unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type, Allocator)
  478. -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
  479. template<class Key, class T, typename Allocator>
  480. unordered_multimap(initializer_list<pair<const Key, T>>, Allocator)
  481. -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
  482. template<class Key, class T, class Hash, class Allocator>
  483. unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type, Hash,
  484. Allocator)
  485. -> unordered_multimap<Key, T, Hash, equal_to<Key>, Allocator>; // C++17
  486. template <class Key, class T, class Hash, class Pred, class Alloc>
  487. void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
  488. unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
  489. noexcept(noexcept(x.swap(y)));
  490. template <class K, class T, class H, class P, class A, class Predicate>
  491. typename unordered_map<K, T, H, P, A>::size_type
  492. erase_if(unordered_map<K, T, H, P, A>& c, Predicate pred); // C++20
  493. template <class K, class T, class H, class P, class A, class Predicate>
  494. typename unordered_multimap<K, T, H, P, A>::size_type
  495. erase_if(unordered_multimap<K, T, H, P, A>& c, Predicate pred); // C++20
  496. template <class Key, class T, class Hash, class Pred, class Alloc>
  497. bool
  498. operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
  499. const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
  500. template <class Key, class T, class Hash, class Pred, class Alloc>
  501. bool
  502. operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
  503. const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); // Removed in C++20
  504. } // std
  505. */
  506. #include <__algorithm/is_permutation.h>
  507. #include <__assert>
  508. #include <__availability>
  509. #include <__config>
  510. #include <__functional/is_transparent.h>
  511. #include <__functional/operations.h>
  512. #include <__hash_table>
  513. #include <__iterator/distance.h>
  514. #include <__iterator/erase_if_container.h>
  515. #include <__iterator/iterator_traits.h>
  516. #include <__iterator/ranges_iterator_traits.h>
  517. #include <__memory/addressof.h>
  518. #include <__memory/allocator.h>
  519. #include <__memory_resource/polymorphic_allocator.h>
  520. #include <__node_handle>
  521. #include <__ranges/concepts.h>
  522. #include <__ranges/container_compatible_range.h>
  523. #include <__ranges/from_range.h>
  524. #include <__type_traits/is_allocator.h>
  525. #include <__type_traits/type_identity.h>
  526. #include <__utility/forward.h>
  527. #include <stdexcept>
  528. #include <tuple>
  529. #include <version>
  530. // standard-mandated includes
  531. // [iterator.range]
  532. #include <__iterator/access.h>
  533. #include <__iterator/data.h>
  534. #include <__iterator/empty.h>
  535. #include <__iterator/reverse_access.h>
  536. #include <__iterator/size.h>
  537. // [unord.map.syn]
  538. #include <compare>
  539. #include <initializer_list>
  540. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  541. # pragma GCC system_header
  542. #endif
  543. _LIBCPP_PUSH_MACROS
  544. #include <__undef_macros>
  545. _LIBCPP_BEGIN_NAMESPACE_STD
  546. template <class _Key,
  547. class _Cp,
  548. class _Hash,
  549. class _Pred,
  550. bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value>
  551. class __unordered_map_hasher : private _Hash {
  552. public:
  553. _LIBCPP_HIDE_FROM_ABI __unordered_map_hasher() _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value) : _Hash() {}
  554. _LIBCPP_HIDE_FROM_ABI __unordered_map_hasher(const _Hash& __h) _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
  555. : _Hash(__h) {}
  556. _LIBCPP_HIDE_FROM_ABI const _Hash& hash_function() const _NOEXCEPT { return *this; }
  557. _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Cp& __x) const {
  558. return static_cast<const _Hash&>(*this)(__x.__get_value().first);
  559. }
  560. _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Key& __x) const { return static_cast<const _Hash&>(*this)(__x); }
  561. #if _LIBCPP_STD_VER >= 20
  562. template <typename _K2>
  563. _LIBCPP_HIDE_FROM_ABI size_t operator()(const _K2& __x) const {
  564. return static_cast<const _Hash&>(*this)(__x);
  565. }
  566. #endif
  567. _LIBCPP_HIDE_FROM_ABI void swap(__unordered_map_hasher& __y) _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) {
  568. using std::swap;
  569. swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
  570. }
  571. };
  572. template <class _Key, class _Cp, class _Hash, class _Pred>
  573. class __unordered_map_hasher<_Key, _Cp, _Hash, _Pred, false> {
  574. _Hash __hash_;
  575. public:
  576. _LIBCPP_HIDE_FROM_ABI __unordered_map_hasher() _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
  577. : __hash_() {}
  578. _LIBCPP_HIDE_FROM_ABI __unordered_map_hasher(const _Hash& __h) _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
  579. : __hash_(__h) {}
  580. _LIBCPP_HIDE_FROM_ABI const _Hash& hash_function() const _NOEXCEPT { return __hash_; }
  581. _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Cp& __x) const { return __hash_(__x.__get_value().first); }
  582. _LIBCPP_HIDE_FROM_ABI size_t operator()(const _Key& __x) const { return __hash_(__x); }
  583. #if _LIBCPP_STD_VER >= 20
  584. template <typename _K2>
  585. _LIBCPP_HIDE_FROM_ABI size_t operator()(const _K2& __x) const {
  586. return __hash_(__x);
  587. }
  588. #endif
  589. _LIBCPP_HIDE_FROM_ABI void swap(__unordered_map_hasher& __y) _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) {
  590. using std::swap;
  591. swap(__hash_, __y.__hash_);
  592. }
  593. };
  594. template <class _Key, class _Cp, class _Hash, class _Pred, bool __b>
  595. inline _LIBCPP_HIDE_FROM_ABI void
  596. swap(__unordered_map_hasher<_Key, _Cp, _Hash, _Pred, __b>& __x,
  597. __unordered_map_hasher<_Key, _Cp, _Hash, _Pred, __b>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
  598. __x.swap(__y);
  599. }
  600. template <class _Key,
  601. class _Cp,
  602. class _Pred,
  603. class _Hash,
  604. bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value>
  605. class __unordered_map_equal : private _Pred {
  606. public:
  607. _LIBCPP_HIDE_FROM_ABI __unordered_map_equal() _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value) : _Pred() {}
  608. _LIBCPP_HIDE_FROM_ABI __unordered_map_equal(const _Pred& __p) _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
  609. : _Pred(__p) {}
  610. _LIBCPP_HIDE_FROM_ABI const _Pred& key_eq() const _NOEXCEPT { return *this; }
  611. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Cp& __y) const {
  612. return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);
  613. }
  614. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Key& __y) const {
  615. return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);
  616. }
  617. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _Cp& __y) const {
  618. return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);
  619. }
  620. #if _LIBCPP_STD_VER >= 20
  621. template <typename _K2>
  622. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _K2& __y) const {
  623. return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);
  624. }
  625. template <typename _K2>
  626. _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _Cp& __y) const {
  627. return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);
  628. }
  629. template <typename _K2>
  630. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _K2& __y) const {
  631. return static_cast<const _Pred&>(*this)(__x, __y);
  632. }
  633. template <typename _K2>
  634. _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _Key& __y) const {
  635. return static_cast<const _Pred&>(*this)(__x, __y);
  636. }
  637. #endif
  638. _LIBCPP_HIDE_FROM_ABI void swap(__unordered_map_equal& __y) _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) {
  639. using std::swap;
  640. swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
  641. }
  642. };
  643. template <class _Key, class _Cp, class _Pred, class _Hash>
  644. class __unordered_map_equal<_Key, _Cp, _Pred, _Hash, false> {
  645. _Pred __pred_;
  646. public:
  647. _LIBCPP_HIDE_FROM_ABI __unordered_map_equal() _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
  648. : __pred_() {}
  649. _LIBCPP_HIDE_FROM_ABI __unordered_map_equal(const _Pred& __p) _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
  650. : __pred_(__p) {}
  651. _LIBCPP_HIDE_FROM_ABI const _Pred& key_eq() const _NOEXCEPT { return __pred_; }
  652. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Cp& __y) const {
  653. return __pred_(__x.__get_value().first, __y.__get_value().first);
  654. }
  655. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _Key& __y) const {
  656. return __pred_(__x.__get_value().first, __y);
  657. }
  658. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _Cp& __y) const {
  659. return __pred_(__x, __y.__get_value().first);
  660. }
  661. #if _LIBCPP_STD_VER >= 20
  662. template <typename _K2>
  663. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Cp& __x, const _K2& __y) const {
  664. return __pred_(__x.__get_value().first, __y);
  665. }
  666. template <typename _K2>
  667. _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _Cp& __y) const {
  668. return __pred_(__x, __y.__get_value().first);
  669. }
  670. template <typename _K2>
  671. _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _K2& __y) const {
  672. return __pred_(__x, __y);
  673. }
  674. template <typename _K2>
  675. _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _Key& __y) const {
  676. return __pred_(__x, __y);
  677. }
  678. #endif
  679. _LIBCPP_HIDE_FROM_ABI void swap(__unordered_map_equal& __y) _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) {
  680. using std::swap;
  681. swap(__pred_, __y.__pred_);
  682. }
  683. };
  684. template <class _Key, class _Cp, class _Pred, class _Hash, bool __b>
  685. inline _LIBCPP_HIDE_FROM_ABI void
  686. swap(__unordered_map_equal<_Key, _Cp, _Pred, _Hash, __b>& __x, __unordered_map_equal<_Key, _Cp, _Pred, _Hash, __b>& __y)
  687. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
  688. __x.swap(__y);
  689. }
  690. template <class _Alloc>
  691. class __hash_map_node_destructor {
  692. typedef _Alloc allocator_type;
  693. typedef allocator_traits<allocator_type> __alloc_traits;
  694. public:
  695. typedef typename __alloc_traits::pointer pointer;
  696. private:
  697. allocator_type& __na_;
  698. __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
  699. public:
  700. bool __first_constructed;
  701. bool __second_constructed;
  702. _LIBCPP_HIDE_FROM_ABI explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
  703. : __na_(__na),
  704. __first_constructed(false),
  705. __second_constructed(false) {}
  706. #ifndef _LIBCPP_CXX03_LANG
  707. _LIBCPP_HIDE_FROM_ABI __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) _NOEXCEPT
  708. : __na_(__x.__na_),
  709. __first_constructed(__x.__value_constructed),
  710. __second_constructed(__x.__value_constructed) {
  711. __x.__value_constructed = false;
  712. }
  713. #else // _LIBCPP_CXX03_LANG
  714. _LIBCPP_HIDE_FROM_ABI __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
  715. : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) {
  716. const_cast<bool&>(__x.__value_constructed) = false;
  717. }
  718. #endif // _LIBCPP_CXX03_LANG
  719. _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT {
  720. if (__second_constructed)
  721. __alloc_traits::destroy(__na_, std::addressof(__p->__get_value().__get_value().second));
  722. if (__first_constructed)
  723. __alloc_traits::destroy(__na_, std::addressof(__p->__get_value().__get_value().first));
  724. if (__p)
  725. __alloc_traits::deallocate(__na_, __p, 1);
  726. }
  727. };
  728. #ifndef _LIBCPP_CXX03_LANG
  729. template <class _Key, class _Tp>
  730. struct _LIBCPP_STANDALONE_DEBUG __hash_value_type {
  731. typedef _Key key_type;
  732. typedef _Tp mapped_type;
  733. typedef pair<const key_type, mapped_type> value_type;
  734. typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
  735. typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
  736. private:
  737. value_type __cc_;
  738. public:
  739. _LIBCPP_HIDE_FROM_ABI value_type& __get_value() {
  740. # if _LIBCPP_STD_VER >= 17
  741. return *std::launder(std::addressof(__cc_));
  742. # else
  743. return __cc_;
  744. # endif
  745. }
  746. _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const {
  747. # if _LIBCPP_STD_VER >= 17
  748. return *std::launder(std::addressof(__cc_));
  749. # else
  750. return __cc_;
  751. # endif
  752. }
  753. _LIBCPP_HIDE_FROM_ABI __nc_ref_pair_type __ref() {
  754. value_type& __v = __get_value();
  755. return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
  756. }
  757. _LIBCPP_HIDE_FROM_ABI __nc_rref_pair_type __move() {
  758. value_type& __v = __get_value();
  759. return __nc_rref_pair_type(std::move(const_cast<key_type&>(__v.first)), std::move(__v.second));
  760. }
  761. _LIBCPP_HIDE_FROM_ABI __hash_value_type& operator=(const __hash_value_type& __v) {
  762. __ref() = __v.__get_value();
  763. return *this;
  764. }
  765. _LIBCPP_HIDE_FROM_ABI __hash_value_type& operator=(__hash_value_type&& __v) {
  766. __ref() = __v.__move();
  767. return *this;
  768. }
  769. template <class _ValueTp, __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value, int> = 0>
  770. _LIBCPP_HIDE_FROM_ABI __hash_value_type& operator=(_ValueTp&& __v) {
  771. __ref() = std::forward<_ValueTp>(__v);
  772. return *this;
  773. }
  774. private:
  775. __hash_value_type(const __hash_value_type& __v) = delete;
  776. __hash_value_type(__hash_value_type&& __v) = delete;
  777. template <class... _Args>
  778. explicit __hash_value_type(_Args&&... __args) = delete;
  779. ~__hash_value_type() = delete;
  780. };
  781. #else
  782. template <class _Key, class _Tp>
  783. struct __hash_value_type {
  784. typedef _Key key_type;
  785. typedef _Tp mapped_type;
  786. typedef pair<const key_type, mapped_type> value_type;
  787. private:
  788. value_type __cc_;
  789. public:
  790. _LIBCPP_HIDE_FROM_ABI value_type& __get_value() { return __cc_; }
  791. _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const { return __cc_; }
  792. private:
  793. ~__hash_value_type();
  794. };
  795. #endif
  796. template <class _HashIterator>
  797. class _LIBCPP_TEMPLATE_VIS __hash_map_iterator {
  798. _HashIterator __i_;
  799. typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
  800. public:
  801. typedef forward_iterator_tag iterator_category;
  802. typedef typename _NodeTypes::__map_value_type value_type;
  803. typedef typename _NodeTypes::difference_type difference_type;
  804. typedef value_type& reference;
  805. typedef typename _NodeTypes::__map_value_type_pointer pointer;
  806. _LIBCPP_HIDE_FROM_ABI __hash_map_iterator() _NOEXCEPT {}
  807. _LIBCPP_HIDE_FROM_ABI __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
  808. _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
  809. _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
  810. _LIBCPP_HIDE_FROM_ABI __hash_map_iterator& operator++() {
  811. ++__i_;
  812. return *this;
  813. }
  814. _LIBCPP_HIDE_FROM_ABI __hash_map_iterator operator++(int) {
  815. __hash_map_iterator __t(*this);
  816. ++(*this);
  817. return __t;
  818. }
  819. friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) {
  820. return __x.__i_ == __y.__i_;
  821. }
  822. #if _LIBCPP_STD_VER <= 17
  823. friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) {
  824. return __x.__i_ != __y.__i_;
  825. }
  826. #endif
  827. template <class, class, class, class, class>
  828. friend class _LIBCPP_TEMPLATE_VIS unordered_map;
  829. template <class, class, class, class, class>
  830. friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
  831. template <class>
  832. friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
  833. template <class>
  834. friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
  835. template <class>
  836. friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
  837. };
  838. template <class _HashIterator>
  839. class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator {
  840. _HashIterator __i_;
  841. typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
  842. public:
  843. typedef forward_iterator_tag iterator_category;
  844. typedef typename _NodeTypes::__map_value_type value_type;
  845. typedef typename _NodeTypes::difference_type difference_type;
  846. typedef const value_type& reference;
  847. typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
  848. _LIBCPP_HIDE_FROM_ABI __hash_map_const_iterator() _NOEXCEPT {}
  849. _LIBCPP_HIDE_FROM_ABI __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
  850. _LIBCPP_HIDE_FROM_ABI
  851. __hash_map_const_iterator(__hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) _NOEXCEPT
  852. : __i_(__i.__i_) {}
  853. _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
  854. _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
  855. _LIBCPP_HIDE_FROM_ABI __hash_map_const_iterator& operator++() {
  856. ++__i_;
  857. return *this;
  858. }
  859. _LIBCPP_HIDE_FROM_ABI __hash_map_const_iterator operator++(int) {
  860. __hash_map_const_iterator __t(*this);
  861. ++(*this);
  862. return __t;
  863. }
  864. friend _LIBCPP_HIDE_FROM_ABI bool
  865. operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) {
  866. return __x.__i_ == __y.__i_;
  867. }
  868. #if _LIBCPP_STD_VER <= 17
  869. friend _LIBCPP_HIDE_FROM_ABI bool
  870. operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) {
  871. return __x.__i_ != __y.__i_;
  872. }
  873. #endif
  874. template <class, class, class, class, class>
  875. friend class _LIBCPP_TEMPLATE_VIS unordered_map;
  876. template <class, class, class, class, class>
  877. friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
  878. template <class>
  879. friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
  880. template <class>
  881. friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
  882. };
  883. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  884. class unordered_multimap;
  885. template <class _Key,
  886. class _Tp,
  887. class _Hash = hash<_Key>,
  888. class _Pred = equal_to<_Key>,
  889. class _Alloc = allocator<pair<const _Key, _Tp> > >
  890. class _LIBCPP_TEMPLATE_VIS unordered_map {
  891. public:
  892. // types
  893. typedef _Key key_type;
  894. typedef _Tp mapped_type;
  895. typedef __type_identity_t<_Hash> hasher;
  896. typedef __type_identity_t<_Pred> key_equal;
  897. typedef __type_identity_t<_Alloc> allocator_type;
  898. typedef pair<const key_type, mapped_type> value_type;
  899. typedef value_type& reference;
  900. typedef const value_type& const_reference;
  901. static_assert((is_same<value_type, typename allocator_type::value_type>::value),
  902. "Allocator::value_type must be same type as value_type");
  903. private:
  904. typedef __hash_value_type<key_type, mapped_type> __value_type;
  905. typedef __unordered_map_hasher<key_type, __value_type, hasher, key_equal> __hasher;
  906. typedef __unordered_map_equal<key_type, __value_type, key_equal, hasher> __key_equal;
  907. typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
  908. typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
  909. __table __table_;
  910. typedef typename __table::_NodeTypes _NodeTypes;
  911. typedef typename __table::__node_pointer __node_pointer;
  912. typedef typename __table::__node_const_pointer __node_const_pointer;
  913. typedef typename __table::__node_traits __node_traits;
  914. typedef typename __table::__node_allocator __node_allocator;
  915. typedef typename __table::__node __node;
  916. typedef __hash_map_node_destructor<__node_allocator> _Dp;
  917. typedef unique_ptr<__node, _Dp> __node_holder;
  918. typedef allocator_traits<allocator_type> __alloc_traits;
  919. static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
  920. "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
  921. "original allocator");
  922. static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
  923. static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
  924. public:
  925. typedef typename __alloc_traits::pointer pointer;
  926. typedef typename __alloc_traits::const_pointer const_pointer;
  927. typedef typename __table::size_type size_type;
  928. typedef typename __table::difference_type difference_type;
  929. typedef __hash_map_iterator<typename __table::iterator> iterator;
  930. typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
  931. typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
  932. typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
  933. #if _LIBCPP_STD_VER >= 17
  934. typedef __map_node_handle<__node, allocator_type> node_type;
  935. typedef __insert_return_type<iterator, node_type> insert_return_type;
  936. #endif
  937. template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
  938. friend class _LIBCPP_TEMPLATE_VIS unordered_map;
  939. template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
  940. friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
  941. _LIBCPP_HIDE_FROM_ABI unordered_map() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
  942. explicit _LIBCPP_HIDE_FROM_ABI
  943. unordered_map(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
  944. _LIBCPP_HIDE_FROM_ABI
  945. unordered_map(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a);
  946. template <class _InputIterator>
  947. _LIBCPP_HIDE_FROM_ABI unordered_map(_InputIterator __first, _InputIterator __last);
  948. template <class _InputIterator>
  949. _LIBCPP_HIDE_FROM_ABI
  950. unordered_map(_InputIterator __first,
  951. _InputIterator __last,
  952. size_type __n,
  953. const hasher& __hf = hasher(),
  954. const key_equal& __eql = key_equal());
  955. template <class _InputIterator>
  956. _LIBCPP_HIDE_FROM_ABI unordered_map(
  957. _InputIterator __first,
  958. _InputIterator __last,
  959. size_type __n,
  960. const hasher& __hf,
  961. const key_equal& __eql,
  962. const allocator_type& __a);
  963. #if _LIBCPP_STD_VER >= 23
  964. template <_ContainerCompatibleRange<value_type> _Range>
  965. _LIBCPP_HIDE_FROM_ABI unordered_map(
  966. from_range_t,
  967. _Range&& __range,
  968. size_type __n = /*implementation-defined*/ 0,
  969. const hasher& __hf = hasher(),
  970. const key_equal& __eql = key_equal(),
  971. const allocator_type& __a = allocator_type())
  972. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  973. if (__n > 0) {
  974. __table_.__rehash_unique(__n);
  975. }
  976. insert_range(std::forward<_Range>(__range));
  977. }
  978. #endif
  979. _LIBCPP_HIDE_FROM_ABI explicit unordered_map(const allocator_type& __a);
  980. _LIBCPP_HIDE_FROM_ABI unordered_map(const unordered_map& __u);
  981. _LIBCPP_HIDE_FROM_ABI unordered_map(const unordered_map& __u, const allocator_type& __a);
  982. #ifndef _LIBCPP_CXX03_LANG
  983. _LIBCPP_HIDE_FROM_ABI unordered_map(unordered_map&& __u) _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
  984. _LIBCPP_HIDE_FROM_ABI unordered_map(unordered_map&& __u, const allocator_type& __a);
  985. _LIBCPP_HIDE_FROM_ABI unordered_map(initializer_list<value_type> __il);
  986. _LIBCPP_HIDE_FROM_ABI
  987. unordered_map(initializer_list<value_type> __il,
  988. size_type __n,
  989. const hasher& __hf = hasher(),
  990. const key_equal& __eql = key_equal());
  991. _LIBCPP_HIDE_FROM_ABI unordered_map(
  992. initializer_list<value_type> __il,
  993. size_type __n,
  994. const hasher& __hf,
  995. const key_equal& __eql,
  996. const allocator_type& __a);
  997. #endif // _LIBCPP_CXX03_LANG
  998. #if _LIBCPP_STD_VER >= 14
  999. _LIBCPP_HIDE_FROM_ABI unordered_map(size_type __n, const allocator_type& __a)
  1000. : unordered_map(__n, hasher(), key_equal(), __a) {}
  1001. _LIBCPP_HIDE_FROM_ABI unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
  1002. : unordered_map(__n, __hf, key_equal(), __a) {}
  1003. template <class _InputIterator>
  1004. _LIBCPP_HIDE_FROM_ABI
  1005. unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
  1006. : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
  1007. template <class _InputIterator>
  1008. _LIBCPP_HIDE_FROM_ABI unordered_map(
  1009. _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const allocator_type& __a)
  1010. : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
  1011. # if _LIBCPP_STD_VER >= 23
  1012. template <_ContainerCompatibleRange<value_type> _Range>
  1013. _LIBCPP_HIDE_FROM_ABI unordered_map(from_range_t, _Range&& __range, size_type __n, const allocator_type& __a)
  1014. : unordered_map(from_range, std::forward<_Range>(__range), __n, hasher(), key_equal(), __a) {}
  1015. template <_ContainerCompatibleRange<value_type> _Range>
  1016. _LIBCPP_HIDE_FROM_ABI
  1017. unordered_map(from_range_t, _Range&& __range, size_type __n, const hasher& __hf, const allocator_type& __a)
  1018. : unordered_map(from_range, std::forward<_Range>(__range), __n, __hf, key_equal(), __a) {}
  1019. # endif
  1020. _LIBCPP_HIDE_FROM_ABI unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
  1021. : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
  1022. _LIBCPP_HIDE_FROM_ABI
  1023. unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
  1024. : unordered_map(__il, __n, __hf, key_equal(), __a) {}
  1025. #endif
  1026. _LIBCPP_HIDE_FROM_ABI ~unordered_map() {
  1027. static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
  1028. }
  1029. _LIBCPP_HIDE_FROM_ABI unordered_map& operator=(const unordered_map& __u) {
  1030. #ifndef _LIBCPP_CXX03_LANG
  1031. __table_ = __u.__table_;
  1032. #else
  1033. if (this != std::addressof(__u)) {
  1034. __table_.clear();
  1035. __table_.hash_function() = __u.__table_.hash_function();
  1036. __table_.key_eq() = __u.__table_.key_eq();
  1037. __table_.max_load_factor() = __u.__table_.max_load_factor();
  1038. __table_.__copy_assign_alloc(__u.__table_);
  1039. insert(__u.begin(), __u.end());
  1040. }
  1041. #endif
  1042. return *this;
  1043. }
  1044. #ifndef _LIBCPP_CXX03_LANG
  1045. _LIBCPP_HIDE_FROM_ABI unordered_map& operator=(unordered_map&& __u)
  1046. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
  1047. _LIBCPP_HIDE_FROM_ABI unordered_map& operator=(initializer_list<value_type> __il);
  1048. #endif // _LIBCPP_CXX03_LANG
  1049. _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
  1050. return allocator_type(__table_.__node_alloc());
  1051. }
  1052. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
  1053. _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __table_.size(); }
  1054. _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __table_.max_size(); }
  1055. _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __table_.begin(); }
  1056. _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __table_.end(); }
  1057. _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __table_.begin(); }
  1058. _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __table_.end(); }
  1059. _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __table_.begin(); }
  1060. _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __table_.end(); }
  1061. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) { return __table_.__insert_unique(__x); }
  1062. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x).first; }
  1063. template <class _InputIterator>
  1064. _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
  1065. #if _LIBCPP_STD_VER >= 23
  1066. template <_ContainerCompatibleRange<value_type> _Range>
  1067. _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
  1068. for (auto&& __element : __range) {
  1069. __table_.__insert_unique(std::forward<decltype(__element)>(__element));
  1070. }
  1071. }
  1072. #endif
  1073. #ifndef _LIBCPP_CXX03_LANG
  1074. _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
  1075. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __x) {
  1076. return __table_.__insert_unique(std::move(__x));
  1077. }
  1078. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, value_type&& __x) {
  1079. return __table_.__insert_unique(std::move(__x)).first;
  1080. }
  1081. template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
  1082. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_Pp&& __x) {
  1083. return __table_.__insert_unique(std::forward<_Pp>(__x));
  1084. }
  1085. template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
  1086. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, _Pp&& __x) {
  1087. return insert(std::forward<_Pp>(__x)).first;
  1088. }
  1089. template <class... _Args>
  1090. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
  1091. return __table_.__emplace_unique(std::forward<_Args>(__args)...);
  1092. }
  1093. template <class... _Args>
  1094. _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator, _Args&&... __args) {
  1095. return __table_.__emplace_unique(std::forward<_Args>(__args)...).first;
  1096. }
  1097. #endif // _LIBCPP_CXX03_LANG
  1098. #if _LIBCPP_STD_VER >= 17
  1099. template <class... _Args>
  1100. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) {
  1101. return __table_.__emplace_unique_key_args(
  1102. __k, piecewise_construct, std::forward_as_tuple(__k), std::forward_as_tuple(std::forward<_Args>(__args)...));
  1103. }
  1104. template <class... _Args>
  1105. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) {
  1106. return __table_.__emplace_unique_key_args(
  1107. __k,
  1108. piecewise_construct,
  1109. std::forward_as_tuple(std::move(__k)),
  1110. std::forward_as_tuple(std::forward<_Args>(__args)...));
  1111. }
  1112. template <class... _Args>
  1113. _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator, const key_type& __k, _Args&&... __args) {
  1114. return try_emplace(__k, std::forward<_Args>(__args)...).first;
  1115. }
  1116. template <class... _Args>
  1117. _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator, key_type&& __k, _Args&&... __args) {
  1118. return try_emplace(std::move(__k), std::forward<_Args>(__args)...).first;
  1119. }
  1120. template <class _Vp>
  1121. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) {
  1122. pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k, __k, std::forward<_Vp>(__v));
  1123. if (!__res.second) {
  1124. __res.first->second = std::forward<_Vp>(__v);
  1125. }
  1126. return __res;
  1127. }
  1128. template <class _Vp>
  1129. _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) {
  1130. pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k, std::move(__k), std::forward<_Vp>(__v));
  1131. if (!__res.second) {
  1132. __res.first->second = std::forward<_Vp>(__v);
  1133. }
  1134. return __res;
  1135. }
  1136. template <class _Vp>
  1137. _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v) {
  1138. return insert_or_assign(__k, std::forward<_Vp>(__v)).first;
  1139. }
  1140. template <class _Vp>
  1141. _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v) {
  1142. return insert_or_assign(std::move(__k), std::forward<_Vp>(__v)).first;
  1143. }
  1144. #endif // _LIBCPP_STD_VER >= 17
  1145. _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __table_.erase(__p.__i_); }
  1146. _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __table_.erase(__p.__i_); }
  1147. _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __table_.__erase_unique(__k); }
  1148. _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) {
  1149. return __table_.erase(__first.__i_, __last.__i_);
  1150. }
  1151. _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __table_.clear(); }
  1152. #if _LIBCPP_STD_VER >= 17
  1153. _LIBCPP_HIDE_FROM_ABI insert_return_type insert(node_type&& __nh) {
  1154. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1155. "node_type with incompatible allocator passed to unordered_map::insert()");
  1156. return __table_.template __node_handle_insert_unique< node_type, insert_return_type>(std::move(__nh));
  1157. }
  1158. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
  1159. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1160. "node_type with incompatible allocator passed to unordered_map::insert()");
  1161. return __table_.template __node_handle_insert_unique<node_type>(__hint.__i_, std::move(__nh));
  1162. }
  1163. _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
  1164. return __table_.template __node_handle_extract<node_type>(__key);
  1165. }
  1166. _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
  1167. return __table_.template __node_handle_extract<node_type>(__it.__i_);
  1168. }
  1169. template <class _H2, class _P2>
  1170. _LIBCPP_HIDE_FROM_ABI void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source) {
  1171. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1172. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1173. return __table_.__node_handle_merge_unique(__source.__table_);
  1174. }
  1175. template <class _H2, class _P2>
  1176. _LIBCPP_HIDE_FROM_ABI void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) {
  1177. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1178. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1179. return __table_.__node_handle_merge_unique(__source.__table_);
  1180. }
  1181. template <class _H2, class _P2>
  1182. _LIBCPP_HIDE_FROM_ABI void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source) {
  1183. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1184. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1185. return __table_.__node_handle_merge_unique(__source.__table_);
  1186. }
  1187. template <class _H2, class _P2>
  1188. _LIBCPP_HIDE_FROM_ABI void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) {
  1189. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1190. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1191. return __table_.__node_handle_merge_unique(__source.__table_);
  1192. }
  1193. #endif
  1194. _LIBCPP_HIDE_FROM_ABI void swap(unordered_map& __u) _NOEXCEPT_(__is_nothrow_swappable<__table>::value) {
  1195. __table_.swap(__u.__table_);
  1196. }
  1197. _LIBCPP_HIDE_FROM_ABI hasher hash_function() const { return __table_.hash_function().hash_function(); }
  1198. _LIBCPP_HIDE_FROM_ABI key_equal key_eq() const { return __table_.key_eq().key_eq(); }
  1199. _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __table_.find(__k); }
  1200. _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __table_.find(__k); }
  1201. #if _LIBCPP_STD_VER >= 20
  1202. template <class _K2,
  1203. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1204. _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
  1205. return __table_.find(__k);
  1206. }
  1207. template <class _K2,
  1208. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1209. _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
  1210. return __table_.find(__k);
  1211. }
  1212. #endif // _LIBCPP_STD_VER >= 20
  1213. _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __table_.__count_unique(__k); }
  1214. #if _LIBCPP_STD_VER >= 20
  1215. template <class _K2,
  1216. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1217. _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
  1218. return __table_.__count_unique(__k);
  1219. }
  1220. #endif // _LIBCPP_STD_VER >= 20
  1221. #if _LIBCPP_STD_VER >= 20
  1222. _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
  1223. template <class _K2,
  1224. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1225. _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
  1226. return find(__k) != end();
  1227. }
  1228. #endif // _LIBCPP_STD_VER >= 20
  1229. _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
  1230. return __table_.__equal_range_unique(__k);
  1231. }
  1232. _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
  1233. return __table_.__equal_range_unique(__k);
  1234. }
  1235. #if _LIBCPP_STD_VER >= 20
  1236. template <class _K2,
  1237. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1238. _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
  1239. return __table_.__equal_range_unique(__k);
  1240. }
  1241. template <class _K2,
  1242. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1243. _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
  1244. return __table_.__equal_range_unique(__k);
  1245. }
  1246. #endif // _LIBCPP_STD_VER >= 20
  1247. _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k);
  1248. #ifndef _LIBCPP_CXX03_LANG
  1249. _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k);
  1250. #endif
  1251. _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __k);
  1252. _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __k) const;
  1253. _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const _NOEXCEPT { return __table_.bucket_count(); }
  1254. _LIBCPP_HIDE_FROM_ABI size_type max_bucket_count() const _NOEXCEPT { return __table_.max_bucket_count(); }
  1255. _LIBCPP_HIDE_FROM_ABI size_type bucket_size(size_type __n) const { return __table_.bucket_size(__n); }
  1256. _LIBCPP_HIDE_FROM_ABI size_type bucket(const key_type& __k) const { return __table_.bucket(__k); }
  1257. _LIBCPP_HIDE_FROM_ABI local_iterator begin(size_type __n) { return __table_.begin(__n); }
  1258. _LIBCPP_HIDE_FROM_ABI local_iterator end(size_type __n) { return __table_.end(__n); }
  1259. _LIBCPP_HIDE_FROM_ABI const_local_iterator begin(size_type __n) const { return __table_.cbegin(__n); }
  1260. _LIBCPP_HIDE_FROM_ABI const_local_iterator end(size_type __n) const { return __table_.cend(__n); }
  1261. _LIBCPP_HIDE_FROM_ABI const_local_iterator cbegin(size_type __n) const { return __table_.cbegin(__n); }
  1262. _LIBCPP_HIDE_FROM_ABI const_local_iterator cend(size_type __n) const { return __table_.cend(__n); }
  1263. _LIBCPP_HIDE_FROM_ABI float load_factor() const _NOEXCEPT { return __table_.load_factor(); }
  1264. _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __table_.max_load_factor(); }
  1265. _LIBCPP_HIDE_FROM_ABI void max_load_factor(float __mlf) { __table_.max_load_factor(__mlf); }
  1266. _LIBCPP_HIDE_FROM_ABI void rehash(size_type __n) { __table_.__rehash_unique(__n); }
  1267. _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n) { __table_.__reserve_unique(__n); }
  1268. private:
  1269. #ifdef _LIBCPP_CXX03_LANG
  1270. _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node_with_key(const key_type& __k);
  1271. #endif
  1272. };
  1273. #if _LIBCPP_STD_VER >= 17
  1274. template <class _InputIterator,
  1275. class _Hash = hash<__iter_key_type<_InputIterator>>,
  1276. class _Pred = equal_to<__iter_key_type<_InputIterator>>,
  1277. class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
  1278. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1279. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1280. class = enable_if_t<!is_integral<_Hash>::value>,
  1281. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1282. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1283. unordered_map(_InputIterator,
  1284. _InputIterator,
  1285. typename allocator_traits<_Allocator>::size_type = 0,
  1286. _Hash = _Hash(),
  1287. _Pred = _Pred(),
  1288. _Allocator = _Allocator())
  1289. -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
  1290. # if _LIBCPP_STD_VER >= 23
  1291. template <ranges::input_range _Range,
  1292. class _Hash = hash<__range_key_type<_Range>>,
  1293. class _Pred = equal_to<__range_key_type<_Range>>,
  1294. class _Allocator = allocator<__range_to_alloc_type<_Range>>,
  1295. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1296. class = enable_if_t<!is_integral<_Hash>::value>,
  1297. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1298. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1299. unordered_map(from_range_t,
  1300. _Range&&,
  1301. typename allocator_traits<_Allocator>::size_type = 0,
  1302. _Hash = _Hash(),
  1303. _Pred = _Pred(),
  1304. _Allocator = _Allocator())
  1305. -> unordered_map<__range_key_type<_Range>, __range_mapped_type<_Range>, _Hash, _Pred, _Allocator>; // C++23
  1306. # endif
  1307. template <class _Key,
  1308. class _Tp,
  1309. class _Hash = hash<remove_const_t<_Key>>,
  1310. class _Pred = equal_to<remove_const_t<_Key>>,
  1311. class _Allocator = allocator<pair<const _Key, _Tp>>,
  1312. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1313. class = enable_if_t<!is_integral<_Hash>::value>,
  1314. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1315. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1316. unordered_map(initializer_list<pair<_Key, _Tp>>,
  1317. typename allocator_traits<_Allocator>::size_type = 0,
  1318. _Hash = _Hash(),
  1319. _Pred = _Pred(),
  1320. _Allocator = _Allocator()) -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
  1321. template <class _InputIterator,
  1322. class _Allocator,
  1323. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1324. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1325. unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1326. -> unordered_map<__iter_key_type<_InputIterator>,
  1327. __iter_mapped_type<_InputIterator>,
  1328. hash<__iter_key_type<_InputIterator>>,
  1329. equal_to<__iter_key_type<_InputIterator>>,
  1330. _Allocator>;
  1331. template <class _InputIterator,
  1332. class _Allocator,
  1333. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1334. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1335. unordered_map(_InputIterator, _InputIterator, _Allocator)
  1336. -> unordered_map<__iter_key_type<_InputIterator>,
  1337. __iter_mapped_type<_InputIterator>,
  1338. hash<__iter_key_type<_InputIterator>>,
  1339. equal_to<__iter_key_type<_InputIterator>>,
  1340. _Allocator>;
  1341. template <class _InputIterator,
  1342. class _Hash,
  1343. class _Allocator,
  1344. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1345. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1346. class = enable_if_t<!is_integral<_Hash>::value>,
  1347. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1348. unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  1349. -> unordered_map<__iter_key_type<_InputIterator>,
  1350. __iter_mapped_type<_InputIterator>,
  1351. _Hash,
  1352. equal_to<__iter_key_type<_InputIterator>>,
  1353. _Allocator>;
  1354. # if _LIBCPP_STD_VER >= 23
  1355. template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
  1356. unordered_map(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1357. -> unordered_map<__range_key_type<_Range>,
  1358. __range_mapped_type<_Range>,
  1359. hash<__range_key_type<_Range>>,
  1360. equal_to<__range_key_type<_Range>>,
  1361. _Allocator>;
  1362. template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
  1363. unordered_map(from_range_t, _Range&&, _Allocator)
  1364. -> unordered_map<__range_key_type<_Range>,
  1365. __range_mapped_type<_Range>,
  1366. hash<__range_key_type<_Range>>,
  1367. equal_to<__range_key_type<_Range>>,
  1368. _Allocator>;
  1369. template <ranges::input_range _Range,
  1370. class _Hash,
  1371. class _Allocator,
  1372. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1373. class = enable_if_t<!is_integral<_Hash>::value>,
  1374. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1375. unordered_map(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  1376. -> unordered_map<__range_key_type<_Range>,
  1377. __range_mapped_type<_Range>,
  1378. _Hash,
  1379. equal_to<__range_key_type<_Range>>,
  1380. _Allocator>;
  1381. # endif
  1382. template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
  1383. unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1384. -> unordered_map<remove_const_t<_Key>, _Tp, hash<remove_const_t<_Key>>, equal_to<remove_const_t<_Key>>, _Allocator>;
  1385. template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
  1386. unordered_map(initializer_list<pair<_Key, _Tp>>, _Allocator)
  1387. -> unordered_map<remove_const_t<_Key>, _Tp, hash<remove_const_t<_Key>>, equal_to<remove_const_t<_Key>>, _Allocator>;
  1388. template <class _Key,
  1389. class _Tp,
  1390. class _Hash,
  1391. class _Allocator,
  1392. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1393. class = enable_if_t<!is_integral<_Hash>::value>,
  1394. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1395. unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  1396. -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, equal_to<remove_const_t<_Key>>, _Allocator>;
  1397. #endif
  1398. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1399. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(size_type __n, const hasher& __hf, const key_equal& __eql)
  1400. : __table_(__hf, __eql) {
  1401. __table_.__rehash_unique(__n);
  1402. }
  1403. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1404. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1405. size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  1406. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  1407. __table_.__rehash_unique(__n);
  1408. }
  1409. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1410. inline unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(const allocator_type& __a)
  1411. : __table_(typename __table::allocator_type(__a)) {}
  1412. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1413. template <class _InputIterator>
  1414. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(_InputIterator __first, _InputIterator __last) {
  1415. insert(__first, __last);
  1416. }
  1417. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1418. template <class _InputIterator>
  1419. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1420. _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql)
  1421. : __table_(__hf, __eql) {
  1422. __table_.__rehash_unique(__n);
  1423. insert(__first, __last);
  1424. }
  1425. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1426. template <class _InputIterator>
  1427. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1428. _InputIterator __first,
  1429. _InputIterator __last,
  1430. size_type __n,
  1431. const hasher& __hf,
  1432. const key_equal& __eql,
  1433. const allocator_type& __a)
  1434. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  1435. __table_.__rehash_unique(__n);
  1436. insert(__first, __last);
  1437. }
  1438. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1439. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(const unordered_map& __u) : __table_(__u.__table_) {
  1440. __table_.__rehash_unique(__u.bucket_count());
  1441. insert(__u.begin(), __u.end());
  1442. }
  1443. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1444. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(const unordered_map& __u, const allocator_type& __a)
  1445. : __table_(__u.__table_, typename __table::allocator_type(__a)) {
  1446. __table_.__rehash_unique(__u.bucket_count());
  1447. insert(__u.begin(), __u.end());
  1448. }
  1449. #ifndef _LIBCPP_CXX03_LANG
  1450. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1451. inline unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(unordered_map&& __u)
  1452. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
  1453. : __table_(std::move(__u.__table_)) {}
  1454. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1455. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(unordered_map&& __u, const allocator_type& __a)
  1456. : __table_(std::move(__u.__table_), typename __table::allocator_type(__a)) {
  1457. if (__a != __u.get_allocator()) {
  1458. iterator __i = __u.begin();
  1459. while (__u.size() != 0) {
  1460. __table_.__emplace_unique(__u.__table_.remove((__i++).__i_)->__get_value().__move());
  1461. }
  1462. }
  1463. }
  1464. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1465. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(initializer_list<value_type> __il) {
  1466. insert(__il.begin(), __il.end());
  1467. }
  1468. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1469. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1470. initializer_list<value_type> __il, size_type __n, const hasher& __hf, const key_equal& __eql)
  1471. : __table_(__hf, __eql) {
  1472. __table_.__rehash_unique(__n);
  1473. insert(__il.begin(), __il.end());
  1474. }
  1475. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1476. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1477. initializer_list<value_type> __il,
  1478. size_type __n,
  1479. const hasher& __hf,
  1480. const key_equal& __eql,
  1481. const allocator_type& __a)
  1482. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  1483. __table_.__rehash_unique(__n);
  1484. insert(__il.begin(), __il.end());
  1485. }
  1486. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1487. inline unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
  1488. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
  1489. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) {
  1490. __table_ = std::move(__u.__table_);
  1491. return *this;
  1492. }
  1493. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1494. inline unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
  1495. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(initializer_list<value_type> __il) {
  1496. __table_.__assign_unique(__il.begin(), __il.end());
  1497. return *this;
  1498. }
  1499. #endif // _LIBCPP_CXX03_LANG
  1500. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1501. template <class _InputIterator>
  1502. inline void unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
  1503. for (; __first != __last; ++__first)
  1504. __table_.__insert_unique(*__first);
  1505. }
  1506. #ifndef _LIBCPP_CXX03_LANG
  1507. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1508. _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) {
  1509. return __table_
  1510. .__emplace_unique_key_args(__k, piecewise_construct, std::forward_as_tuple(__k), std::forward_as_tuple())
  1511. .first->__get_value()
  1512. .second;
  1513. }
  1514. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1515. _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k) {
  1516. return __table_
  1517. .__emplace_unique_key_args(
  1518. __k, piecewise_construct, std::forward_as_tuple(std::move(__k)), std::forward_as_tuple())
  1519. .first->__get_value()
  1520. .second;
  1521. }
  1522. #else // _LIBCPP_CXX03_LANG
  1523. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1524. typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
  1525. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k) {
  1526. __node_allocator& __na = __table_.__node_alloc();
  1527. __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
  1528. __node_traits::construct(__na, std::addressof(__h->__get_value().__get_value().first), __k);
  1529. __h.get_deleter().__first_constructed = true;
  1530. __node_traits::construct(__na, std::addressof(__h->__get_value().__get_value().second));
  1531. __h.get_deleter().__second_constructed = true;
  1532. return __h;
  1533. }
  1534. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1535. _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) {
  1536. iterator __i = find(__k);
  1537. if (__i != end())
  1538. return __i->second;
  1539. __node_holder __h = __construct_node_with_key(__k);
  1540. pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
  1541. __h.release();
  1542. return __r.first->second;
  1543. }
  1544. #endif // _LIBCPP_CXX03_LANG
  1545. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1546. _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) {
  1547. iterator __i = find(__k);
  1548. if (__i == end())
  1549. __throw_out_of_range("unordered_map::at: key not found");
  1550. return __i->second;
  1551. }
  1552. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1553. const _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const {
  1554. const_iterator __i = find(__k);
  1555. if (__i == end())
  1556. __throw_out_of_range("unordered_map::at: key not found");
  1557. return __i->second;
  1558. }
  1559. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1560. inline _LIBCPP_HIDE_FROM_ABI void
  1561. swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
  1562. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
  1563. __x.swap(__y);
  1564. }
  1565. #if _LIBCPP_STD_VER >= 20
  1566. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate>
  1567. inline _LIBCPP_HIDE_FROM_ABI typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
  1568. erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) {
  1569. return std::__libcpp_erase_if_container(__c, __pred);
  1570. }
  1571. #endif
  1572. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1573. _LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  1574. const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) {
  1575. if (__x.size() != __y.size())
  1576. return false;
  1577. typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator const_iterator;
  1578. for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); __i != __ex; ++__i) {
  1579. const_iterator __j = __y.find(__i->first);
  1580. if (__j == __ey || !(*__i == *__j))
  1581. return false;
  1582. }
  1583. return true;
  1584. }
  1585. #if _LIBCPP_STD_VER <= 17
  1586. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1587. inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  1588. const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) {
  1589. return !(__x == __y);
  1590. }
  1591. #endif
  1592. template <class _Key,
  1593. class _Tp,
  1594. class _Hash = hash<_Key>,
  1595. class _Pred = equal_to<_Key>,
  1596. class _Alloc = allocator<pair<const _Key, _Tp> > >
  1597. class _LIBCPP_TEMPLATE_VIS unordered_multimap {
  1598. public:
  1599. // types
  1600. typedef _Key key_type;
  1601. typedef _Tp mapped_type;
  1602. typedef __type_identity_t<_Hash> hasher;
  1603. typedef __type_identity_t<_Pred> key_equal;
  1604. typedef __type_identity_t<_Alloc> allocator_type;
  1605. typedef pair<const key_type, mapped_type> value_type;
  1606. typedef value_type& reference;
  1607. typedef const value_type& const_reference;
  1608. static_assert((is_same<value_type, typename allocator_type::value_type>::value),
  1609. "Allocator::value_type must be same type as value_type");
  1610. private:
  1611. typedef __hash_value_type<key_type, mapped_type> __value_type;
  1612. typedef __unordered_map_hasher<key_type, __value_type, hasher, key_equal> __hasher;
  1613. typedef __unordered_map_equal<key_type, __value_type, key_equal, hasher> __key_equal;
  1614. typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
  1615. typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
  1616. __table __table_;
  1617. typedef typename __table::_NodeTypes _NodeTypes;
  1618. typedef typename __table::__node_traits __node_traits;
  1619. typedef typename __table::__node_allocator __node_allocator;
  1620. typedef typename __table::__node __node;
  1621. typedef __hash_map_node_destructor<__node_allocator> _Dp;
  1622. typedef unique_ptr<__node, _Dp> __node_holder;
  1623. typedef allocator_traits<allocator_type> __alloc_traits;
  1624. static_assert((is_same<typename __node_traits::size_type, typename __alloc_traits::size_type>::value),
  1625. "Allocator uses different size_type for different types");
  1626. static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
  1627. "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
  1628. "original allocator");
  1629. public:
  1630. typedef typename __alloc_traits::pointer pointer;
  1631. typedef typename __alloc_traits::const_pointer const_pointer;
  1632. typedef typename __table::size_type size_type;
  1633. typedef typename __table::difference_type difference_type;
  1634. typedef __hash_map_iterator<typename __table::iterator> iterator;
  1635. typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
  1636. typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
  1637. typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
  1638. #if _LIBCPP_STD_VER >= 17
  1639. typedef __map_node_handle<__node, allocator_type> node_type;
  1640. #endif
  1641. template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
  1642. friend class _LIBCPP_TEMPLATE_VIS unordered_map;
  1643. template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
  1644. friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
  1645. _LIBCPP_HIDE_FROM_ABI unordered_multimap() _NOEXCEPT_(is_nothrow_default_constructible<__table>::value) {}
  1646. explicit _LIBCPP_HIDE_FROM_ABI
  1647. unordered_multimap(size_type __n, const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
  1648. _LIBCPP_HIDE_FROM_ABI
  1649. unordered_multimap(size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a);
  1650. template <class _InputIterator>
  1651. _LIBCPP_HIDE_FROM_ABI unordered_multimap(_InputIterator __first, _InputIterator __last);
  1652. template <class _InputIterator>
  1653. _LIBCPP_HIDE_FROM_ABI unordered_multimap(
  1654. _InputIterator __first,
  1655. _InputIterator __last,
  1656. size_type __n,
  1657. const hasher& __hf = hasher(),
  1658. const key_equal& __eql = key_equal());
  1659. template <class _InputIterator>
  1660. _LIBCPP_HIDE_FROM_ABI unordered_multimap(
  1661. _InputIterator __first,
  1662. _InputIterator __last,
  1663. size_type __n,
  1664. const hasher& __hf,
  1665. const key_equal& __eql,
  1666. const allocator_type& __a);
  1667. #if _LIBCPP_STD_VER >= 23
  1668. template <_ContainerCompatibleRange<value_type> _Range>
  1669. _LIBCPP_HIDE_FROM_ABI unordered_multimap(
  1670. from_range_t,
  1671. _Range&& __range,
  1672. size_type __n = /*implementation-defined*/ 0,
  1673. const hasher& __hf = hasher(),
  1674. const key_equal& __eql = key_equal(),
  1675. const allocator_type& __a = allocator_type())
  1676. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  1677. if (__n > 0) {
  1678. __table_.__rehash_multi(__n);
  1679. }
  1680. insert_range(std::forward<_Range>(__range));
  1681. }
  1682. #endif
  1683. _LIBCPP_HIDE_FROM_ABI explicit unordered_multimap(const allocator_type& __a);
  1684. _LIBCPP_HIDE_FROM_ABI unordered_multimap(const unordered_multimap& __u);
  1685. _LIBCPP_HIDE_FROM_ABI unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
  1686. #ifndef _LIBCPP_CXX03_LANG
  1687. _LIBCPP_HIDE_FROM_ABI unordered_multimap(unordered_multimap&& __u)
  1688. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
  1689. _LIBCPP_HIDE_FROM_ABI unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
  1690. _LIBCPP_HIDE_FROM_ABI unordered_multimap(initializer_list<value_type> __il);
  1691. _LIBCPP_HIDE_FROM_ABI unordered_multimap(
  1692. initializer_list<value_type> __il,
  1693. size_type __n,
  1694. const hasher& __hf = hasher(),
  1695. const key_equal& __eql = key_equal());
  1696. _LIBCPP_HIDE_FROM_ABI unordered_multimap(
  1697. initializer_list<value_type> __il,
  1698. size_type __n,
  1699. const hasher& __hf,
  1700. const key_equal& __eql,
  1701. const allocator_type& __a);
  1702. #endif // _LIBCPP_CXX03_LANG
  1703. #if _LIBCPP_STD_VER >= 14
  1704. _LIBCPP_HIDE_FROM_ABI unordered_multimap(size_type __n, const allocator_type& __a)
  1705. : unordered_multimap(__n, hasher(), key_equal(), __a) {}
  1706. _LIBCPP_HIDE_FROM_ABI unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
  1707. : unordered_multimap(__n, __hf, key_equal(), __a) {}
  1708. template <class _InputIterator>
  1709. _LIBCPP_HIDE_FROM_ABI
  1710. unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
  1711. : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
  1712. template <class _InputIterator>
  1713. _LIBCPP_HIDE_FROM_ABI unordered_multimap(
  1714. _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const allocator_type& __a)
  1715. : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
  1716. # if _LIBCPP_STD_VER >= 23
  1717. template <_ContainerCompatibleRange<value_type> _Range>
  1718. _LIBCPP_HIDE_FROM_ABI unordered_multimap(from_range_t, _Range&& __range, size_type __n, const allocator_type& __a)
  1719. : unordered_multimap(from_range, std::forward<_Range>(__range), __n, hasher(), key_equal(), __a) {}
  1720. template <_ContainerCompatibleRange<value_type> _Range>
  1721. _LIBCPP_HIDE_FROM_ABI
  1722. unordered_multimap(from_range_t, _Range&& __range, size_type __n, const hasher& __hf, const allocator_type& __a)
  1723. : unordered_multimap(from_range, std::forward<_Range>(__range), __n, __hf, key_equal(), __a) {}
  1724. # endif
  1725. _LIBCPP_HIDE_FROM_ABI unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
  1726. : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
  1727. _LIBCPP_HIDE_FROM_ABI
  1728. unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
  1729. : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
  1730. #endif
  1731. _LIBCPP_HIDE_FROM_ABI ~unordered_multimap() {
  1732. static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
  1733. }
  1734. _LIBCPP_HIDE_FROM_ABI unordered_multimap& operator=(const unordered_multimap& __u) {
  1735. #ifndef _LIBCPP_CXX03_LANG
  1736. __table_ = __u.__table_;
  1737. #else
  1738. if (this != std::addressof(__u)) {
  1739. __table_.clear();
  1740. __table_.hash_function() = __u.__table_.hash_function();
  1741. __table_.key_eq() = __u.__table_.key_eq();
  1742. __table_.max_load_factor() = __u.__table_.max_load_factor();
  1743. __table_.__copy_assign_alloc(__u.__table_);
  1744. insert(__u.begin(), __u.end());
  1745. }
  1746. #endif
  1747. return *this;
  1748. }
  1749. #ifndef _LIBCPP_CXX03_LANG
  1750. _LIBCPP_HIDE_FROM_ABI unordered_multimap& operator=(unordered_multimap&& __u)
  1751. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
  1752. _LIBCPP_HIDE_FROM_ABI unordered_multimap& operator=(initializer_list<value_type> __il);
  1753. #endif // _LIBCPP_CXX03_LANG
  1754. _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
  1755. return allocator_type(__table_.__node_alloc());
  1756. }
  1757. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __table_.size() == 0; }
  1758. _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __table_.size(); }
  1759. _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __table_.max_size(); }
  1760. _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __table_.begin(); }
  1761. _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __table_.end(); }
  1762. _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __table_.begin(); }
  1763. _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __table_.end(); }
  1764. _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __table_.begin(); }
  1765. _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __table_.end(); }
  1766. _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__insert_multi(__x); }
  1767. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __x) {
  1768. return __table_.__insert_multi(__p.__i_, __x);
  1769. }
  1770. template <class _InputIterator>
  1771. _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
  1772. #if _LIBCPP_STD_VER >= 23
  1773. template <_ContainerCompatibleRange<value_type> _Range>
  1774. _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
  1775. for (auto&& __element : __range) {
  1776. __table_.__insert_multi(std::forward<decltype(__element)>(__element));
  1777. }
  1778. }
  1779. #endif
  1780. #ifndef _LIBCPP_CXX03_LANG
  1781. _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
  1782. _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __x) { return __table_.__insert_multi(std::move(__x)); }
  1783. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __x) {
  1784. return __table_.__insert_multi(__p.__i_, std::move(__x));
  1785. }
  1786. template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
  1787. _LIBCPP_HIDE_FROM_ABI iterator insert(_Pp&& __x) {
  1788. return __table_.__insert_multi(std::forward<_Pp>(__x));
  1789. }
  1790. template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
  1791. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _Pp&& __x) {
  1792. return __table_.__insert_multi(__p.__i_, std::forward<_Pp>(__x));
  1793. }
  1794. template <class... _Args>
  1795. _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
  1796. return __table_.__emplace_multi(std::forward<_Args>(__args)...);
  1797. }
  1798. template <class... _Args>
  1799. _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
  1800. return __table_.__emplace_hint_multi(__p.__i_, std::forward<_Args>(__args)...);
  1801. }
  1802. #endif // _LIBCPP_CXX03_LANG
  1803. _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __table_.erase(__p.__i_); }
  1804. _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __table_.erase(__p.__i_); }
  1805. _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __table_.__erase_multi(__k); }
  1806. _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) {
  1807. return __table_.erase(__first.__i_, __last.__i_);
  1808. }
  1809. _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __table_.clear(); }
  1810. #if _LIBCPP_STD_VER >= 17
  1811. _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
  1812. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1813. "node_type with incompatible allocator passed to unordered_multimap::insert()");
  1814. return __table_.template __node_handle_insert_multi<node_type>(std::move(__nh));
  1815. }
  1816. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
  1817. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1818. "node_type with incompatible allocator passed to unordered_multimap::insert()");
  1819. return __table_.template __node_handle_insert_multi<node_type>(__hint.__i_, std::move(__nh));
  1820. }
  1821. _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
  1822. return __table_.template __node_handle_extract<node_type>(__key);
  1823. }
  1824. _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
  1825. return __table_.template __node_handle_extract<node_type>(__it.__i_);
  1826. }
  1827. template <class _H2, class _P2>
  1828. _LIBCPP_HIDE_FROM_ABI void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source) {
  1829. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1830. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1831. return __table_.__node_handle_merge_multi(__source.__table_);
  1832. }
  1833. template <class _H2, class _P2>
  1834. _LIBCPP_HIDE_FROM_ABI void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) {
  1835. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1836. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1837. return __table_.__node_handle_merge_multi(__source.__table_);
  1838. }
  1839. template <class _H2, class _P2>
  1840. _LIBCPP_HIDE_FROM_ABI void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source) {
  1841. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1842. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1843. return __table_.__node_handle_merge_multi(__source.__table_);
  1844. }
  1845. template <class _H2, class _P2>
  1846. _LIBCPP_HIDE_FROM_ABI void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source) {
  1847. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
  1848. __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
  1849. return __table_.__node_handle_merge_multi(__source.__table_);
  1850. }
  1851. #endif
  1852. _LIBCPP_HIDE_FROM_ABI void swap(unordered_multimap& __u) _NOEXCEPT_(__is_nothrow_swappable<__table>::value) {
  1853. __table_.swap(__u.__table_);
  1854. }
  1855. _LIBCPP_HIDE_FROM_ABI hasher hash_function() const { return __table_.hash_function().hash_function(); }
  1856. _LIBCPP_HIDE_FROM_ABI key_equal key_eq() const { return __table_.key_eq().key_eq(); }
  1857. _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __table_.find(__k); }
  1858. _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __table_.find(__k); }
  1859. #if _LIBCPP_STD_VER >= 20
  1860. template <class _K2,
  1861. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1862. _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
  1863. return __table_.find(__k);
  1864. }
  1865. template <class _K2,
  1866. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1867. _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
  1868. return __table_.find(__k);
  1869. }
  1870. #endif // _LIBCPP_STD_VER >= 20
  1871. _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __table_.__count_multi(__k); }
  1872. #if _LIBCPP_STD_VER >= 20
  1873. template <class _K2,
  1874. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1875. _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
  1876. return __table_.__count_multi(__k);
  1877. }
  1878. #endif // _LIBCPP_STD_VER >= 20
  1879. #if _LIBCPP_STD_VER >= 20
  1880. _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
  1881. template <class _K2,
  1882. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1883. _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
  1884. return find(__k) != end();
  1885. }
  1886. #endif // _LIBCPP_STD_VER >= 20
  1887. _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
  1888. return __table_.__equal_range_multi(__k);
  1889. }
  1890. _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
  1891. return __table_.__equal_range_multi(__k);
  1892. }
  1893. #if _LIBCPP_STD_VER >= 20
  1894. template <class _K2,
  1895. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1896. _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
  1897. return __table_.__equal_range_multi(__k);
  1898. }
  1899. template <class _K2,
  1900. enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1901. _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
  1902. return __table_.__equal_range_multi(__k);
  1903. }
  1904. #endif // _LIBCPP_STD_VER >= 20
  1905. _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const _NOEXCEPT { return __table_.bucket_count(); }
  1906. _LIBCPP_HIDE_FROM_ABI size_type max_bucket_count() const _NOEXCEPT { return __table_.max_bucket_count(); }
  1907. _LIBCPP_HIDE_FROM_ABI size_type bucket_size(size_type __n) const { return __table_.bucket_size(__n); }
  1908. _LIBCPP_HIDE_FROM_ABI size_type bucket(const key_type& __k) const { return __table_.bucket(__k); }
  1909. _LIBCPP_HIDE_FROM_ABI local_iterator begin(size_type __n) { return __table_.begin(__n); }
  1910. _LIBCPP_HIDE_FROM_ABI local_iterator end(size_type __n) { return __table_.end(__n); }
  1911. _LIBCPP_HIDE_FROM_ABI const_local_iterator begin(size_type __n) const { return __table_.cbegin(__n); }
  1912. _LIBCPP_HIDE_FROM_ABI const_local_iterator end(size_type __n) const { return __table_.cend(__n); }
  1913. _LIBCPP_HIDE_FROM_ABI const_local_iterator cbegin(size_type __n) const { return __table_.cbegin(__n); }
  1914. _LIBCPP_HIDE_FROM_ABI const_local_iterator cend(size_type __n) const { return __table_.cend(__n); }
  1915. _LIBCPP_HIDE_FROM_ABI float load_factor() const _NOEXCEPT { return __table_.load_factor(); }
  1916. _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __table_.max_load_factor(); }
  1917. _LIBCPP_HIDE_FROM_ABI void max_load_factor(float __mlf) { __table_.max_load_factor(__mlf); }
  1918. _LIBCPP_HIDE_FROM_ABI void rehash(size_type __n) { __table_.__rehash_multi(__n); }
  1919. _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n) { __table_.__reserve_multi(__n); }
  1920. };
  1921. #if _LIBCPP_STD_VER >= 17
  1922. template <class _InputIterator,
  1923. class _Hash = hash<__iter_key_type<_InputIterator>>,
  1924. class _Pred = equal_to<__iter_key_type<_InputIterator>>,
  1925. class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
  1926. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1927. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1928. class = enable_if_t<!is_integral<_Hash>::value>,
  1929. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1930. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1931. unordered_multimap(_InputIterator,
  1932. _InputIterator,
  1933. typename allocator_traits<_Allocator>::size_type = 0,
  1934. _Hash = _Hash(),
  1935. _Pred = _Pred(),
  1936. _Allocator = _Allocator())
  1937. -> unordered_multimap<__iter_key_type<_InputIterator>,
  1938. __iter_mapped_type<_InputIterator>,
  1939. _Hash,
  1940. _Pred,
  1941. _Allocator>;
  1942. # if _LIBCPP_STD_VER >= 23
  1943. template <ranges::input_range _Range,
  1944. class _Hash = hash<__range_key_type<_Range>>,
  1945. class _Pred = equal_to<__range_key_type<_Range>>,
  1946. class _Allocator = allocator<__range_to_alloc_type<_Range>>,
  1947. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1948. class = enable_if_t<!is_integral<_Hash>::value>,
  1949. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1950. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1951. unordered_multimap(from_range_t,
  1952. _Range&&,
  1953. typename allocator_traits<_Allocator>::size_type = 0,
  1954. _Hash = _Hash(),
  1955. _Pred = _Pred(),
  1956. _Allocator = _Allocator())
  1957. -> unordered_multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, _Hash, _Pred, _Allocator>;
  1958. # endif
  1959. template <class _Key,
  1960. class _Tp,
  1961. class _Hash = hash<remove_const_t<_Key>>,
  1962. class _Pred = equal_to<remove_const_t<_Key>>,
  1963. class _Allocator = allocator<pair<const _Key, _Tp>>,
  1964. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1965. class = enable_if_t<!is_integral<_Hash>::value>,
  1966. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1967. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1968. unordered_multimap(initializer_list<pair<_Key, _Tp>>,
  1969. typename allocator_traits<_Allocator>::size_type = 0,
  1970. _Hash = _Hash(),
  1971. _Pred = _Pred(),
  1972. _Allocator = _Allocator())
  1973. -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
  1974. template <class _InputIterator,
  1975. class _Allocator,
  1976. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1977. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1978. unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1979. -> unordered_multimap<__iter_key_type<_InputIterator>,
  1980. __iter_mapped_type<_InputIterator>,
  1981. hash<__iter_key_type<_InputIterator>>,
  1982. equal_to<__iter_key_type<_InputIterator>>,
  1983. _Allocator>;
  1984. template <class _InputIterator,
  1985. class _Allocator,
  1986. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1987. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1988. unordered_multimap(_InputIterator, _InputIterator, _Allocator)
  1989. -> unordered_multimap<__iter_key_type<_InputIterator>,
  1990. __iter_mapped_type<_InputIterator>,
  1991. hash<__iter_key_type<_InputIterator>>,
  1992. equal_to<__iter_key_type<_InputIterator>>,
  1993. _Allocator>;
  1994. template <class _InputIterator,
  1995. class _Hash,
  1996. class _Allocator,
  1997. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1998. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1999. class = enable_if_t<!is_integral<_Hash>::value>,
  2000. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2001. unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  2002. -> unordered_multimap<__iter_key_type<_InputIterator>,
  2003. __iter_mapped_type<_InputIterator>,
  2004. _Hash,
  2005. equal_to<__iter_key_type<_InputIterator>>,
  2006. _Allocator>;
  2007. # if _LIBCPP_STD_VER >= 23
  2008. template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
  2009. unordered_multimap(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Allocator)
  2010. -> unordered_multimap<__range_key_type<_Range>,
  2011. __range_mapped_type<_Range>,
  2012. hash<__range_key_type<_Range>>,
  2013. equal_to<__range_key_type<_Range>>,
  2014. _Allocator>;
  2015. template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
  2016. unordered_multimap(from_range_t, _Range&&, _Allocator)
  2017. -> unordered_multimap<__range_key_type<_Range>,
  2018. __range_mapped_type<_Range>,
  2019. hash<__range_key_type<_Range>>,
  2020. equal_to<__range_key_type<_Range>>,
  2021. _Allocator>;
  2022. template <ranges::input_range _Range,
  2023. class _Hash,
  2024. class _Allocator,
  2025. class = enable_if_t<!__is_allocator<_Hash>::value>,
  2026. class = enable_if_t<!is_integral<_Hash>::value>,
  2027. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2028. unordered_multimap(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  2029. -> unordered_multimap<__range_key_type<_Range>,
  2030. __range_mapped_type<_Range>,
  2031. _Hash,
  2032. equal_to<__range_key_type<_Range>>,
  2033. _Allocator>;
  2034. # endif
  2035. template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
  2036. unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
  2037. -> unordered_multimap<remove_const_t<_Key>,
  2038. _Tp,
  2039. hash<remove_const_t<_Key>>,
  2040. equal_to<remove_const_t<_Key>>,
  2041. _Allocator>;
  2042. template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value>>
  2043. unordered_multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
  2044. -> unordered_multimap<remove_const_t<_Key>,
  2045. _Tp,
  2046. hash<remove_const_t<_Key>>,
  2047. equal_to<remove_const_t<_Key>>,
  2048. _Allocator>;
  2049. template <class _Key,
  2050. class _Tp,
  2051. class _Hash,
  2052. class _Allocator,
  2053. class = enable_if_t<!__is_allocator<_Hash>::value>,
  2054. class = enable_if_t<!is_integral<_Hash>::value>,
  2055. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2056. unordered_multimap(
  2057. initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  2058. -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, equal_to<remove_const_t<_Key>>, _Allocator>;
  2059. #endif
  2060. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2061. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2062. size_type __n, const hasher& __hf, const key_equal& __eql)
  2063. : __table_(__hf, __eql) {
  2064. __table_.__rehash_multi(__n);
  2065. }
  2066. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2067. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2068. size_type __n, const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  2069. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  2070. __table_.__rehash_multi(__n);
  2071. }
  2072. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2073. template <class _InputIterator>
  2074. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(_InputIterator __first, _InputIterator __last) {
  2075. insert(__first, __last);
  2076. }
  2077. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2078. template <class _InputIterator>
  2079. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2080. _InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const key_equal& __eql)
  2081. : __table_(__hf, __eql) {
  2082. __table_.__rehash_multi(__n);
  2083. insert(__first, __last);
  2084. }
  2085. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2086. template <class _InputIterator>
  2087. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2088. _InputIterator __first,
  2089. _InputIterator __last,
  2090. size_type __n,
  2091. const hasher& __hf,
  2092. const key_equal& __eql,
  2093. const allocator_type& __a)
  2094. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  2095. __table_.__rehash_multi(__n);
  2096. insert(__first, __last);
  2097. }
  2098. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2099. inline unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(const allocator_type& __a)
  2100. : __table_(typename __table::allocator_type(__a)) {}
  2101. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2102. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(const unordered_multimap& __u)
  2103. : __table_(__u.__table_) {
  2104. __table_.__rehash_multi(__u.bucket_count());
  2105. insert(__u.begin(), __u.end());
  2106. }
  2107. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2108. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2109. const unordered_multimap& __u, const allocator_type& __a)
  2110. : __table_(__u.__table_, typename __table::allocator_type(__a)) {
  2111. __table_.__rehash_multi(__u.bucket_count());
  2112. insert(__u.begin(), __u.end());
  2113. }
  2114. #ifndef _LIBCPP_CXX03_LANG
  2115. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2116. inline unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(unordered_multimap&& __u)
  2117. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
  2118. : __table_(std::move(__u.__table_)) {}
  2119. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2120. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2121. unordered_multimap&& __u, const allocator_type& __a)
  2122. : __table_(std::move(__u.__table_), typename __table::allocator_type(__a)) {
  2123. if (__a != __u.get_allocator()) {
  2124. iterator __i = __u.begin();
  2125. while (__u.size() != 0) {
  2126. __table_.__insert_multi(__u.__table_.remove((__i++).__i_)->__get_value().__move());
  2127. }
  2128. }
  2129. }
  2130. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2131. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(initializer_list<value_type> __il) {
  2132. insert(__il.begin(), __il.end());
  2133. }
  2134. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2135. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2136. initializer_list<value_type> __il, size_type __n, const hasher& __hf, const key_equal& __eql)
  2137. : __table_(__hf, __eql) {
  2138. __table_.__rehash_multi(__n);
  2139. insert(__il.begin(), __il.end());
  2140. }
  2141. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2142. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2143. initializer_list<value_type> __il,
  2144. size_type __n,
  2145. const hasher& __hf,
  2146. const key_equal& __eql,
  2147. const allocator_type& __a)
  2148. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  2149. __table_.__rehash_multi(__n);
  2150. insert(__il.begin(), __il.end());
  2151. }
  2152. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2153. inline unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
  2154. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
  2155. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value) {
  2156. __table_ = std::move(__u.__table_);
  2157. return *this;
  2158. }
  2159. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2160. inline unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
  2161. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(initializer_list<value_type> __il) {
  2162. __table_.__assign_multi(__il.begin(), __il.end());
  2163. return *this;
  2164. }
  2165. #endif // _LIBCPP_CXX03_LANG
  2166. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2167. template <class _InputIterator>
  2168. inline void unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
  2169. for (; __first != __last; ++__first)
  2170. __table_.__insert_multi(*__first);
  2171. }
  2172. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2173. inline _LIBCPP_HIDE_FROM_ABI void
  2174. swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
  2175. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
  2176. __x.swap(__y);
  2177. }
  2178. #if _LIBCPP_STD_VER >= 20
  2179. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate>
  2180. inline _LIBCPP_HIDE_FROM_ABI typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
  2181. erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred) {
  2182. return std::__libcpp_erase_if_container(__c, __pred);
  2183. }
  2184. #endif
  2185. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2186. _LIBCPP_HIDE_FROM_ABI bool operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  2187. const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) {
  2188. if (__x.size() != __y.size())
  2189. return false;
  2190. typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator const_iterator;
  2191. typedef pair<const_iterator, const_iterator> _EqRng;
  2192. for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) {
  2193. _EqRng __xeq = __x.equal_range(__i->first);
  2194. _EqRng __yeq = __y.equal_range(__i->first);
  2195. if (std::distance(__xeq.first, __xeq.second) != std::distance(__yeq.first, __yeq.second) ||
  2196. !std::is_permutation(__xeq.first, __xeq.second, __yeq.first))
  2197. return false;
  2198. __i = __xeq.second;
  2199. }
  2200. return true;
  2201. }
  2202. #if _LIBCPP_STD_VER <= 17
  2203. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2204. inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  2205. const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) {
  2206. return !(__x == __y);
  2207. }
  2208. #endif
  2209. _LIBCPP_END_NAMESPACE_STD
  2210. #if _LIBCPP_STD_VER >= 17
  2211. _LIBCPP_BEGIN_NAMESPACE_STD
  2212. namespace pmr {
  2213. template <class _KeyT, class _ValueT, class _HashT = std::hash<_KeyT>, class _PredT = std::equal_to<_KeyT>>
  2214. using unordered_map _LIBCPP_AVAILABILITY_PMR =
  2215. std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
  2216. template <class _KeyT, class _ValueT, class _HashT = std::hash<_KeyT>, class _PredT = std::equal_to<_KeyT>>
  2217. using unordered_multimap _LIBCPP_AVAILABILITY_PMR =
  2218. std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
  2219. } // namespace pmr
  2220. _LIBCPP_END_NAMESPACE_STD
  2221. #endif
  2222. _LIBCPP_POP_MACROS
  2223. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  2224. # include <algorithm>
  2225. # include <bit>
  2226. # include <concepts>
  2227. # include <cstdlib>
  2228. # include <iterator>
  2229. # include <type_traits>
  2230. #endif
  2231. #endif // _LIBCPP_UNORDERED_MAP