unordered_map 79 KB

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