unordered_map 110 KB

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