unordered_map 97 KB

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