unordered_map 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805
  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> // all public C++ headers provide the assertion handler
  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_BEGIN_NAMESPACE_STD
  544. template <class _Key, class _Cp, class _Hash, class _Pred,
  545. bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value>
  546. class __unordered_map_hasher
  547. : private _Hash
  548. {
  549. public:
  550. _LIBCPP_INLINE_VISIBILITY
  551. __unordered_map_hasher()
  552. _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
  553. : _Hash() {}
  554. _LIBCPP_INLINE_VISIBILITY
  555. __unordered_map_hasher(const _Hash& __h)
  556. _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
  557. : _Hash(__h) {}
  558. _LIBCPP_INLINE_VISIBILITY
  559. const _Hash& hash_function() const _NOEXCEPT {return *this;}
  560. _LIBCPP_INLINE_VISIBILITY
  561. size_t operator()(const _Cp& __x) const
  562. {return static_cast<const _Hash&>(*this)(__x.__get_value().first);}
  563. _LIBCPP_INLINE_VISIBILITY
  564. size_t operator()(const _Key& __x) const
  565. {return static_cast<const _Hash&>(*this)(__x);}
  566. #if _LIBCPP_STD_VER >= 20
  567. template <typename _K2>
  568. _LIBCPP_INLINE_VISIBILITY
  569. size_t operator()(const _K2& __x) const
  570. {return static_cast<const _Hash&>(*this)(__x);}
  571. #endif
  572. _LIBCPP_INLINE_VISIBILITY
  573. void swap(__unordered_map_hasher& __y)
  574. _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
  575. {
  576. using _VSTD::swap;
  577. swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
  578. }
  579. };
  580. template <class _Key, class _Cp, class _Hash, class _Pred>
  581. class __unordered_map_hasher<_Key, _Cp, _Hash, _Pred, false>
  582. {
  583. _Hash __hash_;
  584. public:
  585. _LIBCPP_INLINE_VISIBILITY
  586. __unordered_map_hasher()
  587. _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
  588. : __hash_() {}
  589. _LIBCPP_INLINE_VISIBILITY
  590. __unordered_map_hasher(const _Hash& __h)
  591. _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
  592. : __hash_(__h) {}
  593. _LIBCPP_INLINE_VISIBILITY
  594. const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
  595. _LIBCPP_INLINE_VISIBILITY
  596. size_t operator()(const _Cp& __x) const
  597. {return __hash_(__x.__get_value().first);}
  598. _LIBCPP_INLINE_VISIBILITY
  599. size_t operator()(const _Key& __x) const
  600. {return __hash_(__x);}
  601. #if _LIBCPP_STD_VER >= 20
  602. template <typename _K2>
  603. _LIBCPP_INLINE_VISIBILITY
  604. size_t operator()(const _K2& __x) const
  605. {return __hash_(__x);}
  606. #endif
  607. _LIBCPP_INLINE_VISIBILITY
  608. void swap(__unordered_map_hasher& __y)
  609. _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
  610. {
  611. using _VSTD::swap;
  612. swap(__hash_, __y.__hash_);
  613. }
  614. };
  615. template <class _Key, class _Cp, class _Hash, class _Pred, bool __b>
  616. inline _LIBCPP_INLINE_VISIBILITY
  617. void
  618. swap(__unordered_map_hasher<_Key, _Cp, _Hash, _Pred, __b>& __x,
  619. __unordered_map_hasher<_Key, _Cp, _Hash, _Pred, __b>& __y)
  620. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  621. {
  622. __x.swap(__y);
  623. }
  624. template <class _Key, class _Cp, class _Pred, class _Hash,
  625. bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value>
  626. class __unordered_map_equal
  627. : private _Pred
  628. {
  629. public:
  630. _LIBCPP_INLINE_VISIBILITY
  631. __unordered_map_equal()
  632. _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
  633. : _Pred() {}
  634. _LIBCPP_INLINE_VISIBILITY
  635. __unordered_map_equal(const _Pred& __p)
  636. _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
  637. : _Pred(__p) {}
  638. _LIBCPP_INLINE_VISIBILITY
  639. const _Pred& key_eq() const _NOEXCEPT {return *this;}
  640. _LIBCPP_INLINE_VISIBILITY
  641. bool operator()(const _Cp& __x, const _Cp& __y) const
  642. {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);}
  643. _LIBCPP_INLINE_VISIBILITY
  644. bool operator()(const _Cp& __x, const _Key& __y) const
  645. {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
  646. _LIBCPP_INLINE_VISIBILITY
  647. bool operator()(const _Key& __x, const _Cp& __y) const
  648. {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
  649. #if _LIBCPP_STD_VER >= 20
  650. template <typename _K2>
  651. _LIBCPP_INLINE_VISIBILITY
  652. bool operator()(const _Cp& __x, const _K2& __y) const
  653. {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
  654. template <typename _K2>
  655. _LIBCPP_INLINE_VISIBILITY
  656. bool operator()(const _K2& __x, const _Cp& __y) const
  657. {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
  658. template <typename _K2>
  659. _LIBCPP_INLINE_VISIBILITY
  660. bool operator()(const _Key& __x, const _K2& __y) const
  661. {return static_cast<const _Pred&>(*this)(__x, __y);}
  662. template <typename _K2>
  663. _LIBCPP_INLINE_VISIBILITY
  664. bool operator()(const _K2& __x, const _Key& __y) const
  665. {return static_cast<const _Pred&>(*this)(__x, __y);}
  666. #endif
  667. _LIBCPP_INLINE_VISIBILITY
  668. void swap(__unordered_map_equal& __y)
  669. _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
  670. {
  671. using _VSTD::swap;
  672. swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
  673. }
  674. };
  675. template <class _Key, class _Cp, class _Pred, class _Hash>
  676. class __unordered_map_equal<_Key, _Cp, _Pred, _Hash, false>
  677. {
  678. _Pred __pred_;
  679. public:
  680. _LIBCPP_INLINE_VISIBILITY
  681. __unordered_map_equal()
  682. _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
  683. : __pred_() {}
  684. _LIBCPP_INLINE_VISIBILITY
  685. __unordered_map_equal(const _Pred& __p)
  686. _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
  687. : __pred_(__p) {}
  688. _LIBCPP_INLINE_VISIBILITY
  689. const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
  690. _LIBCPP_INLINE_VISIBILITY
  691. bool operator()(const _Cp& __x, const _Cp& __y) const
  692. {return __pred_(__x.__get_value().first, __y.__get_value().first);}
  693. _LIBCPP_INLINE_VISIBILITY
  694. bool operator()(const _Cp& __x, const _Key& __y) const
  695. {return __pred_(__x.__get_value().first, __y);}
  696. _LIBCPP_INLINE_VISIBILITY
  697. bool operator()(const _Key& __x, const _Cp& __y) const
  698. {return __pred_(__x, __y.__get_value().first);}
  699. #if _LIBCPP_STD_VER >= 20
  700. template <typename _K2>
  701. _LIBCPP_INLINE_VISIBILITY
  702. bool operator()(const _Cp& __x, const _K2& __y) const
  703. {return __pred_(__x.__get_value().first, __y);}
  704. template <typename _K2>
  705. _LIBCPP_INLINE_VISIBILITY
  706. bool operator()(const _K2& __x, const _Cp& __y) const
  707. {return __pred_(__x, __y.__get_value().first);}
  708. template <typename _K2>
  709. _LIBCPP_INLINE_VISIBILITY
  710. bool operator()(const _Key& __x, const _K2& __y) const
  711. {return __pred_(__x, __y);}
  712. template <typename _K2>
  713. _LIBCPP_INLINE_VISIBILITY
  714. bool operator()(const _K2& __x, const _Key& __y) const
  715. {return __pred_(__x, __y);}
  716. #endif
  717. _LIBCPP_INLINE_VISIBILITY
  718. void swap(__unordered_map_equal& __y)
  719. _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
  720. {
  721. using _VSTD::swap;
  722. swap(__pred_, __y.__pred_);
  723. }
  724. };
  725. template <class _Key, class _Cp, class _Pred, class _Hash, bool __b>
  726. inline _LIBCPP_INLINE_VISIBILITY
  727. void
  728. swap(__unordered_map_equal<_Key, _Cp, _Pred, _Hash, __b>& __x,
  729. __unordered_map_equal<_Key, _Cp, _Pred, _Hash, __b>& __y)
  730. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  731. {
  732. __x.swap(__y);
  733. }
  734. template <class _Alloc>
  735. class __hash_map_node_destructor
  736. {
  737. typedef _Alloc allocator_type;
  738. typedef allocator_traits<allocator_type> __alloc_traits;
  739. public:
  740. typedef typename __alloc_traits::pointer pointer;
  741. private:
  742. allocator_type& __na_;
  743. __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
  744. public:
  745. bool __first_constructed;
  746. bool __second_constructed;
  747. _LIBCPP_INLINE_VISIBILITY
  748. explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
  749. : __na_(__na),
  750. __first_constructed(false),
  751. __second_constructed(false)
  752. {}
  753. #ifndef _LIBCPP_CXX03_LANG
  754. _LIBCPP_INLINE_VISIBILITY
  755. __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
  756. _NOEXCEPT
  757. : __na_(__x.__na_),
  758. __first_constructed(__x.__value_constructed),
  759. __second_constructed(__x.__value_constructed)
  760. {
  761. __x.__value_constructed = false;
  762. }
  763. #else // _LIBCPP_CXX03_LANG
  764. _LIBCPP_INLINE_VISIBILITY
  765. __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
  766. : __na_(__x.__na_),
  767. __first_constructed(__x.__value_constructed),
  768. __second_constructed(__x.__value_constructed)
  769. {
  770. const_cast<bool&>(__x.__value_constructed) = false;
  771. }
  772. #endif // _LIBCPP_CXX03_LANG
  773. _LIBCPP_INLINE_VISIBILITY
  774. void operator()(pointer __p) _NOEXCEPT
  775. {
  776. if (__second_constructed)
  777. __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__get_value().__get_value().second));
  778. if (__first_constructed)
  779. __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__get_value().__get_value().first));
  780. if (__p)
  781. __alloc_traits::deallocate(__na_, __p, 1);
  782. }
  783. };
  784. #ifndef _LIBCPP_CXX03_LANG
  785. template <class _Key, class _Tp>
  786. struct _LIBCPP_STANDALONE_DEBUG __hash_value_type
  787. {
  788. typedef _Key key_type;
  789. typedef _Tp mapped_type;
  790. typedef pair<const key_type, mapped_type> value_type;
  791. typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
  792. typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
  793. private:
  794. value_type __cc_;
  795. public:
  796. _LIBCPP_INLINE_VISIBILITY
  797. value_type& __get_value()
  798. {
  799. #if _LIBCPP_STD_VER >= 17
  800. return *_VSTD::launder(_VSTD::addressof(__cc_));
  801. #else
  802. return __cc_;
  803. #endif
  804. }
  805. _LIBCPP_INLINE_VISIBILITY
  806. const value_type& __get_value() const
  807. {
  808. #if _LIBCPP_STD_VER >= 17
  809. return *_VSTD::launder(_VSTD::addressof(__cc_));
  810. #else
  811. return __cc_;
  812. #endif
  813. }
  814. _LIBCPP_INLINE_VISIBILITY
  815. __nc_ref_pair_type __ref()
  816. {
  817. value_type& __v = __get_value();
  818. return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
  819. }
  820. _LIBCPP_INLINE_VISIBILITY
  821. __nc_rref_pair_type __move()
  822. {
  823. value_type& __v = __get_value();
  824. return __nc_rref_pair_type(
  825. _VSTD::move(const_cast<key_type&>(__v.first)),
  826. _VSTD::move(__v.second));
  827. }
  828. _LIBCPP_INLINE_VISIBILITY
  829. __hash_value_type& operator=(const __hash_value_type& __v)
  830. {
  831. __ref() = __v.__get_value();
  832. return *this;
  833. }
  834. _LIBCPP_INLINE_VISIBILITY
  835. __hash_value_type& operator=(__hash_value_type&& __v)
  836. {
  837. __ref() = __v.__move();
  838. return *this;
  839. }
  840. template <class _ValueTp,
  841. class = __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value>
  842. >
  843. _LIBCPP_INLINE_VISIBILITY
  844. __hash_value_type& operator=(_ValueTp&& __v)
  845. {
  846. __ref() = _VSTD::forward<_ValueTp>(__v);
  847. return *this;
  848. }
  849. private:
  850. __hash_value_type(const __hash_value_type& __v) = delete;
  851. __hash_value_type(__hash_value_type&& __v) = delete;
  852. template <class ..._Args>
  853. explicit __hash_value_type(_Args&& ...__args) = delete;
  854. ~__hash_value_type() = delete;
  855. };
  856. #else
  857. template <class _Key, class _Tp>
  858. struct __hash_value_type
  859. {
  860. typedef _Key key_type;
  861. typedef _Tp mapped_type;
  862. typedef pair<const key_type, mapped_type> value_type;
  863. private:
  864. value_type __cc_;
  865. public:
  866. _LIBCPP_INLINE_VISIBILITY
  867. value_type& __get_value() { return __cc_; }
  868. _LIBCPP_INLINE_VISIBILITY
  869. const value_type& __get_value() const { return __cc_; }
  870. private:
  871. ~__hash_value_type();
  872. };
  873. #endif
  874. template <class _HashIterator>
  875. class _LIBCPP_TEMPLATE_VIS __hash_map_iterator
  876. {
  877. _HashIterator __i_;
  878. typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
  879. public:
  880. typedef forward_iterator_tag iterator_category;
  881. typedef typename _NodeTypes::__map_value_type value_type;
  882. typedef typename _NodeTypes::difference_type difference_type;
  883. typedef value_type& reference;
  884. typedef typename _NodeTypes::__map_value_type_pointer pointer;
  885. _LIBCPP_INLINE_VISIBILITY
  886. __hash_map_iterator() _NOEXCEPT {}
  887. _LIBCPP_INLINE_VISIBILITY
  888. __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
  889. _LIBCPP_INLINE_VISIBILITY
  890. reference operator*() const {return __i_->__get_value();}
  891. _LIBCPP_INLINE_VISIBILITY
  892. pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
  893. _LIBCPP_INLINE_VISIBILITY
  894. __hash_map_iterator& operator++() {++__i_; return *this;}
  895. _LIBCPP_INLINE_VISIBILITY
  896. __hash_map_iterator operator++(int)
  897. {
  898. __hash_map_iterator __t(*this);
  899. ++(*this);
  900. return __t;
  901. }
  902. friend _LIBCPP_INLINE_VISIBILITY
  903. bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
  904. {return __x.__i_ == __y.__i_;}
  905. #if _LIBCPP_STD_VER <= 17
  906. friend _LIBCPP_INLINE_VISIBILITY
  907. bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
  908. {return __x.__i_ != __y.__i_;}
  909. #endif
  910. template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
  911. template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
  912. template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
  913. template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
  914. template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
  915. };
  916. template <class _HashIterator>
  917. class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
  918. {
  919. _HashIterator __i_;
  920. typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
  921. public:
  922. typedef forward_iterator_tag iterator_category;
  923. typedef typename _NodeTypes::__map_value_type value_type;
  924. typedef typename _NodeTypes::difference_type difference_type;
  925. typedef const value_type& reference;
  926. typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
  927. _LIBCPP_INLINE_VISIBILITY
  928. __hash_map_const_iterator() _NOEXCEPT {}
  929. _LIBCPP_INLINE_VISIBILITY
  930. __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
  931. _LIBCPP_INLINE_VISIBILITY
  932. __hash_map_const_iterator(
  933. __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
  934. _NOEXCEPT
  935. : __i_(__i.__i_) {}
  936. _LIBCPP_INLINE_VISIBILITY
  937. reference operator*() const {return __i_->__get_value();}
  938. _LIBCPP_INLINE_VISIBILITY
  939. pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
  940. _LIBCPP_INLINE_VISIBILITY
  941. __hash_map_const_iterator& operator++() {++__i_; return *this;}
  942. _LIBCPP_INLINE_VISIBILITY
  943. __hash_map_const_iterator operator++(int)
  944. {
  945. __hash_map_const_iterator __t(*this);
  946. ++(*this);
  947. return __t;
  948. }
  949. friend _LIBCPP_INLINE_VISIBILITY
  950. bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
  951. {return __x.__i_ == __y.__i_;}
  952. #if _LIBCPP_STD_VER <= 17
  953. friend _LIBCPP_INLINE_VISIBILITY
  954. bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
  955. {return __x.__i_ != __y.__i_;}
  956. #endif
  957. template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
  958. template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
  959. template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
  960. template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
  961. };
  962. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  963. class unordered_multimap;
  964. template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
  965. class _Alloc = allocator<pair<const _Key, _Tp> > >
  966. class _LIBCPP_TEMPLATE_VIS unordered_map
  967. {
  968. public:
  969. // types
  970. typedef _Key key_type;
  971. typedef _Tp mapped_type;
  972. typedef __type_identity_t<_Hash> hasher;
  973. typedef __type_identity_t<_Pred> key_equal;
  974. typedef __type_identity_t<_Alloc> allocator_type;
  975. typedef pair<const key_type, mapped_type> value_type;
  976. typedef value_type& reference;
  977. typedef const value_type& const_reference;
  978. static_assert((is_same<value_type, typename allocator_type::value_type>::value),
  979. "Allocator::value_type must be same type as value_type");
  980. private:
  981. typedef __hash_value_type<key_type, mapped_type> __value_type;
  982. typedef __unordered_map_hasher<key_type, __value_type, hasher, key_equal> __hasher;
  983. typedef __unordered_map_equal<key_type, __value_type, key_equal, hasher> __key_equal;
  984. typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
  985. typedef __hash_table<__value_type, __hasher,
  986. __key_equal, __allocator_type> __table;
  987. __table __table_;
  988. typedef typename __table::_NodeTypes _NodeTypes;
  989. typedef typename __table::__node_pointer __node_pointer;
  990. typedef typename __table::__node_const_pointer __node_const_pointer;
  991. typedef typename __table::__node_traits __node_traits;
  992. typedef typename __table::__node_allocator __node_allocator;
  993. typedef typename __table::__node __node;
  994. typedef __hash_map_node_destructor<__node_allocator> _Dp;
  995. typedef unique_ptr<__node, _Dp> __node_holder;
  996. typedef allocator_traits<allocator_type> __alloc_traits;
  997. static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
  998. "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
  999. "original allocator");
  1000. static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
  1001. static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
  1002. public:
  1003. typedef typename __alloc_traits::pointer pointer;
  1004. typedef typename __alloc_traits::const_pointer const_pointer;
  1005. typedef typename __table::size_type size_type;
  1006. typedef typename __table::difference_type difference_type;
  1007. typedef __hash_map_iterator<typename __table::iterator> iterator;
  1008. typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
  1009. typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
  1010. typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
  1011. #if _LIBCPP_STD_VER >= 17
  1012. typedef __map_node_handle<__node, allocator_type> node_type;
  1013. typedef __insert_return_type<iterator, node_type> insert_return_type;
  1014. #endif
  1015. template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
  1016. friend class _LIBCPP_TEMPLATE_VIS unordered_map;
  1017. template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
  1018. friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
  1019. _LIBCPP_INLINE_VISIBILITY
  1020. unordered_map()
  1021. _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
  1022. {
  1023. }
  1024. explicit _LIBCPP_HIDE_FROM_ABI unordered_map(size_type __n, const hasher& __hf = hasher(),
  1025. const key_equal& __eql = key_equal());
  1026. _LIBCPP_HIDE_FROM_ABI unordered_map(size_type __n, const hasher& __hf,
  1027. const key_equal& __eql,
  1028. const allocator_type& __a);
  1029. template <class _InputIterator>
  1030. _LIBCPP_HIDE_FROM_ABI unordered_map(_InputIterator __first, _InputIterator __last);
  1031. template <class _InputIterator>
  1032. _LIBCPP_HIDE_FROM_ABI unordered_map(_InputIterator __first, _InputIterator __last,
  1033. size_type __n, const hasher& __hf = hasher(),
  1034. const key_equal& __eql = key_equal());
  1035. template <class _InputIterator>
  1036. _LIBCPP_HIDE_FROM_ABI unordered_map(_InputIterator __first, _InputIterator __last,
  1037. size_type __n, const hasher& __hf,
  1038. const key_equal& __eql,
  1039. const allocator_type& __a);
  1040. #if _LIBCPP_STD_VER >= 23
  1041. template <_ContainerCompatibleRange<value_type> _Range>
  1042. _LIBCPP_HIDE_FROM_ABI
  1043. unordered_map(from_range_t, _Range&& __range, size_type __n = /*implementation-defined*/0,
  1044. const hasher& __hf = hasher(), const key_equal& __eql = key_equal(),
  1045. const allocator_type& __a = allocator_type())
  1046. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  1047. if (__n > 0) {
  1048. __table_.__rehash_unique(__n);
  1049. }
  1050. insert_range(std::forward<_Range>(__range));
  1051. }
  1052. #endif
  1053. _LIBCPP_INLINE_VISIBILITY
  1054. explicit unordered_map(const allocator_type& __a);
  1055. _LIBCPP_HIDE_FROM_ABI unordered_map(const unordered_map& __u);
  1056. _LIBCPP_HIDE_FROM_ABI unordered_map(const unordered_map& __u, const allocator_type& __a);
  1057. #ifndef _LIBCPP_CXX03_LANG
  1058. _LIBCPP_INLINE_VISIBILITY
  1059. unordered_map(unordered_map&& __u)
  1060. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
  1061. _LIBCPP_HIDE_FROM_ABI unordered_map(unordered_map&& __u, const allocator_type& __a);
  1062. _LIBCPP_HIDE_FROM_ABI unordered_map(initializer_list<value_type> __il);
  1063. _LIBCPP_HIDE_FROM_ABI unordered_map(initializer_list<value_type> __il, size_type __n,
  1064. const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
  1065. _LIBCPP_HIDE_FROM_ABI unordered_map(initializer_list<value_type> __il, size_type __n,
  1066. const hasher& __hf, const key_equal& __eql,
  1067. const allocator_type& __a);
  1068. #endif // _LIBCPP_CXX03_LANG
  1069. #if _LIBCPP_STD_VER >= 14
  1070. _LIBCPP_INLINE_VISIBILITY
  1071. unordered_map(size_type __n, const allocator_type& __a)
  1072. : unordered_map(__n, hasher(), key_equal(), __a) {}
  1073. _LIBCPP_INLINE_VISIBILITY
  1074. unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
  1075. : unordered_map(__n, __hf, key_equal(), __a) {}
  1076. template <class _InputIterator>
  1077. _LIBCPP_INLINE_VISIBILITY
  1078. unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
  1079. : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
  1080. template <class _InputIterator>
  1081. _LIBCPP_INLINE_VISIBILITY
  1082. unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
  1083. const allocator_type& __a)
  1084. : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
  1085. #if _LIBCPP_STD_VER >= 23
  1086. template <_ContainerCompatibleRange<value_type> _Range>
  1087. _LIBCPP_HIDE_FROM_ABI
  1088. unordered_map(from_range_t, _Range&& __range, size_type __n, const allocator_type& __a)
  1089. : unordered_map(from_range, std::forward<_Range>(__range), __n, hasher(), key_equal(), __a) {}
  1090. template <_ContainerCompatibleRange<value_type> _Range>
  1091. _LIBCPP_HIDE_FROM_ABI
  1092. unordered_map(from_range_t, _Range&& __range, size_type __n, const hasher& __hf, const allocator_type& __a)
  1093. : unordered_map(from_range, std::forward<_Range>(__range), __n, __hf, key_equal(), __a) {}
  1094. #endif
  1095. _LIBCPP_INLINE_VISIBILITY
  1096. unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
  1097. : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
  1098. _LIBCPP_INLINE_VISIBILITY
  1099. unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  1100. const allocator_type& __a)
  1101. : unordered_map(__il, __n, __hf, key_equal(), __a) {}
  1102. #endif
  1103. _LIBCPP_INLINE_VISIBILITY
  1104. ~unordered_map() {
  1105. static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
  1106. }
  1107. _LIBCPP_INLINE_VISIBILITY
  1108. unordered_map& operator=(const unordered_map& __u)
  1109. {
  1110. #ifndef _LIBCPP_CXX03_LANG
  1111. __table_ = __u.__table_;
  1112. #else
  1113. if (this != _VSTD::addressof(__u)) {
  1114. __table_.clear();
  1115. __table_.hash_function() = __u.__table_.hash_function();
  1116. __table_.key_eq() = __u.__table_.key_eq();
  1117. __table_.max_load_factor() = __u.__table_.max_load_factor();
  1118. __table_.__copy_assign_alloc(__u.__table_);
  1119. insert(__u.begin(), __u.end());
  1120. }
  1121. #endif
  1122. return *this;
  1123. }
  1124. #ifndef _LIBCPP_CXX03_LANG
  1125. _LIBCPP_INLINE_VISIBILITY
  1126. unordered_map& operator=(unordered_map&& __u)
  1127. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
  1128. _LIBCPP_INLINE_VISIBILITY
  1129. unordered_map& operator=(initializer_list<value_type> __il);
  1130. #endif // _LIBCPP_CXX03_LANG
  1131. _LIBCPP_INLINE_VISIBILITY
  1132. allocator_type get_allocator() const _NOEXCEPT
  1133. {return allocator_type(__table_.__node_alloc());}
  1134. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  1135. bool empty() const _NOEXCEPT {return __table_.size() == 0;}
  1136. _LIBCPP_INLINE_VISIBILITY
  1137. size_type size() const _NOEXCEPT {return __table_.size();}
  1138. _LIBCPP_INLINE_VISIBILITY
  1139. size_type max_size() const _NOEXCEPT {return __table_.max_size();}
  1140. _LIBCPP_INLINE_VISIBILITY
  1141. iterator begin() _NOEXCEPT {return __table_.begin();}
  1142. _LIBCPP_INLINE_VISIBILITY
  1143. iterator end() _NOEXCEPT {return __table_.end();}
  1144. _LIBCPP_INLINE_VISIBILITY
  1145. const_iterator begin() const _NOEXCEPT {return __table_.begin();}
  1146. _LIBCPP_INLINE_VISIBILITY
  1147. const_iterator end() const _NOEXCEPT {return __table_.end();}
  1148. _LIBCPP_INLINE_VISIBILITY
  1149. const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
  1150. _LIBCPP_INLINE_VISIBILITY
  1151. const_iterator cend() const _NOEXCEPT {return __table_.end();}
  1152. _LIBCPP_INLINE_VISIBILITY
  1153. pair<iterator, bool> insert(const value_type& __x)
  1154. {return __table_.__insert_unique(__x);}
  1155. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) {
  1156. return insert(__x).first;
  1157. }
  1158. template <class _InputIterator>
  1159. _LIBCPP_INLINE_VISIBILITY
  1160. void insert(_InputIterator __first, _InputIterator __last);
  1161. #if _LIBCPP_STD_VER >= 23
  1162. template <_ContainerCompatibleRange<value_type> _Range>
  1163. _LIBCPP_HIDE_FROM_ABI
  1164. void insert_range(_Range&& __range) {
  1165. for (auto&& __element : __range) {
  1166. __table_.__insert_unique(std::forward<decltype(__element)>(__element));
  1167. }
  1168. }
  1169. #endif
  1170. #ifndef _LIBCPP_CXX03_LANG
  1171. _LIBCPP_INLINE_VISIBILITY
  1172. void insert(initializer_list<value_type> __il)
  1173. {insert(__il.begin(), __il.end());}
  1174. _LIBCPP_INLINE_VISIBILITY
  1175. pair<iterator, bool> insert(value_type&& __x)
  1176. {return __table_.__insert_unique(_VSTD::move(__x));}
  1177. _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, value_type&& __x) {
  1178. return __table_.__insert_unique(_VSTD::move(__x)).first;
  1179. }
  1180. template <class _Pp,
  1181. class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
  1182. _LIBCPP_INLINE_VISIBILITY
  1183. pair<iterator, bool> insert(_Pp&& __x)
  1184. {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
  1185. template <class _Pp,
  1186. class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
  1187. _LIBCPP_INLINE_VISIBILITY
  1188. iterator insert(const_iterator, _Pp&& __x)
  1189. {
  1190. return insert(_VSTD::forward<_Pp>(__x)).first;
  1191. }
  1192. template <class... _Args>
  1193. _LIBCPP_INLINE_VISIBILITY
  1194. pair<iterator, bool> emplace(_Args&&... __args) {
  1195. return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
  1196. }
  1197. template <class... _Args>
  1198. _LIBCPP_INLINE_VISIBILITY
  1199. iterator emplace_hint(const_iterator, _Args&&... __args) {
  1200. return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
  1201. }
  1202. #endif // _LIBCPP_CXX03_LANG
  1203. #if _LIBCPP_STD_VER >= 17
  1204. template <class... _Args>
  1205. _LIBCPP_INLINE_VISIBILITY
  1206. pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
  1207. {
  1208. return __table_.__emplace_unique_key_args(__k, piecewise_construct,
  1209. _VSTD::forward_as_tuple(__k),
  1210. _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
  1211. }
  1212. template <class... _Args>
  1213. _LIBCPP_INLINE_VISIBILITY
  1214. pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
  1215. {
  1216. return __table_.__emplace_unique_key_args(__k, piecewise_construct,
  1217. _VSTD::forward_as_tuple(_VSTD::move(__k)),
  1218. _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
  1219. }
  1220. template <class... _Args>
  1221. _LIBCPP_INLINE_VISIBILITY
  1222. iterator try_emplace(const_iterator, const key_type& __k, _Args&&... __args)
  1223. {
  1224. return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
  1225. }
  1226. template <class... _Args>
  1227. _LIBCPP_INLINE_VISIBILITY
  1228. iterator try_emplace(const_iterator, key_type&& __k, _Args&&... __args)
  1229. {
  1230. return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
  1231. }
  1232. template <class _Vp>
  1233. _LIBCPP_INLINE_VISIBILITY
  1234. pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
  1235. {
  1236. pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
  1237. __k, _VSTD::forward<_Vp>(__v));
  1238. if (!__res.second) {
  1239. __res.first->second = _VSTD::forward<_Vp>(__v);
  1240. }
  1241. return __res;
  1242. }
  1243. template <class _Vp>
  1244. _LIBCPP_INLINE_VISIBILITY
  1245. pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
  1246. {
  1247. pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
  1248. _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
  1249. if (!__res.second) {
  1250. __res.first->second = _VSTD::forward<_Vp>(__v);
  1251. }
  1252. return __res;
  1253. }
  1254. template <class _Vp>
  1255. _LIBCPP_INLINE_VISIBILITY
  1256. iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v)
  1257. {
  1258. return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
  1259. }
  1260. template <class _Vp>
  1261. _LIBCPP_INLINE_VISIBILITY
  1262. iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v)
  1263. {
  1264. return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
  1265. }
  1266. #endif // _LIBCPP_STD_VER >= 17
  1267. _LIBCPP_INLINE_VISIBILITY
  1268. iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
  1269. _LIBCPP_INLINE_VISIBILITY
  1270. iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
  1271. _LIBCPP_INLINE_VISIBILITY
  1272. size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
  1273. _LIBCPP_INLINE_VISIBILITY
  1274. iterator erase(const_iterator __first, const_iterator __last)
  1275. {return __table_.erase(__first.__i_, __last.__i_);}
  1276. _LIBCPP_INLINE_VISIBILITY
  1277. void clear() _NOEXCEPT {__table_.clear();}
  1278. #if _LIBCPP_STD_VER >= 17
  1279. _LIBCPP_INLINE_VISIBILITY
  1280. insert_return_type insert(node_type&& __nh)
  1281. {
  1282. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1283. "node_type with incompatible allocator passed to unordered_map::insert()");
  1284. return __table_.template __node_handle_insert_unique<
  1285. node_type, insert_return_type>(_VSTD::move(__nh));
  1286. }
  1287. _LIBCPP_INLINE_VISIBILITY
  1288. iterator insert(const_iterator __hint, node_type&& __nh)
  1289. {
  1290. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1291. "node_type with incompatible allocator passed to unordered_map::insert()");
  1292. return __table_.template __node_handle_insert_unique<node_type>(
  1293. __hint.__i_, _VSTD::move(__nh));
  1294. }
  1295. _LIBCPP_INLINE_VISIBILITY
  1296. node_type extract(key_type const& __key)
  1297. {
  1298. return __table_.template __node_handle_extract<node_type>(__key);
  1299. }
  1300. _LIBCPP_INLINE_VISIBILITY
  1301. node_type extract(const_iterator __it)
  1302. {
  1303. return __table_.template __node_handle_extract<node_type>(
  1304. __it.__i_);
  1305. }
  1306. template <class _H2, class _P2>
  1307. _LIBCPP_INLINE_VISIBILITY
  1308. void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
  1309. {
  1310. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(),
  1311. "merging container with incompatible allocator");
  1312. return __table_.__node_handle_merge_unique(__source.__table_);
  1313. }
  1314. template <class _H2, class _P2>
  1315. _LIBCPP_INLINE_VISIBILITY
  1316. void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
  1317. {
  1318. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(),
  1319. "merging container with incompatible allocator");
  1320. return __table_.__node_handle_merge_unique(__source.__table_);
  1321. }
  1322. template <class _H2, class _P2>
  1323. _LIBCPP_INLINE_VISIBILITY
  1324. void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
  1325. {
  1326. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(),
  1327. "merging container with incompatible allocator");
  1328. return __table_.__node_handle_merge_unique(__source.__table_);
  1329. }
  1330. template <class _H2, class _P2>
  1331. _LIBCPP_INLINE_VISIBILITY
  1332. void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
  1333. {
  1334. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(),
  1335. "merging container with incompatible allocator");
  1336. return __table_.__node_handle_merge_unique(__source.__table_);
  1337. }
  1338. #endif
  1339. _LIBCPP_INLINE_VISIBILITY
  1340. void swap(unordered_map& __u)
  1341. _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
  1342. { __table_.swap(__u.__table_);}
  1343. _LIBCPP_INLINE_VISIBILITY
  1344. hasher hash_function() const
  1345. {return __table_.hash_function().hash_function();}
  1346. _LIBCPP_INLINE_VISIBILITY
  1347. key_equal key_eq() const
  1348. {return __table_.key_eq().key_eq();}
  1349. _LIBCPP_INLINE_VISIBILITY
  1350. iterator find(const key_type& __k) {return __table_.find(__k);}
  1351. _LIBCPP_INLINE_VISIBILITY
  1352. const_iterator find(const key_type& __k) const {return __table_.find(__k);}
  1353. #if _LIBCPP_STD_VER >= 20
  1354. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1355. _LIBCPP_INLINE_VISIBILITY
  1356. iterator find(const _K2& __k) {return __table_.find(__k);}
  1357. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1358. _LIBCPP_INLINE_VISIBILITY
  1359. const_iterator find(const _K2& __k) const {return __table_.find(__k);}
  1360. #endif // _LIBCPP_STD_VER >= 20
  1361. _LIBCPP_INLINE_VISIBILITY
  1362. size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
  1363. #if _LIBCPP_STD_VER >= 20
  1364. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1365. _LIBCPP_INLINE_VISIBILITY
  1366. size_type count(const _K2& __k) const {return __table_.__count_unique(__k);}
  1367. #endif // _LIBCPP_STD_VER >= 20
  1368. #if _LIBCPP_STD_VER >= 20
  1369. _LIBCPP_INLINE_VISIBILITY
  1370. bool contains(const key_type& __k) const {return find(__k) != end();}
  1371. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1372. _LIBCPP_INLINE_VISIBILITY
  1373. bool contains(const _K2& __k) const {return find(__k) != end();}
  1374. #endif // _LIBCPP_STD_VER >= 20
  1375. _LIBCPP_INLINE_VISIBILITY
  1376. pair<iterator, iterator> equal_range(const key_type& __k)
  1377. {return __table_.__equal_range_unique(__k);}
  1378. _LIBCPP_INLINE_VISIBILITY
  1379. pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
  1380. {return __table_.__equal_range_unique(__k);}
  1381. #if _LIBCPP_STD_VER >= 20
  1382. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1383. _LIBCPP_INLINE_VISIBILITY
  1384. pair<iterator, iterator> equal_range(const _K2& __k)
  1385. {return __table_.__equal_range_unique(__k);}
  1386. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1387. _LIBCPP_INLINE_VISIBILITY
  1388. pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
  1389. {return __table_.__equal_range_unique(__k);}
  1390. #endif // _LIBCPP_STD_VER >= 20
  1391. _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k);
  1392. #ifndef _LIBCPP_CXX03_LANG
  1393. _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k);
  1394. #endif
  1395. _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __k);
  1396. _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __k) const;
  1397. _LIBCPP_INLINE_VISIBILITY
  1398. size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
  1399. _LIBCPP_INLINE_VISIBILITY
  1400. size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
  1401. _LIBCPP_INLINE_VISIBILITY
  1402. size_type bucket_size(size_type __n) const
  1403. {return __table_.bucket_size(__n);}
  1404. _LIBCPP_INLINE_VISIBILITY
  1405. size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
  1406. _LIBCPP_INLINE_VISIBILITY
  1407. local_iterator begin(size_type __n) {return __table_.begin(__n);}
  1408. _LIBCPP_INLINE_VISIBILITY
  1409. local_iterator end(size_type __n) {return __table_.end(__n);}
  1410. _LIBCPP_INLINE_VISIBILITY
  1411. const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
  1412. _LIBCPP_INLINE_VISIBILITY
  1413. const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
  1414. _LIBCPP_INLINE_VISIBILITY
  1415. const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
  1416. _LIBCPP_INLINE_VISIBILITY
  1417. const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
  1418. _LIBCPP_INLINE_VISIBILITY
  1419. float load_factor() const _NOEXCEPT {return __table_.load_factor();}
  1420. _LIBCPP_INLINE_VISIBILITY
  1421. float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
  1422. _LIBCPP_INLINE_VISIBILITY
  1423. void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
  1424. _LIBCPP_INLINE_VISIBILITY
  1425. void rehash(size_type __n) {__table_.__rehash_unique(__n);}
  1426. _LIBCPP_INLINE_VISIBILITY
  1427. void reserve(size_type __n) {__table_.__reserve_unique(__n);}
  1428. private:
  1429. #ifdef _LIBCPP_CXX03_LANG
  1430. _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node_with_key(const key_type& __k);
  1431. #endif
  1432. };
  1433. #if _LIBCPP_STD_VER >= 17
  1434. template<class _InputIterator,
  1435. class _Hash = hash<__iter_key_type<_InputIterator>>,
  1436. class _Pred = equal_to<__iter_key_type<_InputIterator>>,
  1437. class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
  1438. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1439. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1440. class = enable_if_t<!is_integral<_Hash>::value>,
  1441. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1442. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1443. unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
  1444. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  1445. -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
  1446. #if _LIBCPP_STD_VER >= 23
  1447. template <ranges::input_range _Range,
  1448. class _Hash = hash<__range_key_type<_Range>>,
  1449. class _Pred = equal_to<__range_key_type<_Range>>,
  1450. class _Allocator = allocator<__range_to_alloc_type<_Range>>,
  1451. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1452. class = enable_if_t<!is_integral<_Hash>::value>,
  1453. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1454. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1455. unordered_map(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type = 0,
  1456. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  1457. -> unordered_map<__range_key_type<_Range>, __range_mapped_type<_Range>, _Hash, _Pred, _Allocator>; // C++23
  1458. #endif
  1459. template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
  1460. class _Pred = equal_to<remove_const_t<_Key>>,
  1461. class _Allocator = allocator<pair<const _Key, _Tp>>,
  1462. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1463. class = enable_if_t<!is_integral<_Hash>::value>,
  1464. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1465. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1466. unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
  1467. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  1468. -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
  1469. template<class _InputIterator, class _Allocator,
  1470. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1471. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1472. unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1473. -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
  1474. hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
  1475. template<class _InputIterator, class _Allocator,
  1476. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1477. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1478. unordered_map(_InputIterator, _InputIterator, _Allocator)
  1479. -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
  1480. hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
  1481. template<class _InputIterator, class _Hash, class _Allocator,
  1482. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  1483. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1484. class = enable_if_t<!is_integral<_Hash>::value>,
  1485. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1486. unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  1487. -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
  1488. _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
  1489. #if _LIBCPP_STD_VER >= 23
  1490. template <ranges::input_range _Range, class _Allocator,
  1491. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1492. unordered_map(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1493. -> unordered_map<__range_key_type<_Range>, __range_mapped_type<_Range>, hash<__range_key_type<_Range>>,
  1494. equal_to<__range_key_type<_Range>>, _Allocator>;
  1495. template <ranges::input_range _Range, class _Allocator,
  1496. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1497. unordered_map(from_range_t, _Range&&, _Allocator)
  1498. -> unordered_map<__range_key_type<_Range>, __range_mapped_type<_Range>, hash<__range_key_type<_Range>>,
  1499. equal_to<__range_key_type<_Range>>, _Allocator>;
  1500. template <ranges::input_range _Range, class _Hash, class _Allocator,
  1501. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1502. class = enable_if_t<!is_integral<_Hash>::value>,
  1503. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1504. unordered_map(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  1505. -> unordered_map<__range_key_type<_Range>, __range_mapped_type<_Range>, _Hash,
  1506. equal_to<__range_key_type<_Range>>, _Allocator>;
  1507. #endif
  1508. template<class _Key, class _Tp, class _Allocator,
  1509. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1510. unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1511. -> unordered_map<remove_const_t<_Key>, _Tp,
  1512. hash<remove_const_t<_Key>>,
  1513. equal_to<remove_const_t<_Key>>, _Allocator>;
  1514. template<class _Key, class _Tp, class _Allocator,
  1515. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1516. unordered_map(initializer_list<pair<_Key, _Tp>>, _Allocator)
  1517. -> unordered_map<remove_const_t<_Key>, _Tp,
  1518. hash<remove_const_t<_Key>>,
  1519. equal_to<remove_const_t<_Key>>, _Allocator>;
  1520. template<class _Key, class _Tp, class _Hash, class _Allocator,
  1521. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1522. class = enable_if_t<!is_integral<_Hash>::value>,
  1523. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1524. unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  1525. -> unordered_map<remove_const_t<_Key>, _Tp, _Hash,
  1526. equal_to<remove_const_t<_Key>>, _Allocator>;
  1527. #endif
  1528. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1529. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1530. size_type __n, const hasher& __hf, const key_equal& __eql)
  1531. : __table_(__hf, __eql)
  1532. {
  1533. __table_.__rehash_unique(__n);
  1534. }
  1535. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1536. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1537. size_type __n, const hasher& __hf, const key_equal& __eql,
  1538. const allocator_type& __a)
  1539. : __table_(__hf, __eql, typename __table::allocator_type(__a))
  1540. {
  1541. __table_.__rehash_unique(__n);
  1542. }
  1543. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1544. inline
  1545. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1546. const allocator_type& __a)
  1547. : __table_(typename __table::allocator_type(__a))
  1548. {
  1549. }
  1550. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1551. template <class _InputIterator>
  1552. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1553. _InputIterator __first, _InputIterator __last)
  1554. {
  1555. insert(__first, __last);
  1556. }
  1557. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1558. template <class _InputIterator>
  1559. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1560. _InputIterator __first, _InputIterator __last, size_type __n,
  1561. const hasher& __hf, const key_equal& __eql)
  1562. : __table_(__hf, __eql)
  1563. {
  1564. __table_.__rehash_unique(__n);
  1565. insert(__first, __last);
  1566. }
  1567. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1568. template <class _InputIterator>
  1569. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1570. _InputIterator __first, _InputIterator __last, size_type __n,
  1571. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  1572. : __table_(__hf, __eql, typename __table::allocator_type(__a))
  1573. {
  1574. __table_.__rehash_unique(__n);
  1575. insert(__first, __last);
  1576. }
  1577. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1578. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1579. const unordered_map& __u)
  1580. : __table_(__u.__table_)
  1581. {
  1582. __table_.__rehash_unique(__u.bucket_count());
  1583. insert(__u.begin(), __u.end());
  1584. }
  1585. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1586. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1587. const unordered_map& __u, const allocator_type& __a)
  1588. : __table_(__u.__table_, typename __table::allocator_type(__a))
  1589. {
  1590. __table_.__rehash_unique(__u.bucket_count());
  1591. insert(__u.begin(), __u.end());
  1592. }
  1593. #ifndef _LIBCPP_CXX03_LANG
  1594. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1595. inline
  1596. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1597. unordered_map&& __u)
  1598. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
  1599. : __table_(_VSTD::move(__u.__table_))
  1600. {
  1601. }
  1602. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1603. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1604. unordered_map&& __u, const allocator_type& __a)
  1605. : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
  1606. {
  1607. if (__a != __u.get_allocator())
  1608. {
  1609. iterator __i = __u.begin();
  1610. while (__u.size() != 0) {
  1611. __table_.__emplace_unique(
  1612. __u.__table_.remove((__i++).__i_)->__get_value().__move());
  1613. }
  1614. }
  1615. }
  1616. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1617. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1618. initializer_list<value_type> __il)
  1619. {
  1620. insert(__il.begin(), __il.end());
  1621. }
  1622. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1623. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1624. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  1625. const key_equal& __eql)
  1626. : __table_(__hf, __eql)
  1627. {
  1628. __table_.__rehash_unique(__n);
  1629. insert(__il.begin(), __il.end());
  1630. }
  1631. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1632. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
  1633. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  1634. const key_equal& __eql, const allocator_type& __a)
  1635. : __table_(__hf, __eql, typename __table::allocator_type(__a))
  1636. {
  1637. __table_.__rehash_unique(__n);
  1638. insert(__il.begin(), __il.end());
  1639. }
  1640. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1641. inline
  1642. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
  1643. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
  1644. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
  1645. {
  1646. __table_ = _VSTD::move(__u.__table_);
  1647. return *this;
  1648. }
  1649. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1650. inline
  1651. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
  1652. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
  1653. initializer_list<value_type> __il)
  1654. {
  1655. __table_.__assign_unique(__il.begin(), __il.end());
  1656. return *this;
  1657. }
  1658. #endif // _LIBCPP_CXX03_LANG
  1659. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1660. template <class _InputIterator>
  1661. inline
  1662. void
  1663. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
  1664. _InputIterator __last)
  1665. {
  1666. for (; __first != __last; ++__first)
  1667. __table_.__insert_unique(*__first);
  1668. }
  1669. #ifndef _LIBCPP_CXX03_LANG
  1670. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1671. _Tp&
  1672. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
  1673. {
  1674. return __table_.__emplace_unique_key_args(__k,
  1675. piecewise_construct, _VSTD::forward_as_tuple(__k),
  1676. _VSTD::forward_as_tuple()).first->__get_value().second;
  1677. }
  1678. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1679. _Tp&
  1680. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
  1681. {
  1682. return __table_.__emplace_unique_key_args(__k,
  1683. piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
  1684. _VSTD::forward_as_tuple()).first->__get_value().second;
  1685. }
  1686. #else // _LIBCPP_CXX03_LANG
  1687. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1688. typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
  1689. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
  1690. {
  1691. __node_allocator& __na = __table_.__node_alloc();
  1692. __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
  1693. __node_traits::construct(__na, _VSTD::addressof(__h->__get_value().__get_value().first), __k);
  1694. __h.get_deleter().__first_constructed = true;
  1695. __node_traits::construct(__na, _VSTD::addressof(__h->__get_value().__get_value().second));
  1696. __h.get_deleter().__second_constructed = true;
  1697. return __h;
  1698. }
  1699. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1700. _Tp&
  1701. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
  1702. {
  1703. iterator __i = find(__k);
  1704. if (__i != end())
  1705. return __i->second;
  1706. __node_holder __h = __construct_node_with_key(__k);
  1707. pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
  1708. __h.release();
  1709. return __r.first->second;
  1710. }
  1711. #endif // _LIBCPP_CXX03_LANG
  1712. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1713. _Tp&
  1714. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
  1715. {
  1716. iterator __i = find(__k);
  1717. if (__i == end())
  1718. __throw_out_of_range("unordered_map::at: key not found");
  1719. return __i->second;
  1720. }
  1721. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1722. const _Tp&
  1723. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
  1724. {
  1725. const_iterator __i = find(__k);
  1726. if (__i == end())
  1727. __throw_out_of_range("unordered_map::at: key not found");
  1728. return __i->second;
  1729. }
  1730. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1731. inline _LIBCPP_INLINE_VISIBILITY
  1732. void
  1733. swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  1734. unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
  1735. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  1736. {
  1737. __x.swap(__y);
  1738. }
  1739. #if _LIBCPP_STD_VER >= 20
  1740. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
  1741. class _Predicate>
  1742. inline _LIBCPP_INLINE_VISIBILITY
  1743. typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
  1744. erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
  1745. _Predicate __pred) {
  1746. return _VSTD::__libcpp_erase_if_container(__c, __pred);
  1747. }
  1748. #endif
  1749. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1750. _LIBCPP_HIDE_FROM_ABI bool
  1751. operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  1752. const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
  1753. {
  1754. if (__x.size() != __y.size())
  1755. return false;
  1756. typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
  1757. const_iterator;
  1758. for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
  1759. __i != __ex; ++__i)
  1760. {
  1761. const_iterator __j = __y.find(__i->first);
  1762. if (__j == __ey || !(*__i == *__j))
  1763. return false;
  1764. }
  1765. return true;
  1766. }
  1767. #if _LIBCPP_STD_VER <= 17
  1768. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  1769. inline _LIBCPP_INLINE_VISIBILITY
  1770. bool
  1771. operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  1772. const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
  1773. {
  1774. return !(__x == __y);
  1775. }
  1776. #endif
  1777. template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
  1778. class _Alloc = allocator<pair<const _Key, _Tp> > >
  1779. class _LIBCPP_TEMPLATE_VIS unordered_multimap
  1780. {
  1781. public:
  1782. // types
  1783. typedef _Key key_type;
  1784. typedef _Tp mapped_type;
  1785. typedef __type_identity_t<_Hash> hasher;
  1786. typedef __type_identity_t<_Pred> key_equal;
  1787. typedef __type_identity_t<_Alloc> allocator_type;
  1788. typedef pair<const key_type, mapped_type> value_type;
  1789. typedef value_type& reference;
  1790. typedef const value_type& const_reference;
  1791. static_assert((is_same<value_type, typename allocator_type::value_type>::value),
  1792. "Allocator::value_type must be same type as value_type");
  1793. private:
  1794. typedef __hash_value_type<key_type, mapped_type> __value_type;
  1795. typedef __unordered_map_hasher<key_type, __value_type, hasher, key_equal> __hasher;
  1796. typedef __unordered_map_equal<key_type, __value_type, key_equal, hasher> __key_equal;
  1797. typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
  1798. typedef __hash_table<__value_type, __hasher,
  1799. __key_equal, __allocator_type> __table;
  1800. __table __table_;
  1801. typedef typename __table::_NodeTypes _NodeTypes;
  1802. typedef typename __table::__node_traits __node_traits;
  1803. typedef typename __table::__node_allocator __node_allocator;
  1804. typedef typename __table::__node __node;
  1805. typedef __hash_map_node_destructor<__node_allocator> _Dp;
  1806. typedef unique_ptr<__node, _Dp> __node_holder;
  1807. typedef allocator_traits<allocator_type> __alloc_traits;
  1808. static_assert((is_same<typename __node_traits::size_type,
  1809. typename __alloc_traits::size_type>::value),
  1810. "Allocator uses different size_type for different types");
  1811. static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
  1812. "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
  1813. "original allocator");
  1814. public:
  1815. typedef typename __alloc_traits::pointer pointer;
  1816. typedef typename __alloc_traits::const_pointer const_pointer;
  1817. typedef typename __table::size_type size_type;
  1818. typedef typename __table::difference_type difference_type;
  1819. typedef __hash_map_iterator<typename __table::iterator> iterator;
  1820. typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
  1821. typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
  1822. typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
  1823. #if _LIBCPP_STD_VER >= 17
  1824. typedef __map_node_handle<__node, allocator_type> node_type;
  1825. #endif
  1826. template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
  1827. friend class _LIBCPP_TEMPLATE_VIS unordered_map;
  1828. template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
  1829. friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
  1830. _LIBCPP_INLINE_VISIBILITY
  1831. unordered_multimap()
  1832. _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
  1833. {
  1834. }
  1835. explicit _LIBCPP_HIDE_FROM_ABI unordered_multimap(size_type __n, const hasher& __hf = hasher(),
  1836. const key_equal& __eql = key_equal());
  1837. _LIBCPP_HIDE_FROM_ABI unordered_multimap(size_type __n, const hasher& __hf,
  1838. const key_equal& __eql,
  1839. const allocator_type& __a);
  1840. template <class _InputIterator>
  1841. _LIBCPP_HIDE_FROM_ABI unordered_multimap(_InputIterator __first, _InputIterator __last);
  1842. template <class _InputIterator>
  1843. _LIBCPP_HIDE_FROM_ABI unordered_multimap(_InputIterator __first, _InputIterator __last,
  1844. size_type __n, const hasher& __hf = hasher(),
  1845. const key_equal& __eql = key_equal());
  1846. template <class _InputIterator>
  1847. _LIBCPP_HIDE_FROM_ABI unordered_multimap(_InputIterator __first, _InputIterator __last,
  1848. size_type __n, const hasher& __hf,
  1849. const key_equal& __eql,
  1850. const allocator_type& __a);
  1851. #if _LIBCPP_STD_VER >= 23
  1852. template <_ContainerCompatibleRange<value_type> _Range>
  1853. _LIBCPP_HIDE_FROM_ABI
  1854. unordered_multimap(from_range_t, _Range&& __range, size_type __n = /*implementation-defined*/0,
  1855. const hasher& __hf = hasher(), const key_equal& __eql = key_equal(),
  1856. const allocator_type& __a = allocator_type())
  1857. : __table_(__hf, __eql, typename __table::allocator_type(__a)) {
  1858. if (__n > 0) {
  1859. __table_.__rehash_multi(__n);
  1860. }
  1861. insert_range(std::forward<_Range>(__range));
  1862. }
  1863. #endif
  1864. _LIBCPP_INLINE_VISIBILITY
  1865. explicit unordered_multimap(const allocator_type& __a);
  1866. _LIBCPP_HIDE_FROM_ABI unordered_multimap(const unordered_multimap& __u);
  1867. _LIBCPP_HIDE_FROM_ABI unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
  1868. #ifndef _LIBCPP_CXX03_LANG
  1869. _LIBCPP_INLINE_VISIBILITY
  1870. unordered_multimap(unordered_multimap&& __u)
  1871. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
  1872. _LIBCPP_HIDE_FROM_ABI unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
  1873. _LIBCPP_HIDE_FROM_ABI unordered_multimap(initializer_list<value_type> __il);
  1874. _LIBCPP_HIDE_FROM_ABI unordered_multimap(initializer_list<value_type> __il, size_type __n,
  1875. const hasher& __hf = hasher(),
  1876. const key_equal& __eql = key_equal());
  1877. _LIBCPP_HIDE_FROM_ABI unordered_multimap(initializer_list<value_type> __il, size_type __n,
  1878. const hasher& __hf, const key_equal& __eql,
  1879. const allocator_type& __a);
  1880. #endif // _LIBCPP_CXX03_LANG
  1881. #if _LIBCPP_STD_VER >= 14
  1882. _LIBCPP_INLINE_VISIBILITY
  1883. unordered_multimap(size_type __n, const allocator_type& __a)
  1884. : unordered_multimap(__n, hasher(), key_equal(), __a) {}
  1885. _LIBCPP_INLINE_VISIBILITY
  1886. unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
  1887. : unordered_multimap(__n, __hf, key_equal(), __a) {}
  1888. template <class _InputIterator>
  1889. _LIBCPP_INLINE_VISIBILITY
  1890. unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
  1891. : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
  1892. template <class _InputIterator>
  1893. _LIBCPP_INLINE_VISIBILITY
  1894. unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
  1895. const allocator_type& __a)
  1896. : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
  1897. #if _LIBCPP_STD_VER >= 23
  1898. template <_ContainerCompatibleRange<value_type> _Range>
  1899. _LIBCPP_HIDE_FROM_ABI
  1900. unordered_multimap(from_range_t, _Range&& __range, size_type __n, const allocator_type& __a)
  1901. : unordered_multimap(from_range, std::forward<_Range>(__range), __n, hasher(), key_equal(), __a) {}
  1902. template <_ContainerCompatibleRange<value_type> _Range>
  1903. _LIBCPP_HIDE_FROM_ABI
  1904. unordered_multimap(from_range_t, _Range&& __range, size_type __n, const hasher& __hf, const allocator_type& __a)
  1905. : unordered_multimap(from_range, std::forward<_Range>(__range), __n, __hf, key_equal(), __a) {}
  1906. #endif
  1907. _LIBCPP_INLINE_VISIBILITY
  1908. unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
  1909. : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
  1910. _LIBCPP_INLINE_VISIBILITY
  1911. unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  1912. const allocator_type& __a)
  1913. : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
  1914. #endif
  1915. _LIBCPP_INLINE_VISIBILITY
  1916. ~unordered_multimap() {
  1917. static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
  1918. }
  1919. _LIBCPP_INLINE_VISIBILITY
  1920. unordered_multimap& operator=(const unordered_multimap& __u)
  1921. {
  1922. #ifndef _LIBCPP_CXX03_LANG
  1923. __table_ = __u.__table_;
  1924. #else
  1925. if (this != _VSTD::addressof(__u)) {
  1926. __table_.clear();
  1927. __table_.hash_function() = __u.__table_.hash_function();
  1928. __table_.key_eq() = __u.__table_.key_eq();
  1929. __table_.max_load_factor() = __u.__table_.max_load_factor();
  1930. __table_.__copy_assign_alloc(__u.__table_);
  1931. insert(__u.begin(), __u.end());
  1932. }
  1933. #endif
  1934. return *this;
  1935. }
  1936. #ifndef _LIBCPP_CXX03_LANG
  1937. _LIBCPP_INLINE_VISIBILITY
  1938. unordered_multimap& operator=(unordered_multimap&& __u)
  1939. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
  1940. _LIBCPP_INLINE_VISIBILITY
  1941. unordered_multimap& operator=(initializer_list<value_type> __il);
  1942. #endif // _LIBCPP_CXX03_LANG
  1943. _LIBCPP_INLINE_VISIBILITY
  1944. allocator_type get_allocator() const _NOEXCEPT
  1945. {return allocator_type(__table_.__node_alloc());}
  1946. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  1947. bool empty() const _NOEXCEPT {return __table_.size() == 0;}
  1948. _LIBCPP_INLINE_VISIBILITY
  1949. size_type size() const _NOEXCEPT {return __table_.size();}
  1950. _LIBCPP_INLINE_VISIBILITY
  1951. size_type max_size() const _NOEXCEPT {return __table_.max_size();}
  1952. _LIBCPP_INLINE_VISIBILITY
  1953. iterator begin() _NOEXCEPT {return __table_.begin();}
  1954. _LIBCPP_INLINE_VISIBILITY
  1955. iterator end() _NOEXCEPT {return __table_.end();}
  1956. _LIBCPP_INLINE_VISIBILITY
  1957. const_iterator begin() const _NOEXCEPT {return __table_.begin();}
  1958. _LIBCPP_INLINE_VISIBILITY
  1959. const_iterator end() const _NOEXCEPT {return __table_.end();}
  1960. _LIBCPP_INLINE_VISIBILITY
  1961. const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
  1962. _LIBCPP_INLINE_VISIBILITY
  1963. const_iterator cend() const _NOEXCEPT {return __table_.end();}
  1964. _LIBCPP_INLINE_VISIBILITY
  1965. iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
  1966. _LIBCPP_INLINE_VISIBILITY
  1967. iterator insert(const_iterator __p, const value_type& __x)
  1968. {return __table_.__insert_multi(__p.__i_, __x);}
  1969. template <class _InputIterator>
  1970. _LIBCPP_INLINE_VISIBILITY
  1971. void insert(_InputIterator __first, _InputIterator __last);
  1972. #if _LIBCPP_STD_VER >= 23
  1973. template <_ContainerCompatibleRange<value_type> _Range>
  1974. _LIBCPP_HIDE_FROM_ABI
  1975. void insert_range(_Range&& __range) {
  1976. for (auto&& __element : __range) {
  1977. __table_.__insert_multi(std::forward<decltype(__element)>(__element));
  1978. }
  1979. }
  1980. #endif
  1981. #ifndef _LIBCPP_CXX03_LANG
  1982. _LIBCPP_INLINE_VISIBILITY
  1983. void insert(initializer_list<value_type> __il)
  1984. {insert(__il.begin(), __il.end());}
  1985. _LIBCPP_INLINE_VISIBILITY
  1986. iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
  1987. _LIBCPP_INLINE_VISIBILITY
  1988. iterator insert(const_iterator __p, value_type&& __x)
  1989. {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
  1990. template <class _Pp,
  1991. class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
  1992. _LIBCPP_INLINE_VISIBILITY
  1993. iterator insert(_Pp&& __x)
  1994. {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
  1995. template <class _Pp,
  1996. class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
  1997. _LIBCPP_INLINE_VISIBILITY
  1998. iterator insert(const_iterator __p, _Pp&& __x)
  1999. {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
  2000. template <class... _Args>
  2001. _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
  2002. return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
  2003. }
  2004. template <class... _Args>
  2005. _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
  2006. return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
  2007. }
  2008. #endif // _LIBCPP_CXX03_LANG
  2009. _LIBCPP_INLINE_VISIBILITY
  2010. iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
  2011. _LIBCPP_INLINE_VISIBILITY
  2012. iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
  2013. _LIBCPP_INLINE_VISIBILITY
  2014. size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
  2015. _LIBCPP_INLINE_VISIBILITY
  2016. iterator erase(const_iterator __first, const_iterator __last)
  2017. {return __table_.erase(__first.__i_, __last.__i_);}
  2018. _LIBCPP_INLINE_VISIBILITY
  2019. void clear() _NOEXCEPT {__table_.clear();}
  2020. #if _LIBCPP_STD_VER >= 17
  2021. _LIBCPP_INLINE_VISIBILITY
  2022. iterator insert(node_type&& __nh)
  2023. {
  2024. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  2025. "node_type with incompatible allocator passed to unordered_multimap::insert()");
  2026. return __table_.template __node_handle_insert_multi<node_type>(
  2027. _VSTD::move(__nh));
  2028. }
  2029. _LIBCPP_INLINE_VISIBILITY
  2030. iterator insert(const_iterator __hint, node_type&& __nh)
  2031. {
  2032. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
  2033. "node_type with incompatible allocator passed to unordered_multimap::insert()");
  2034. return __table_.template __node_handle_insert_multi<node_type>(
  2035. __hint.__i_, _VSTD::move(__nh));
  2036. }
  2037. _LIBCPP_INLINE_VISIBILITY
  2038. node_type extract(key_type const& __key)
  2039. {
  2040. return __table_.template __node_handle_extract<node_type>(__key);
  2041. }
  2042. _LIBCPP_INLINE_VISIBILITY
  2043. node_type extract(const_iterator __it)
  2044. {
  2045. return __table_.template __node_handle_extract<node_type>(
  2046. __it.__i_);
  2047. }
  2048. template <class _H2, class _P2>
  2049. _LIBCPP_INLINE_VISIBILITY
  2050. void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
  2051. {
  2052. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(),
  2053. "merging container with incompatible allocator");
  2054. return __table_.__node_handle_merge_multi(__source.__table_);
  2055. }
  2056. template <class _H2, class _P2>
  2057. _LIBCPP_INLINE_VISIBILITY
  2058. void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
  2059. {
  2060. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(),
  2061. "merging container with incompatible allocator");
  2062. return __table_.__node_handle_merge_multi(__source.__table_);
  2063. }
  2064. template <class _H2, class _P2>
  2065. _LIBCPP_INLINE_VISIBILITY
  2066. void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
  2067. {
  2068. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(),
  2069. "merging container with incompatible allocator");
  2070. return __table_.__node_handle_merge_multi(__source.__table_);
  2071. }
  2072. template <class _H2, class _P2>
  2073. _LIBCPP_INLINE_VISIBILITY
  2074. void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
  2075. {
  2076. _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__source.get_allocator() == get_allocator(),
  2077. "merging container with incompatible allocator");
  2078. return __table_.__node_handle_merge_multi(__source.__table_);
  2079. }
  2080. #endif
  2081. _LIBCPP_INLINE_VISIBILITY
  2082. void swap(unordered_multimap& __u)
  2083. _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
  2084. {__table_.swap(__u.__table_);}
  2085. _LIBCPP_INLINE_VISIBILITY
  2086. hasher hash_function() const
  2087. {return __table_.hash_function().hash_function();}
  2088. _LIBCPP_INLINE_VISIBILITY
  2089. key_equal key_eq() const
  2090. {return __table_.key_eq().key_eq();}
  2091. _LIBCPP_INLINE_VISIBILITY
  2092. iterator find(const key_type& __k) {return __table_.find(__k);}
  2093. _LIBCPP_INLINE_VISIBILITY
  2094. const_iterator find(const key_type& __k) const {return __table_.find(__k);}
  2095. #if _LIBCPP_STD_VER >= 20
  2096. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  2097. _LIBCPP_INLINE_VISIBILITY
  2098. iterator find(const _K2& __k) {return __table_.find(__k);}
  2099. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  2100. _LIBCPP_INLINE_VISIBILITY
  2101. const_iterator find(const _K2& __k) const {return __table_.find(__k);}
  2102. #endif // _LIBCPP_STD_VER >= 20
  2103. _LIBCPP_INLINE_VISIBILITY
  2104. size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
  2105. #if _LIBCPP_STD_VER >= 20
  2106. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  2107. _LIBCPP_INLINE_VISIBILITY
  2108. size_type count(const _K2& __k) const {return __table_.__count_multi(__k);}
  2109. #endif // _LIBCPP_STD_VER >= 20
  2110. #if _LIBCPP_STD_VER >= 20
  2111. _LIBCPP_INLINE_VISIBILITY
  2112. bool contains(const key_type& __k) const {return find(__k) != end();}
  2113. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  2114. _LIBCPP_INLINE_VISIBILITY
  2115. bool contains(const _K2& __k) const {return find(__k) != end();}
  2116. #endif // _LIBCPP_STD_VER >= 20
  2117. _LIBCPP_INLINE_VISIBILITY
  2118. pair<iterator, iterator> equal_range(const key_type& __k)
  2119. {return __table_.__equal_range_multi(__k);}
  2120. _LIBCPP_INLINE_VISIBILITY
  2121. pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
  2122. {return __table_.__equal_range_multi(__k);}
  2123. #if _LIBCPP_STD_VER >= 20
  2124. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  2125. _LIBCPP_INLINE_VISIBILITY
  2126. pair<iterator, iterator> equal_range(const _K2& __k)
  2127. {return __table_.__equal_range_multi(__k);}
  2128. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  2129. _LIBCPP_INLINE_VISIBILITY
  2130. pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
  2131. {return __table_.__equal_range_multi(__k);}
  2132. #endif // _LIBCPP_STD_VER >= 20
  2133. _LIBCPP_INLINE_VISIBILITY
  2134. size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
  2135. _LIBCPP_INLINE_VISIBILITY
  2136. size_type max_bucket_count() const _NOEXCEPT
  2137. {return __table_.max_bucket_count();}
  2138. _LIBCPP_INLINE_VISIBILITY
  2139. size_type bucket_size(size_type __n) const
  2140. {return __table_.bucket_size(__n);}
  2141. _LIBCPP_INLINE_VISIBILITY
  2142. size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
  2143. _LIBCPP_INLINE_VISIBILITY
  2144. local_iterator begin(size_type __n) {return __table_.begin(__n);}
  2145. _LIBCPP_INLINE_VISIBILITY
  2146. local_iterator end(size_type __n) {return __table_.end(__n);}
  2147. _LIBCPP_INLINE_VISIBILITY
  2148. const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
  2149. _LIBCPP_INLINE_VISIBILITY
  2150. const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
  2151. _LIBCPP_INLINE_VISIBILITY
  2152. const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
  2153. _LIBCPP_INLINE_VISIBILITY
  2154. const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
  2155. _LIBCPP_INLINE_VISIBILITY
  2156. float load_factor() const _NOEXCEPT {return __table_.load_factor();}
  2157. _LIBCPP_INLINE_VISIBILITY
  2158. float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
  2159. _LIBCPP_INLINE_VISIBILITY
  2160. void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
  2161. _LIBCPP_INLINE_VISIBILITY
  2162. void rehash(size_type __n) {__table_.__rehash_multi(__n);}
  2163. _LIBCPP_INLINE_VISIBILITY
  2164. void reserve(size_type __n) {__table_.__reserve_multi(__n);}
  2165. };
  2166. #if _LIBCPP_STD_VER >= 17
  2167. template<class _InputIterator,
  2168. class _Hash = hash<__iter_key_type<_InputIterator>>,
  2169. class _Pred = equal_to<__iter_key_type<_InputIterator>>,
  2170. class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
  2171. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  2172. class = enable_if_t<!__is_allocator<_Hash>::value>,
  2173. class = enable_if_t<!is_integral<_Hash>::value>,
  2174. class = enable_if_t<!__is_allocator<_Pred>::value>,
  2175. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2176. unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
  2177. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  2178. -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
  2179. #if _LIBCPP_STD_VER >= 23
  2180. template <ranges::input_range _Range,
  2181. class _Hash = hash<__range_key_type<_Range>>,
  2182. class _Pred = equal_to<__range_key_type<_Range>>,
  2183. class _Allocator = allocator<__range_to_alloc_type<_Range>>,
  2184. class = enable_if_t<!__is_allocator<_Hash>::value>,
  2185. class = enable_if_t<!is_integral<_Hash>::value>,
  2186. class = enable_if_t<!__is_allocator<_Pred>::value>,
  2187. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2188. unordered_multimap(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type = 0,
  2189. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  2190. -> unordered_multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, _Hash, _Pred, _Allocator>;
  2191. #endif
  2192. template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
  2193. class _Pred = equal_to<remove_const_t<_Key>>,
  2194. class _Allocator = allocator<pair<const _Key, _Tp>>,
  2195. class = enable_if_t<!__is_allocator<_Hash>::value>,
  2196. class = enable_if_t<!is_integral<_Hash>::value>,
  2197. class = enable_if_t<!__is_allocator<_Pred>::value>,
  2198. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2199. unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
  2200. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  2201. -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
  2202. template<class _InputIterator, class _Allocator,
  2203. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  2204. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2205. unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
  2206. -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
  2207. hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
  2208. template<class _InputIterator, class _Allocator,
  2209. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  2210. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2211. unordered_multimap(_InputIterator, _InputIterator, _Allocator)
  2212. -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
  2213. hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
  2214. template<class _InputIterator, class _Hash, class _Allocator,
  2215. class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
  2216. class = enable_if_t<!__is_allocator<_Hash>::value>,
  2217. class = enable_if_t<!is_integral<_Hash>::value>,
  2218. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2219. unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  2220. -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
  2221. _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
  2222. #if _LIBCPP_STD_VER >= 23
  2223. template <ranges::input_range _Range, class _Allocator,
  2224. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2225. unordered_multimap(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Allocator)
  2226. -> unordered_multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, hash<__range_key_type<_Range>>,
  2227. equal_to<__range_key_type<_Range>>, _Allocator>;
  2228. template <ranges::input_range _Range, class _Allocator,
  2229. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2230. unordered_multimap(from_range_t, _Range&&, _Allocator)
  2231. -> unordered_multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, hash<__range_key_type<_Range>>,
  2232. equal_to<__range_key_type<_Range>>, _Allocator>;
  2233. template <ranges::input_range _Range, class _Hash, class _Allocator,
  2234. class = enable_if_t<!__is_allocator<_Hash>::value>,
  2235. class = enable_if_t<!is_integral<_Hash>::value>,
  2236. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2237. unordered_multimap(from_range_t, _Range&&, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  2238. -> unordered_multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, _Hash,
  2239. equal_to<__range_key_type<_Range>>, _Allocator>;
  2240. #endif
  2241. template<class _Key, class _Tp, class _Allocator,
  2242. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2243. unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
  2244. -> unordered_multimap<remove_const_t<_Key>, _Tp,
  2245. hash<remove_const_t<_Key>>,
  2246. equal_to<remove_const_t<_Key>>, _Allocator>;
  2247. template<class _Key, class _Tp, class _Allocator,
  2248. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2249. unordered_multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
  2250. -> unordered_multimap<remove_const_t<_Key>, _Tp,
  2251. hash<remove_const_t<_Key>>,
  2252. equal_to<remove_const_t<_Key>>, _Allocator>;
  2253. template<class _Key, class _Tp, class _Hash, class _Allocator,
  2254. class = enable_if_t<!__is_allocator<_Hash>::value>,
  2255. class = enable_if_t<!is_integral<_Hash>::value>,
  2256. class = enable_if_t<__is_allocator<_Allocator>::value>>
  2257. unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  2258. -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash,
  2259. equal_to<remove_const_t<_Key>>, _Allocator>;
  2260. #endif
  2261. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2262. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2263. size_type __n, const hasher& __hf, const key_equal& __eql)
  2264. : __table_(__hf, __eql)
  2265. {
  2266. __table_.__rehash_multi(__n);
  2267. }
  2268. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2269. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2270. size_type __n, const hasher& __hf, const key_equal& __eql,
  2271. const allocator_type& __a)
  2272. : __table_(__hf, __eql, typename __table::allocator_type(__a))
  2273. {
  2274. __table_.__rehash_multi(__n);
  2275. }
  2276. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2277. template <class _InputIterator>
  2278. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2279. _InputIterator __first, _InputIterator __last)
  2280. {
  2281. insert(__first, __last);
  2282. }
  2283. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2284. template <class _InputIterator>
  2285. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2286. _InputIterator __first, _InputIterator __last, size_type __n,
  2287. const hasher& __hf, const key_equal& __eql)
  2288. : __table_(__hf, __eql)
  2289. {
  2290. __table_.__rehash_multi(__n);
  2291. insert(__first, __last);
  2292. }
  2293. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2294. template <class _InputIterator>
  2295. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2296. _InputIterator __first, _InputIterator __last, size_type __n,
  2297. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  2298. : __table_(__hf, __eql, typename __table::allocator_type(__a))
  2299. {
  2300. __table_.__rehash_multi(__n);
  2301. insert(__first, __last);
  2302. }
  2303. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2304. inline
  2305. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2306. const allocator_type& __a)
  2307. : __table_(typename __table::allocator_type(__a))
  2308. {
  2309. }
  2310. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2311. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2312. const unordered_multimap& __u)
  2313. : __table_(__u.__table_)
  2314. {
  2315. __table_.__rehash_multi(__u.bucket_count());
  2316. insert(__u.begin(), __u.end());
  2317. }
  2318. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2319. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2320. const unordered_multimap& __u, const allocator_type& __a)
  2321. : __table_(__u.__table_, typename __table::allocator_type(__a))
  2322. {
  2323. __table_.__rehash_multi(__u.bucket_count());
  2324. insert(__u.begin(), __u.end());
  2325. }
  2326. #ifndef _LIBCPP_CXX03_LANG
  2327. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2328. inline
  2329. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2330. unordered_multimap&& __u)
  2331. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
  2332. : __table_(_VSTD::move(__u.__table_))
  2333. {
  2334. }
  2335. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2336. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2337. unordered_multimap&& __u, const allocator_type& __a)
  2338. : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
  2339. {
  2340. if (__a != __u.get_allocator())
  2341. {
  2342. iterator __i = __u.begin();
  2343. while (__u.size() != 0)
  2344. {
  2345. __table_.__insert_multi(
  2346. __u.__table_.remove((__i++).__i_)->__get_value().__move());
  2347. }
  2348. }
  2349. }
  2350. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2351. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2352. initializer_list<value_type> __il)
  2353. {
  2354. insert(__il.begin(), __il.end());
  2355. }
  2356. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2357. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2358. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  2359. const key_equal& __eql)
  2360. : __table_(__hf, __eql)
  2361. {
  2362. __table_.__rehash_multi(__n);
  2363. insert(__il.begin(), __il.end());
  2364. }
  2365. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2366. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
  2367. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  2368. const key_equal& __eql, const allocator_type& __a)
  2369. : __table_(__hf, __eql, typename __table::allocator_type(__a))
  2370. {
  2371. __table_.__rehash_multi(__n);
  2372. insert(__il.begin(), __il.end());
  2373. }
  2374. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2375. inline
  2376. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
  2377. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
  2378. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
  2379. {
  2380. __table_ = _VSTD::move(__u.__table_);
  2381. return *this;
  2382. }
  2383. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2384. inline
  2385. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
  2386. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
  2387. initializer_list<value_type> __il)
  2388. {
  2389. __table_.__assign_multi(__il.begin(), __il.end());
  2390. return *this;
  2391. }
  2392. #endif // _LIBCPP_CXX03_LANG
  2393. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2394. template <class _InputIterator>
  2395. inline
  2396. void
  2397. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
  2398. _InputIterator __last)
  2399. {
  2400. for (; __first != __last; ++__first)
  2401. __table_.__insert_multi(*__first);
  2402. }
  2403. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2404. inline _LIBCPP_INLINE_VISIBILITY
  2405. void
  2406. swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  2407. unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
  2408. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  2409. {
  2410. __x.swap(__y);
  2411. }
  2412. #if _LIBCPP_STD_VER >= 20
  2413. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
  2414. class _Predicate>
  2415. inline _LIBCPP_INLINE_VISIBILITY
  2416. typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
  2417. erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
  2418. _Predicate __pred) {
  2419. return _VSTD::__libcpp_erase_if_container(__c, __pred);
  2420. }
  2421. #endif
  2422. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2423. _LIBCPP_HIDE_FROM_ABI bool
  2424. operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  2425. const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
  2426. {
  2427. if (__x.size() != __y.size())
  2428. return false;
  2429. typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
  2430. const_iterator;
  2431. typedef pair<const_iterator, const_iterator> _EqRng;
  2432. for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
  2433. {
  2434. _EqRng __xeq = __x.equal_range(__i->first);
  2435. _EqRng __yeq = __y.equal_range(__i->first);
  2436. if (_VSTD::distance(__xeq.first, __xeq.second) !=
  2437. _VSTD::distance(__yeq.first, __yeq.second) ||
  2438. !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
  2439. return false;
  2440. __i = __xeq.second;
  2441. }
  2442. return true;
  2443. }
  2444. #if _LIBCPP_STD_VER <= 17
  2445. template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
  2446. inline _LIBCPP_INLINE_VISIBILITY
  2447. bool
  2448. operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
  2449. const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
  2450. {
  2451. return !(__x == __y);
  2452. }
  2453. #endif
  2454. _LIBCPP_END_NAMESPACE_STD
  2455. #if _LIBCPP_STD_VER >= 17
  2456. _LIBCPP_BEGIN_NAMESPACE_STD
  2457. namespace pmr {
  2458. template <class _KeyT, class _ValueT, class _HashT = std::hash<_KeyT>, class _PredT = std::equal_to<_KeyT>>
  2459. using unordered_map _LIBCPP_AVAILABILITY_PMR =
  2460. std::unordered_map<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
  2461. template <class _KeyT, class _ValueT, class _HashT = std::hash<_KeyT>, class _PredT = std::equal_to<_KeyT>>
  2462. using unordered_multimap _LIBCPP_AVAILABILITY_PMR =
  2463. std::unordered_multimap<_KeyT, _ValueT, _HashT, _PredT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
  2464. } // namespace pmr
  2465. _LIBCPP_END_NAMESPACE_STD
  2466. #endif
  2467. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  2468. # include <algorithm>
  2469. # include <bit>
  2470. # include <concepts>
  2471. # include <cstdlib>
  2472. # include <iterator>
  2473. # include <type_traits>
  2474. #endif
  2475. #endif // _LIBCPP_UNORDERED_MAP