unordered_map 109 KB

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