unordered_set 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807
  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_SET
  10. #define _LIBCPP_UNORDERED_SET
  11. /*
  12. unordered_set synopsis
  13. #include <initializer_list>
  14. namespace std
  15. {
  16. template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
  17. class Alloc = allocator<Value>>
  18. class unordered_set
  19. {
  20. public:
  21. // types
  22. typedef Value key_type;
  23. typedef key_type value_type;
  24. typedef Hash hasher;
  25. typedef Pred key_equal;
  26. typedef Alloc allocator_type;
  27. typedef value_type& reference;
  28. typedef const value_type& const_reference;
  29. typedef typename allocator_traits<allocator_type>::pointer pointer;
  30. typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
  31. typedef typename allocator_traits<allocator_type>::size_type size_type;
  32. typedef typename allocator_traits<allocator_type>::difference_type difference_type;
  33. typedef /unspecified/ iterator;
  34. typedef /unspecified/ const_iterator;
  35. typedef /unspecified/ local_iterator;
  36. typedef /unspecified/ const_local_iterator;
  37. typedef unspecified node_type unspecified; // C++17
  38. typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
  39. unordered_set()
  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_set(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_set(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_set(const allocator_type&);
  53. unordered_set(const unordered_set&);
  54. unordered_set(const unordered_set&, const Allocator&);
  55. unordered_set(unordered_set&&)
  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_set(unordered_set&&, const Allocator&);
  61. unordered_set(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_set(size_type n, const allocator_type& a); // C++14
  65. unordered_set(size_type n, const hasher& hf, const allocator_type& a); // C++14
  66. template <class InputIterator>
  67. unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
  68. template <class InputIterator>
  69. unordered_set(InputIterator f, InputIterator l, size_type n,
  70. const hasher& hf, const allocator_type& a); // C++14
  71. unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
  72. unordered_set(initializer_list<value_type> il, size_type n,
  73. const hasher& hf, const allocator_type& a); // C++14
  74. ~unordered_set();
  75. unordered_set& operator=(const unordered_set&);
  76. unordered_set& operator=(unordered_set&&)
  77. noexcept(
  78. allocator_type::propagate_on_container_move_assignment::value &&
  79. is_nothrow_move_assignable<allocator_type>::value &&
  80. is_nothrow_move_assignable<hasher>::value &&
  81. is_nothrow_move_assignable<key_equal>::value);
  82. unordered_set& operator=(initializer_list<value_type>);
  83. allocator_type get_allocator() const noexcept;
  84. bool empty() const noexcept;
  85. size_type size() const noexcept;
  86. size_type max_size() const noexcept;
  87. iterator begin() noexcept;
  88. iterator end() noexcept;
  89. const_iterator begin() const noexcept;
  90. const_iterator end() const noexcept;
  91. const_iterator cbegin() const noexcept;
  92. const_iterator cend() const noexcept;
  93. template <class... Args>
  94. pair<iterator, bool> emplace(Args&&... args);
  95. template <class... Args>
  96. iterator emplace_hint(const_iterator position, Args&&... args);
  97. pair<iterator, bool> insert(const value_type& obj);
  98. pair<iterator, bool> insert(value_type&& obj);
  99. iterator insert(const_iterator hint, const value_type& obj);
  100. iterator insert(const_iterator hint, value_type&& obj);
  101. template <class InputIterator>
  102. void insert(InputIterator first, InputIterator last);
  103. void insert(initializer_list<value_type>);
  104. node_type extract(const_iterator position); // C++17
  105. node_type extract(const key_type& x); // C++17
  106. insert_return_type insert(node_type&& nh); // C++17
  107. iterator insert(const_iterator hint, node_type&& nh); // C++17
  108. iterator erase(const_iterator position);
  109. iterator erase(iterator position); // C++14
  110. size_type erase(const key_type& k);
  111. iterator erase(const_iterator first, const_iterator last);
  112. void clear() noexcept;
  113. template<class H2, class P2>
  114. void merge(unordered_set<Key, H2, P2, Allocator>& source); // C++17
  115. template<class H2, class P2>
  116. void merge(unordered_set<Key, H2, P2, Allocator>&& source); // C++17
  117. template<class H2, class P2>
  118. void merge(unordered_multiset<Key, H2, P2, Allocator>& source); // C++17
  119. template<class H2, class P2>
  120. void merge(unordered_multiset<Key, H2, P2, Allocator>&& source); // C++17
  121. void swap(unordered_set&)
  122. noexcept(allocator_traits<Allocator>::is_always_equal::value &&
  123. noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
  124. noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
  125. hasher hash_function() const;
  126. key_equal key_eq() const;
  127. iterator find(const key_type& k);
  128. const_iterator find(const key_type& k) const;
  129. template<typename K>
  130. iterator find(const K& x); // C++20
  131. template<typename K>
  132. const_iterator find(const K& x) const; // C++20
  133. size_type count(const key_type& k) const;
  134. template<typename K>
  135. size_type count(const K& k) const; // C++20
  136. bool contains(const key_type& k) const; // C++20
  137. template<typename K>
  138. bool contains(const K& k) const; // C++20
  139. pair<iterator, iterator> equal_range(const key_type& k);
  140. pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
  141. template<typename K>
  142. pair<iterator, iterator> equal_range(const K& k); // C++20
  143. template<typename K>
  144. pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
  145. size_type bucket_count() const noexcept;
  146. size_type max_bucket_count() const noexcept;
  147. size_type bucket_size(size_type n) const;
  148. size_type bucket(const key_type& k) const;
  149. local_iterator begin(size_type n);
  150. local_iterator end(size_type n);
  151. const_local_iterator begin(size_type n) const;
  152. const_local_iterator end(size_type n) const;
  153. const_local_iterator cbegin(size_type n) const;
  154. const_local_iterator cend(size_type n) const;
  155. float load_factor() const noexcept;
  156. float max_load_factor() const noexcept;
  157. void max_load_factor(float z);
  158. void rehash(size_type n);
  159. void reserve(size_type n);
  160. };
  161. template<class InputIterator,
  162. class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
  163. class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
  164. class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
  165. unordered_set(InputIterator, InputIterator, typename see below::size_type = see below,
  166. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  167. -> unordered_set<typename iterator_traits<InputIterator>::value_type,
  168. Hash, Pred, Allocator>; // C++17
  169. template<class T, class Hash = hash<T>,
  170. class Pred = equal_to<T>, class Allocator = allocator<T>>
  171. unordered_set(initializer_list<T>, typename see below::size_type = see below,
  172. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  173. -> unordered_set<T, Hash, Pred, Allocator>; // C++17
  174. template<class InputIterator, class Allocator>
  175. unordered_set(InputIterator, InputIterator, typename see below::size_type, Allocator)
  176. -> unordered_set<typename iterator_traits<InputIterator>::value_type,
  177. hash<typename iterator_traits<InputIterator>::value_type>,
  178. equal_to<typename iterator_traits<InputIterator>::value_type>,
  179. Allocator>; // C++17
  180. template<class InputIterator, class Hash, class Allocator>
  181. unordered_set(InputIterator, InputIterator, typename see below::size_type,
  182. Hash, Allocator)
  183. -> unordered_set<typename iterator_traits<InputIterator>::value_type, Hash,
  184. equal_to<typename iterator_traits<InputIterator>::value_type>,
  185. Allocator>; // C++17
  186. template<class T, class Allocator>
  187. unordered_set(initializer_list<T>, typename see below::size_type, Allocator)
  188. -> unordered_set<T, hash<T>, equal_to<T>, Allocator>; // C++17
  189. template<class T, class Hash, class Allocator>
  190. unordered_set(initializer_list<T>, typename see below::size_type, Hash, Allocator)
  191. -> unordered_set<T, Hash, equal_to<T>, Allocator>; // C++17
  192. template <class Value, class Hash, class Pred, class Alloc>
  193. void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
  194. unordered_set<Value, Hash, Pred, Alloc>& y)
  195. noexcept(noexcept(x.swap(y)));
  196. template <class Value, class Hash, class Pred, class Alloc>
  197. bool
  198. operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
  199. const unordered_set<Value, Hash, Pred, Alloc>& y);
  200. template <class Value, class Hash, class Pred, class Alloc>
  201. bool
  202. operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
  203. const unordered_set<Value, Hash, Pred, Alloc>& y);
  204. template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
  205. class Alloc = allocator<Value>>
  206. class unordered_multiset
  207. {
  208. public:
  209. // types
  210. typedef Value key_type;
  211. typedef key_type value_type;
  212. typedef Hash hasher;
  213. typedef Pred key_equal;
  214. typedef Alloc allocator_type;
  215. typedef value_type& reference;
  216. typedef const value_type& const_reference;
  217. typedef typename allocator_traits<allocator_type>::pointer pointer;
  218. typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
  219. typedef typename allocator_traits<allocator_type>::size_type size_type;
  220. typedef typename allocator_traits<allocator_type>::difference_type difference_type;
  221. typedef /unspecified/ iterator;
  222. typedef /unspecified/ const_iterator;
  223. typedef /unspecified/ local_iterator;
  224. typedef /unspecified/ const_local_iterator;
  225. typedef unspecified node_type unspecified; // C++17
  226. unordered_multiset()
  227. noexcept(
  228. is_nothrow_default_constructible<hasher>::value &&
  229. is_nothrow_default_constructible<key_equal>::value &&
  230. is_nothrow_default_constructible<allocator_type>::value);
  231. explicit unordered_multiset(size_type n, const hasher& hf = hasher(),
  232. const key_equal& eql = key_equal(),
  233. const allocator_type& a = allocator_type());
  234. template <class InputIterator>
  235. unordered_multiset(InputIterator f, InputIterator l,
  236. size_type n = 0, const hasher& hf = hasher(),
  237. const key_equal& eql = key_equal(),
  238. const allocator_type& a = allocator_type());
  239. explicit unordered_multiset(const allocator_type&);
  240. unordered_multiset(const unordered_multiset&);
  241. unordered_multiset(const unordered_multiset&, const Allocator&);
  242. unordered_multiset(unordered_multiset&&)
  243. noexcept(
  244. is_nothrow_move_constructible<hasher>::value &&
  245. is_nothrow_move_constructible<key_equal>::value &&
  246. is_nothrow_move_constructible<allocator_type>::value);
  247. unordered_multiset(unordered_multiset&&, const Allocator&);
  248. unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
  249. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  250. const allocator_type& a = allocator_type());
  251. unordered_multiset(size_type n, const allocator_type& a); // C++14
  252. unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14
  253. template <class InputIterator>
  254. unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
  255. template <class InputIterator>
  256. unordered_multiset(InputIterator f, InputIterator l, size_type n,
  257. const hasher& hf, const allocator_type& a); // C++14
  258. unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
  259. unordered_multiset(initializer_list<value_type> il, size_type n,
  260. const hasher& hf, const allocator_type& a); // C++14
  261. ~unordered_multiset();
  262. unordered_multiset& operator=(const unordered_multiset&);
  263. unordered_multiset& operator=(unordered_multiset&&)
  264. noexcept(
  265. allocator_type::propagate_on_container_move_assignment::value &&
  266. is_nothrow_move_assignable<allocator_type>::value &&
  267. is_nothrow_move_assignable<hasher>::value &&
  268. is_nothrow_move_assignable<key_equal>::value);
  269. unordered_multiset& operator=(initializer_list<value_type>);
  270. allocator_type get_allocator() const noexcept;
  271. bool empty() const noexcept;
  272. size_type size() const noexcept;
  273. size_type max_size() const noexcept;
  274. iterator begin() noexcept;
  275. iterator end() noexcept;
  276. const_iterator begin() const noexcept;
  277. const_iterator end() const noexcept;
  278. const_iterator cbegin() const noexcept;
  279. const_iterator cend() const noexcept;
  280. template <class... Args>
  281. iterator emplace(Args&&... args);
  282. template <class... Args>
  283. iterator emplace_hint(const_iterator position, Args&&... args);
  284. iterator insert(const value_type& obj);
  285. iterator insert(value_type&& obj);
  286. iterator insert(const_iterator hint, const value_type& obj);
  287. iterator insert(const_iterator hint, value_type&& obj);
  288. template <class InputIterator>
  289. void insert(InputIterator first, InputIterator last);
  290. void insert(initializer_list<value_type>);
  291. node_type extract(const_iterator position); // C++17
  292. node_type extract(const key_type& x); // C++17
  293. iterator insert(node_type&& nh); // C++17
  294. iterator insert(const_iterator hint, node_type&& nh); // C++17
  295. iterator erase(const_iterator position);
  296. iterator erase(iterator position); // C++14
  297. size_type erase(const key_type& k);
  298. iterator erase(const_iterator first, const_iterator last);
  299. void clear() noexcept;
  300. template<class H2, class P2>
  301. void merge(unordered_multiset<Key, H2, P2, Allocator>& source); // C++17
  302. template<class H2, class P2>
  303. void merge(unordered_multiset<Key, H2, P2, Allocator>&& source); // C++17
  304. template<class H2, class P2>
  305. void merge(unordered_set<Key, H2, P2, Allocator>& source); // C++17
  306. template<class H2, class P2>
  307. void merge(unordered_set<Key, H2, P2, Allocator>&& source); // C++17
  308. void swap(unordered_multiset&)
  309. noexcept(allocator_traits<Allocator>::is_always_equal::value &&
  310. noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
  311. noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
  312. hasher hash_function() const;
  313. key_equal key_eq() const;
  314. iterator find(const key_type& k);
  315. const_iterator find(const key_type& k) const;
  316. template<typename K>
  317. iterator find(const K& x); // C++20
  318. template<typename K>
  319. const_iterator find(const K& x) const; // C++20
  320. size_type count(const key_type& k) const;
  321. template<typename K>
  322. size_type count(const K& k) const; // C++20
  323. bool contains(const key_type& k) const; // C++20
  324. template<typename K>
  325. bool contains(const K& k) const; // C++20
  326. pair<iterator, iterator> equal_range(const key_type& k);
  327. pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
  328. template<typename K>
  329. pair<iterator, iterator> equal_range(const K& k); // C++20
  330. template<typename K>
  331. pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
  332. size_type bucket_count() const noexcept;
  333. size_type max_bucket_count() const noexcept;
  334. size_type bucket_size(size_type n) const;
  335. size_type bucket(const key_type& k) const;
  336. local_iterator begin(size_type n);
  337. local_iterator end(size_type n);
  338. const_local_iterator begin(size_type n) const;
  339. const_local_iterator end(size_type n) const;
  340. const_local_iterator cbegin(size_type n) const;
  341. const_local_iterator cend(size_type n) const;
  342. float load_factor() const noexcept;
  343. float max_load_factor() const noexcept;
  344. void max_load_factor(float z);
  345. void rehash(size_type n);
  346. void reserve(size_type n);
  347. };
  348. template<class InputIterator,
  349. class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
  350. class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
  351. class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
  352. unordered_multiset(InputIterator, InputIterator, see below::size_type = see below,
  353. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  354. -> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
  355. Hash, Pred, Allocator>; // C++17
  356. template<class T, class Hash = hash<T>,
  357. class Pred = equal_to<T>, class Allocator = allocator<T>>
  358. unordered_multiset(initializer_list<T>, typename see below::size_type = see below,
  359. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  360. -> unordered_multiset<T, Hash, Pred, Allocator>; // C++17
  361. template<class InputIterator, class Allocator>
  362. unordered_multiset(InputIterator, InputIterator, typename see below::size_type, Allocator)
  363. -> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
  364. hash<typename iterator_traits<InputIterator>::value_type>,
  365. equal_to<typename iterator_traits<InputIterator>::value_type>,
  366. Allocator>; // C++17
  367. template<class InputIterator, class Hash, class Allocator>
  368. unordered_multiset(InputIterator, InputIterator, typename see below::size_type,
  369. Hash, Allocator)
  370. -> unordered_multiset<typename iterator_traits<InputIterator>::value_type, Hash,
  371. equal_to<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
  372. template<class T, class Allocator>
  373. unordered_multiset(initializer_list<T>, typename see below::size_type, Allocator)
  374. -> unordered_multiset<T, hash<T>, equal_to<T>, Allocator>; // C++17
  375. template<class T, class Hash, class Allocator>
  376. unordered_multiset(initializer_list<T>, typename see below::size_type, Hash, Allocator)
  377. -> unordered_multiset<T, Hash, equal_to<T>, Allocator>; // C++17
  378. template <class Value, class Hash, class Pred, class Alloc>
  379. void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
  380. unordered_multiset<Value, Hash, Pred, Alloc>& y)
  381. noexcept(noexcept(x.swap(y)));
  382. template <class K, class T, class H, class P, class A, class Predicate>
  383. typename unordered_set<K, T, H, P, A>::size_type
  384. erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20
  385. template <class K, class T, class H, class P, class A, class Predicate>
  386. typename unordered_multiset<K, T, H, P, A>::size_type
  387. erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20
  388. template <class Value, class Hash, class Pred, class Alloc>
  389. bool
  390. operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
  391. const unordered_multiset<Value, Hash, Pred, Alloc>& y);
  392. template <class Value, class Hash, class Pred, class Alloc>
  393. bool
  394. operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
  395. const unordered_multiset<Value, Hash, Pred, Alloc>& y);
  396. } // std
  397. */
  398. #include <__algorithm/is_permutation.h>
  399. #include <__assert>
  400. #include <__config>
  401. #include <__debug>
  402. #include <__functional/is_transparent.h>
  403. #include <__hash_table>
  404. #include <__memory/addressof.h>
  405. #include <__node_handle>
  406. #include <__utility/forward.h>
  407. #include <compare>
  408. #include <functional>
  409. #include <iterator> // __libcpp_erase_if_container
  410. #include <version>
  411. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  412. # pragma GCC system_header
  413. #endif
  414. _LIBCPP_BEGIN_NAMESPACE_STD
  415. template <class _Value, class _Hash, class _Pred, class _Alloc>
  416. class unordered_multiset;
  417. template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
  418. class _Alloc = allocator<_Value> >
  419. class _LIBCPP_TEMPLATE_VIS unordered_set
  420. {
  421. public:
  422. // types
  423. typedef _Value key_type;
  424. typedef key_type value_type;
  425. typedef __identity_t<_Hash> hasher;
  426. typedef __identity_t<_Pred> key_equal;
  427. typedef __identity_t<_Alloc> allocator_type;
  428. typedef value_type& reference;
  429. typedef const value_type& const_reference;
  430. static_assert((is_same<value_type, typename allocator_type::value_type>::value),
  431. "Invalid allocator::value_type");
  432. private:
  433. typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
  434. __table __table_;
  435. public:
  436. typedef typename __table::pointer pointer;
  437. typedef typename __table::const_pointer const_pointer;
  438. typedef typename __table::size_type size_type;
  439. typedef typename __table::difference_type difference_type;
  440. typedef typename __table::const_iterator iterator;
  441. typedef typename __table::const_iterator const_iterator;
  442. typedef typename __table::const_local_iterator local_iterator;
  443. typedef typename __table::const_local_iterator const_local_iterator;
  444. #if _LIBCPP_STD_VER > 14
  445. typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
  446. typedef __insert_return_type<iterator, node_type> insert_return_type;
  447. #endif
  448. template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
  449. friend class _LIBCPP_TEMPLATE_VIS unordered_set;
  450. template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
  451. friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
  452. _LIBCPP_INLINE_VISIBILITY
  453. unordered_set()
  454. _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
  455. {
  456. _VSTD::__debug_db_insert_c(this);
  457. }
  458. explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
  459. const key_equal& __eql = key_equal());
  460. #if _LIBCPP_STD_VER > 11
  461. inline _LIBCPP_INLINE_VISIBILITY
  462. unordered_set(size_type __n, const allocator_type& __a)
  463. : unordered_set(__n, hasher(), key_equal(), __a) {}
  464. inline _LIBCPP_INLINE_VISIBILITY
  465. unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
  466. : unordered_set(__n, __hf, key_equal(), __a) {}
  467. #endif
  468. unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
  469. const allocator_type& __a);
  470. template <class _InputIterator>
  471. unordered_set(_InputIterator __first, _InputIterator __last);
  472. template <class _InputIterator>
  473. unordered_set(_InputIterator __first, _InputIterator __last,
  474. size_type __n, const hasher& __hf = hasher(),
  475. const key_equal& __eql = key_equal());
  476. template <class _InputIterator>
  477. unordered_set(_InputIterator __first, _InputIterator __last,
  478. size_type __n, const hasher& __hf, const key_equal& __eql,
  479. const allocator_type& __a);
  480. #if _LIBCPP_STD_VER > 11
  481. template <class _InputIterator>
  482. inline _LIBCPP_INLINE_VISIBILITY
  483. unordered_set(_InputIterator __first, _InputIterator __last,
  484. size_type __n, const allocator_type& __a)
  485. : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
  486. template <class _InputIterator>
  487. unordered_set(_InputIterator __first, _InputIterator __last,
  488. size_type __n, const hasher& __hf, const allocator_type& __a)
  489. : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
  490. #endif
  491. _LIBCPP_INLINE_VISIBILITY
  492. explicit unordered_set(const allocator_type& __a);
  493. unordered_set(const unordered_set& __u);
  494. unordered_set(const unordered_set& __u, const allocator_type& __a);
  495. #ifndef _LIBCPP_CXX03_LANG
  496. _LIBCPP_INLINE_VISIBILITY
  497. unordered_set(unordered_set&& __u)
  498. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
  499. unordered_set(unordered_set&& __u, const allocator_type& __a);
  500. unordered_set(initializer_list<value_type> __il);
  501. unordered_set(initializer_list<value_type> __il, size_type __n,
  502. const hasher& __hf = hasher(),
  503. const key_equal& __eql = key_equal());
  504. unordered_set(initializer_list<value_type> __il, size_type __n,
  505. const hasher& __hf, const key_equal& __eql,
  506. const allocator_type& __a);
  507. #if _LIBCPP_STD_VER > 11
  508. inline _LIBCPP_INLINE_VISIBILITY
  509. unordered_set(initializer_list<value_type> __il, size_type __n,
  510. const allocator_type& __a)
  511. : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
  512. inline _LIBCPP_INLINE_VISIBILITY
  513. unordered_set(initializer_list<value_type> __il, size_type __n,
  514. const hasher& __hf, const allocator_type& __a)
  515. : unordered_set(__il, __n, __hf, key_equal(), __a) {}
  516. #endif
  517. #endif // _LIBCPP_CXX03_LANG
  518. _LIBCPP_INLINE_VISIBILITY
  519. ~unordered_set() {
  520. static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
  521. }
  522. _LIBCPP_INLINE_VISIBILITY
  523. unordered_set& operator=(const unordered_set& __u)
  524. {
  525. __table_ = __u.__table_;
  526. return *this;
  527. }
  528. #ifndef _LIBCPP_CXX03_LANG
  529. _LIBCPP_INLINE_VISIBILITY
  530. unordered_set& operator=(unordered_set&& __u)
  531. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
  532. _LIBCPP_INLINE_VISIBILITY
  533. unordered_set& operator=(initializer_list<value_type> __il);
  534. #endif // _LIBCPP_CXX03_LANG
  535. _LIBCPP_INLINE_VISIBILITY
  536. allocator_type get_allocator() const _NOEXCEPT
  537. {return allocator_type(__table_.__node_alloc());}
  538. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  539. bool empty() const _NOEXCEPT {return __table_.size() == 0;}
  540. _LIBCPP_INLINE_VISIBILITY
  541. size_type size() const _NOEXCEPT {return __table_.size();}
  542. _LIBCPP_INLINE_VISIBILITY
  543. size_type max_size() const _NOEXCEPT {return __table_.max_size();}
  544. _LIBCPP_INLINE_VISIBILITY
  545. iterator begin() _NOEXCEPT {return __table_.begin();}
  546. _LIBCPP_INLINE_VISIBILITY
  547. iterator end() _NOEXCEPT {return __table_.end();}
  548. _LIBCPP_INLINE_VISIBILITY
  549. const_iterator begin() const _NOEXCEPT {return __table_.begin();}
  550. _LIBCPP_INLINE_VISIBILITY
  551. const_iterator end() const _NOEXCEPT {return __table_.end();}
  552. _LIBCPP_INLINE_VISIBILITY
  553. const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
  554. _LIBCPP_INLINE_VISIBILITY
  555. const_iterator cend() const _NOEXCEPT {return __table_.end();}
  556. #ifndef _LIBCPP_CXX03_LANG
  557. template <class... _Args>
  558. _LIBCPP_INLINE_VISIBILITY
  559. pair<iterator, bool> emplace(_Args&&... __args)
  560. {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
  561. template <class... _Args>
  562. _LIBCPP_INLINE_VISIBILITY
  563. #if _LIBCPP_DEBUG_LEVEL == 2
  564. iterator emplace_hint(const_iterator __p, _Args&&... __args)
  565. {
  566. _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
  567. "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
  568. " referring to this unordered_set");
  569. return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
  570. }
  571. #else
  572. iterator emplace_hint(const_iterator, _Args&&... __args)
  573. {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
  574. #endif
  575. _LIBCPP_INLINE_VISIBILITY
  576. pair<iterator, bool> insert(value_type&& __x)
  577. {return __table_.__insert_unique(_VSTD::move(__x));}
  578. _LIBCPP_INLINE_VISIBILITY
  579. #if _LIBCPP_DEBUG_LEVEL == 2
  580. iterator insert(const_iterator __p, value_type&& __x)
  581. {
  582. _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
  583. "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
  584. " referring to this unordered_set");
  585. return insert(_VSTD::move(__x)).first;
  586. }
  587. #else
  588. iterator insert(const_iterator, value_type&& __x)
  589. {return insert(_VSTD::move(__x)).first;}
  590. #endif
  591. _LIBCPP_INLINE_VISIBILITY
  592. void insert(initializer_list<value_type> __il)
  593. {insert(__il.begin(), __il.end());}
  594. #endif // _LIBCPP_CXX03_LANG
  595. _LIBCPP_INLINE_VISIBILITY
  596. pair<iterator, bool> insert(const value_type& __x)
  597. {return __table_.__insert_unique(__x);}
  598. _LIBCPP_INLINE_VISIBILITY
  599. #if _LIBCPP_DEBUG_LEVEL == 2
  600. iterator insert(const_iterator __p, const value_type& __x)
  601. {
  602. _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
  603. "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
  604. " referring to this unordered_set");
  605. return insert(__x).first;
  606. }
  607. #else
  608. iterator insert(const_iterator, const value_type& __x)
  609. {return insert(__x).first;}
  610. #endif
  611. template <class _InputIterator>
  612. _LIBCPP_INLINE_VISIBILITY
  613. void insert(_InputIterator __first, _InputIterator __last);
  614. _LIBCPP_INLINE_VISIBILITY
  615. iterator erase(const_iterator __p) {return __table_.erase(__p);}
  616. _LIBCPP_INLINE_VISIBILITY
  617. size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
  618. _LIBCPP_INLINE_VISIBILITY
  619. iterator erase(const_iterator __first, const_iterator __last)
  620. {return __table_.erase(__first, __last);}
  621. _LIBCPP_INLINE_VISIBILITY
  622. void clear() _NOEXCEPT {__table_.clear();}
  623. #if _LIBCPP_STD_VER > 14
  624. _LIBCPP_INLINE_VISIBILITY
  625. insert_return_type insert(node_type&& __nh)
  626. {
  627. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  628. "node_type with incompatible allocator passed to unordered_set::insert()");
  629. return __table_.template __node_handle_insert_unique<
  630. node_type, insert_return_type>(_VSTD::move(__nh));
  631. }
  632. _LIBCPP_INLINE_VISIBILITY
  633. iterator insert(const_iterator __h, node_type&& __nh)
  634. {
  635. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  636. "node_type with incompatible allocator passed to unordered_set::insert()");
  637. return __table_.template __node_handle_insert_unique<node_type>(
  638. __h, _VSTD::move(__nh));
  639. }
  640. _LIBCPP_INLINE_VISIBILITY
  641. node_type extract(key_type const& __key)
  642. {
  643. return __table_.template __node_handle_extract<node_type>(__key);
  644. }
  645. _LIBCPP_INLINE_VISIBILITY
  646. node_type extract(const_iterator __it)
  647. {
  648. return __table_.template __node_handle_extract<node_type>(__it);
  649. }
  650. template<class _H2, class _P2>
  651. _LIBCPP_INLINE_VISIBILITY
  652. void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
  653. {
  654. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  655. "merging container with incompatible allocator");
  656. __table_.__node_handle_merge_unique(__source.__table_);
  657. }
  658. template<class _H2, class _P2>
  659. _LIBCPP_INLINE_VISIBILITY
  660. void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
  661. {
  662. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  663. "merging container with incompatible allocator");
  664. __table_.__node_handle_merge_unique(__source.__table_);
  665. }
  666. template<class _H2, class _P2>
  667. _LIBCPP_INLINE_VISIBILITY
  668. void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
  669. {
  670. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  671. "merging container with incompatible allocator");
  672. __table_.__node_handle_merge_unique(__source.__table_);
  673. }
  674. template<class _H2, class _P2>
  675. _LIBCPP_INLINE_VISIBILITY
  676. void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
  677. {
  678. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  679. "merging container with incompatible allocator");
  680. __table_.__node_handle_merge_unique(__source.__table_);
  681. }
  682. #endif
  683. _LIBCPP_INLINE_VISIBILITY
  684. void swap(unordered_set& __u)
  685. _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
  686. {__table_.swap(__u.__table_);}
  687. _LIBCPP_INLINE_VISIBILITY
  688. hasher hash_function() const {return __table_.hash_function();}
  689. _LIBCPP_INLINE_VISIBILITY
  690. key_equal key_eq() const {return __table_.key_eq();}
  691. _LIBCPP_INLINE_VISIBILITY
  692. iterator find(const key_type& __k) {return __table_.find(__k);}
  693. _LIBCPP_INLINE_VISIBILITY
  694. const_iterator find(const key_type& __k) const {return __table_.find(__k);}
  695. #if _LIBCPP_STD_VER > 17
  696. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  697. _LIBCPP_INLINE_VISIBILITY
  698. iterator find(const _K2& __k) {return __table_.find(__k);}
  699. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  700. _LIBCPP_INLINE_VISIBILITY
  701. const_iterator find(const _K2& __k) const {return __table_.find(__k);}
  702. #endif // _LIBCPP_STD_VER > 17
  703. _LIBCPP_INLINE_VISIBILITY
  704. size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
  705. #if _LIBCPP_STD_VER > 17
  706. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  707. _LIBCPP_INLINE_VISIBILITY
  708. size_type count(const _K2& __k) const {return __table_.__count_unique(__k);}
  709. #endif // _LIBCPP_STD_VER > 17
  710. #if _LIBCPP_STD_VER > 17
  711. _LIBCPP_INLINE_VISIBILITY
  712. bool contains(const key_type& __k) const {return find(__k) != end();}
  713. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  714. _LIBCPP_INLINE_VISIBILITY
  715. bool contains(const _K2& __k) const {return find(__k) != end();}
  716. #endif // _LIBCPP_STD_VER > 17
  717. _LIBCPP_INLINE_VISIBILITY
  718. pair<iterator, iterator> equal_range(const key_type& __k)
  719. {return __table_.__equal_range_unique(__k);}
  720. _LIBCPP_INLINE_VISIBILITY
  721. pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
  722. {return __table_.__equal_range_unique(__k);}
  723. #if _LIBCPP_STD_VER > 17
  724. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  725. _LIBCPP_INLINE_VISIBILITY
  726. pair<iterator, iterator> equal_range(const _K2& __k)
  727. {return __table_.__equal_range_unique(__k);}
  728. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  729. _LIBCPP_INLINE_VISIBILITY
  730. pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
  731. {return __table_.__equal_range_unique(__k);}
  732. #endif // _LIBCPP_STD_VER > 17
  733. _LIBCPP_INLINE_VISIBILITY
  734. size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
  735. _LIBCPP_INLINE_VISIBILITY
  736. size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
  737. _LIBCPP_INLINE_VISIBILITY
  738. size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
  739. _LIBCPP_INLINE_VISIBILITY
  740. size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
  741. _LIBCPP_INLINE_VISIBILITY
  742. local_iterator begin(size_type __n) {return __table_.begin(__n);}
  743. _LIBCPP_INLINE_VISIBILITY
  744. local_iterator end(size_type __n) {return __table_.end(__n);}
  745. _LIBCPP_INLINE_VISIBILITY
  746. const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
  747. _LIBCPP_INLINE_VISIBILITY
  748. const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
  749. _LIBCPP_INLINE_VISIBILITY
  750. const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
  751. _LIBCPP_INLINE_VISIBILITY
  752. const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
  753. _LIBCPP_INLINE_VISIBILITY
  754. float load_factor() const _NOEXCEPT {return __table_.load_factor();}
  755. _LIBCPP_INLINE_VISIBILITY
  756. float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
  757. _LIBCPP_INLINE_VISIBILITY
  758. void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
  759. _LIBCPP_INLINE_VISIBILITY
  760. void rehash(size_type __n) {__table_.rehash(__n);}
  761. _LIBCPP_INLINE_VISIBILITY
  762. void reserve(size_type __n) {__table_.reserve(__n);}
  763. #if _LIBCPP_DEBUG_LEVEL == 2
  764. bool __dereferenceable(const const_iterator* __i) const
  765. {return __table_.__dereferenceable(__i);}
  766. bool __decrementable(const const_iterator* __i) const
  767. {return __table_.__decrementable(__i);}
  768. bool __addable(const const_iterator* __i, ptrdiff_t __n) const
  769. {return __table_.__addable(__i, __n);}
  770. bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
  771. {return __table_.__addable(__i, __n);}
  772. #endif // _LIBCPP_DEBUG_LEVEL == 2
  773. };
  774. #if _LIBCPP_STD_VER >= 17
  775. template<class _InputIterator,
  776. class _Hash = hash<__iter_value_type<_InputIterator>>,
  777. class _Pred = equal_to<__iter_value_type<_InputIterator>>,
  778. class _Allocator = allocator<__iter_value_type<_InputIterator>>,
  779. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  780. class = enable_if_t<!__is_allocator<_Hash>::value>,
  781. class = enable_if_t<!is_integral<_Hash>::value>,
  782. class = enable_if_t<!__is_allocator<_Pred>::value>,
  783. class = enable_if_t<__is_allocator<_Allocator>::value>>
  784. unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
  785. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  786. -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
  787. template<class _Tp, class _Hash = hash<_Tp>,
  788. class _Pred = equal_to<_Tp>,
  789. class _Allocator = allocator<_Tp>,
  790. class = enable_if_t<!__is_allocator<_Hash>::value>,
  791. class = enable_if_t<!is_integral<_Hash>::value>,
  792. class = enable_if_t<!__is_allocator<_Pred>::value>,
  793. class = enable_if_t<__is_allocator<_Allocator>::value>>
  794. unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
  795. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  796. -> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
  797. template<class _InputIterator, class _Allocator,
  798. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  799. class = enable_if_t<__is_allocator<_Allocator>::value>>
  800. unordered_set(_InputIterator, _InputIterator,
  801. typename allocator_traits<_Allocator>::size_type, _Allocator)
  802. -> unordered_set<__iter_value_type<_InputIterator>,
  803. hash<__iter_value_type<_InputIterator>>,
  804. equal_to<__iter_value_type<_InputIterator>>,
  805. _Allocator>;
  806. template<class _InputIterator, class _Hash, class _Allocator,
  807. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  808. class = enable_if_t<!__is_allocator<_Hash>::value>,
  809. class = enable_if_t<!is_integral<_Hash>::value>,
  810. class = enable_if_t<__is_allocator<_Allocator>::value>>
  811. unordered_set(_InputIterator, _InputIterator,
  812. typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  813. -> unordered_set<__iter_value_type<_InputIterator>, _Hash,
  814. equal_to<__iter_value_type<_InputIterator>>,
  815. _Allocator>;
  816. template<class _Tp, class _Allocator,
  817. class = enable_if_t<__is_allocator<_Allocator>::value>>
  818. unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
  819. -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
  820. template<class _Tp, class _Hash, class _Allocator,
  821. class = enable_if_t<!__is_allocator<_Hash>::value>,
  822. class = enable_if_t<!is_integral<_Hash>::value>,
  823. class = enable_if_t<__is_allocator<_Allocator>::value>>
  824. unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  825. -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
  826. #endif
  827. template <class _Value, class _Hash, class _Pred, class _Alloc>
  828. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
  829. const hasher& __hf, const key_equal& __eql)
  830. : __table_(__hf, __eql)
  831. {
  832. _VSTD::__debug_db_insert_c(this);
  833. __table_.rehash(__n);
  834. }
  835. template <class _Value, class _Hash, class _Pred, class _Alloc>
  836. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
  837. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  838. : __table_(__hf, __eql, __a)
  839. {
  840. _VSTD::__debug_db_insert_c(this);
  841. __table_.rehash(__n);
  842. }
  843. template <class _Value, class _Hash, class _Pred, class _Alloc>
  844. template <class _InputIterator>
  845. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  846. _InputIterator __first, _InputIterator __last)
  847. {
  848. _VSTD::__debug_db_insert_c(this);
  849. insert(__first, __last);
  850. }
  851. template <class _Value, class _Hash, class _Pred, class _Alloc>
  852. template <class _InputIterator>
  853. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  854. _InputIterator __first, _InputIterator __last, size_type __n,
  855. const hasher& __hf, const key_equal& __eql)
  856. : __table_(__hf, __eql)
  857. {
  858. _VSTD::__debug_db_insert_c(this);
  859. __table_.rehash(__n);
  860. insert(__first, __last);
  861. }
  862. template <class _Value, class _Hash, class _Pred, class _Alloc>
  863. template <class _InputIterator>
  864. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  865. _InputIterator __first, _InputIterator __last, size_type __n,
  866. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  867. : __table_(__hf, __eql, __a)
  868. {
  869. _VSTD::__debug_db_insert_c(this);
  870. __table_.rehash(__n);
  871. insert(__first, __last);
  872. }
  873. template <class _Value, class _Hash, class _Pred, class _Alloc>
  874. inline
  875. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  876. const allocator_type& __a)
  877. : __table_(__a)
  878. {
  879. _VSTD::__debug_db_insert_c(this);
  880. }
  881. template <class _Value, class _Hash, class _Pred, class _Alloc>
  882. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  883. const unordered_set& __u)
  884. : __table_(__u.__table_)
  885. {
  886. _VSTD::__debug_db_insert_c(this);
  887. __table_.rehash(__u.bucket_count());
  888. insert(__u.begin(), __u.end());
  889. }
  890. template <class _Value, class _Hash, class _Pred, class _Alloc>
  891. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  892. const unordered_set& __u, const allocator_type& __a)
  893. : __table_(__u.__table_, __a)
  894. {
  895. _VSTD::__debug_db_insert_c(this);
  896. __table_.rehash(__u.bucket_count());
  897. insert(__u.begin(), __u.end());
  898. }
  899. #ifndef _LIBCPP_CXX03_LANG
  900. template <class _Value, class _Hash, class _Pred, class _Alloc>
  901. inline
  902. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  903. unordered_set&& __u)
  904. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
  905. : __table_(_VSTD::move(__u.__table_))
  906. {
  907. _VSTD::__debug_db_insert_c(this);
  908. #if _LIBCPP_DEBUG_LEVEL == 2
  909. __get_db()->swap(this, _VSTD::addressof(__u));
  910. #endif
  911. }
  912. template <class _Value, class _Hash, class _Pred, class _Alloc>
  913. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  914. unordered_set&& __u, const allocator_type& __a)
  915. : __table_(_VSTD::move(__u.__table_), __a)
  916. {
  917. _VSTD::__debug_db_insert_c(this);
  918. if (__a != __u.get_allocator())
  919. {
  920. iterator __i = __u.begin();
  921. while (__u.size() != 0)
  922. __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
  923. }
  924. #if _LIBCPP_DEBUG_LEVEL == 2
  925. else
  926. __get_db()->swap(this, _VSTD::addressof(__u));
  927. #endif
  928. }
  929. template <class _Value, class _Hash, class _Pred, class _Alloc>
  930. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  931. initializer_list<value_type> __il)
  932. {
  933. _VSTD::__debug_db_insert_c(this);
  934. insert(__il.begin(), __il.end());
  935. }
  936. template <class _Value, class _Hash, class _Pred, class _Alloc>
  937. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  938. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  939. const key_equal& __eql)
  940. : __table_(__hf, __eql)
  941. {
  942. _VSTD::__debug_db_insert_c(this);
  943. __table_.rehash(__n);
  944. insert(__il.begin(), __il.end());
  945. }
  946. template <class _Value, class _Hash, class _Pred, class _Alloc>
  947. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  948. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  949. const key_equal& __eql, const allocator_type& __a)
  950. : __table_(__hf, __eql, __a)
  951. {
  952. _VSTD::__debug_db_insert_c(this);
  953. __table_.rehash(__n);
  954. insert(__il.begin(), __il.end());
  955. }
  956. template <class _Value, class _Hash, class _Pred, class _Alloc>
  957. inline
  958. unordered_set<_Value, _Hash, _Pred, _Alloc>&
  959. unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
  960. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
  961. {
  962. __table_ = _VSTD::move(__u.__table_);
  963. return *this;
  964. }
  965. template <class _Value, class _Hash, class _Pred, class _Alloc>
  966. inline
  967. unordered_set<_Value, _Hash, _Pred, _Alloc>&
  968. unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
  969. initializer_list<value_type> __il)
  970. {
  971. __table_.__assign_unique(__il.begin(), __il.end());
  972. return *this;
  973. }
  974. #endif // _LIBCPP_CXX03_LANG
  975. template <class _Value, class _Hash, class _Pred, class _Alloc>
  976. template <class _InputIterator>
  977. inline
  978. void
  979. unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
  980. _InputIterator __last)
  981. {
  982. for (; __first != __last; ++__first)
  983. __table_.__insert_unique(*__first);
  984. }
  985. template <class _Value, class _Hash, class _Pred, class _Alloc>
  986. inline _LIBCPP_INLINE_VISIBILITY
  987. void
  988. swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  989. unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  990. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  991. {
  992. __x.swap(__y);
  993. }
  994. #if _LIBCPP_STD_VER > 17
  995. template <class _Value, class _Hash, class _Pred, class _Alloc,
  996. class _Predicate>
  997. inline _LIBCPP_INLINE_VISIBILITY
  998. typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type
  999. erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c,
  1000. _Predicate __pred) {
  1001. return _VSTD::__libcpp_erase_if_container(__c, __pred);
  1002. }
  1003. #endif
  1004. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1005. bool
  1006. operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  1007. const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  1008. {
  1009. if (__x.size() != __y.size())
  1010. return false;
  1011. typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
  1012. const_iterator;
  1013. for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
  1014. __i != __ex; ++__i)
  1015. {
  1016. const_iterator __j = __y.find(*__i);
  1017. if (__j == __ey || !(*__i == *__j))
  1018. return false;
  1019. }
  1020. return true;
  1021. }
  1022. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1023. inline _LIBCPP_INLINE_VISIBILITY
  1024. bool
  1025. operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  1026. const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  1027. {
  1028. return !(__x == __y);
  1029. }
  1030. template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
  1031. class _Alloc = allocator<_Value> >
  1032. class _LIBCPP_TEMPLATE_VIS unordered_multiset
  1033. {
  1034. public:
  1035. // types
  1036. typedef _Value key_type;
  1037. typedef key_type value_type;
  1038. typedef __identity_t<_Hash> hasher;
  1039. typedef __identity_t<_Pred> key_equal;
  1040. typedef __identity_t<_Alloc> allocator_type;
  1041. typedef value_type& reference;
  1042. typedef const value_type& const_reference;
  1043. static_assert((is_same<value_type, typename allocator_type::value_type>::value),
  1044. "Invalid allocator::value_type");
  1045. private:
  1046. typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
  1047. __table __table_;
  1048. public:
  1049. typedef typename __table::pointer pointer;
  1050. typedef typename __table::const_pointer const_pointer;
  1051. typedef typename __table::size_type size_type;
  1052. typedef typename __table::difference_type difference_type;
  1053. typedef typename __table::const_iterator iterator;
  1054. typedef typename __table::const_iterator const_iterator;
  1055. typedef typename __table::const_local_iterator local_iterator;
  1056. typedef typename __table::const_local_iterator const_local_iterator;
  1057. #if _LIBCPP_STD_VER > 14
  1058. typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
  1059. #endif
  1060. template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
  1061. friend class _LIBCPP_TEMPLATE_VIS unordered_set;
  1062. template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
  1063. friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
  1064. _LIBCPP_INLINE_VISIBILITY
  1065. unordered_multiset()
  1066. _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
  1067. {
  1068. _VSTD::__debug_db_insert_c(this);
  1069. }
  1070. explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
  1071. const key_equal& __eql = key_equal());
  1072. unordered_multiset(size_type __n, const hasher& __hf,
  1073. const key_equal& __eql, const allocator_type& __a);
  1074. #if _LIBCPP_STD_VER > 11
  1075. inline _LIBCPP_INLINE_VISIBILITY
  1076. unordered_multiset(size_type __n, const allocator_type& __a)
  1077. : unordered_multiset(__n, hasher(), key_equal(), __a) {}
  1078. inline _LIBCPP_INLINE_VISIBILITY
  1079. unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
  1080. : unordered_multiset(__n, __hf, key_equal(), __a) {}
  1081. #endif
  1082. template <class _InputIterator>
  1083. unordered_multiset(_InputIterator __first, _InputIterator __last);
  1084. template <class _InputIterator>
  1085. unordered_multiset(_InputIterator __first, _InputIterator __last,
  1086. size_type __n, const hasher& __hf = hasher(),
  1087. const key_equal& __eql = key_equal());
  1088. template <class _InputIterator>
  1089. unordered_multiset(_InputIterator __first, _InputIterator __last,
  1090. size_type __n , const hasher& __hf,
  1091. const key_equal& __eql, const allocator_type& __a);
  1092. #if _LIBCPP_STD_VER > 11
  1093. template <class _InputIterator>
  1094. inline _LIBCPP_INLINE_VISIBILITY
  1095. unordered_multiset(_InputIterator __first, _InputIterator __last,
  1096. size_type __n, const allocator_type& __a)
  1097. : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
  1098. template <class _InputIterator>
  1099. inline _LIBCPP_INLINE_VISIBILITY
  1100. unordered_multiset(_InputIterator __first, _InputIterator __last,
  1101. size_type __n, const hasher& __hf, const allocator_type& __a)
  1102. : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
  1103. #endif
  1104. _LIBCPP_INLINE_VISIBILITY
  1105. explicit unordered_multiset(const allocator_type& __a);
  1106. unordered_multiset(const unordered_multiset& __u);
  1107. unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
  1108. #ifndef _LIBCPP_CXX03_LANG
  1109. _LIBCPP_INLINE_VISIBILITY
  1110. unordered_multiset(unordered_multiset&& __u)
  1111. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
  1112. unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
  1113. unordered_multiset(initializer_list<value_type> __il);
  1114. unordered_multiset(initializer_list<value_type> __il, size_type __n,
  1115. const hasher& __hf = hasher(),
  1116. const key_equal& __eql = key_equal());
  1117. unordered_multiset(initializer_list<value_type> __il, size_type __n,
  1118. const hasher& __hf, const key_equal& __eql,
  1119. const allocator_type& __a);
  1120. #if _LIBCPP_STD_VER > 11
  1121. inline _LIBCPP_INLINE_VISIBILITY
  1122. unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
  1123. : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
  1124. inline _LIBCPP_INLINE_VISIBILITY
  1125. unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
  1126. : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
  1127. #endif
  1128. #endif // _LIBCPP_CXX03_LANG
  1129. _LIBCPP_INLINE_VISIBILITY
  1130. ~unordered_multiset() {
  1131. static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
  1132. }
  1133. _LIBCPP_INLINE_VISIBILITY
  1134. unordered_multiset& operator=(const unordered_multiset& __u)
  1135. {
  1136. __table_ = __u.__table_;
  1137. return *this;
  1138. }
  1139. #ifndef _LIBCPP_CXX03_LANG
  1140. _LIBCPP_INLINE_VISIBILITY
  1141. unordered_multiset& operator=(unordered_multiset&& __u)
  1142. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
  1143. unordered_multiset& operator=(initializer_list<value_type> __il);
  1144. #endif // _LIBCPP_CXX03_LANG
  1145. _LIBCPP_INLINE_VISIBILITY
  1146. allocator_type get_allocator() const _NOEXCEPT
  1147. {return allocator_type(__table_.__node_alloc());}
  1148. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  1149. bool empty() const _NOEXCEPT {return __table_.size() == 0;}
  1150. _LIBCPP_INLINE_VISIBILITY
  1151. size_type size() const _NOEXCEPT {return __table_.size();}
  1152. _LIBCPP_INLINE_VISIBILITY
  1153. size_type max_size() const _NOEXCEPT {return __table_.max_size();}
  1154. _LIBCPP_INLINE_VISIBILITY
  1155. iterator begin() _NOEXCEPT {return __table_.begin();}
  1156. _LIBCPP_INLINE_VISIBILITY
  1157. iterator end() _NOEXCEPT {return __table_.end();}
  1158. _LIBCPP_INLINE_VISIBILITY
  1159. const_iterator begin() const _NOEXCEPT {return __table_.begin();}
  1160. _LIBCPP_INLINE_VISIBILITY
  1161. const_iterator end() const _NOEXCEPT {return __table_.end();}
  1162. _LIBCPP_INLINE_VISIBILITY
  1163. const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
  1164. _LIBCPP_INLINE_VISIBILITY
  1165. const_iterator cend() const _NOEXCEPT {return __table_.end();}
  1166. #ifndef _LIBCPP_CXX03_LANG
  1167. template <class... _Args>
  1168. _LIBCPP_INLINE_VISIBILITY
  1169. iterator emplace(_Args&&... __args)
  1170. {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
  1171. template <class... _Args>
  1172. _LIBCPP_INLINE_VISIBILITY
  1173. iterator emplace_hint(const_iterator __p, _Args&&... __args)
  1174. {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
  1175. _LIBCPP_INLINE_VISIBILITY
  1176. iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
  1177. _LIBCPP_INLINE_VISIBILITY
  1178. iterator insert(const_iterator __p, value_type&& __x)
  1179. {return __table_.__insert_multi(__p, _VSTD::move(__x));}
  1180. _LIBCPP_INLINE_VISIBILITY
  1181. void insert(initializer_list<value_type> __il)
  1182. {insert(__il.begin(), __il.end());}
  1183. #endif // _LIBCPP_CXX03_LANG
  1184. _LIBCPP_INLINE_VISIBILITY
  1185. iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
  1186. _LIBCPP_INLINE_VISIBILITY
  1187. iterator insert(const_iterator __p, const value_type& __x)
  1188. {return __table_.__insert_multi(__p, __x);}
  1189. template <class _InputIterator>
  1190. _LIBCPP_INLINE_VISIBILITY
  1191. void insert(_InputIterator __first, _InputIterator __last);
  1192. #if _LIBCPP_STD_VER > 14
  1193. _LIBCPP_INLINE_VISIBILITY
  1194. iterator insert(node_type&& __nh)
  1195. {
  1196. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1197. "node_type with incompatible allocator passed to unordered_multiset::insert()");
  1198. return __table_.template __node_handle_insert_multi<node_type>(
  1199. _VSTD::move(__nh));
  1200. }
  1201. _LIBCPP_INLINE_VISIBILITY
  1202. iterator insert(const_iterator __hint, node_type&& __nh)
  1203. {
  1204. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1205. "node_type with incompatible allocator passed to unordered_multiset::insert()");
  1206. return __table_.template __node_handle_insert_multi<node_type>(
  1207. __hint, _VSTD::move(__nh));
  1208. }
  1209. _LIBCPP_INLINE_VISIBILITY
  1210. node_type extract(const_iterator __position)
  1211. {
  1212. return __table_.template __node_handle_extract<node_type>(
  1213. __position);
  1214. }
  1215. _LIBCPP_INLINE_VISIBILITY
  1216. node_type extract(key_type const& __key)
  1217. {
  1218. return __table_.template __node_handle_extract<node_type>(__key);
  1219. }
  1220. template <class _H2, class _P2>
  1221. _LIBCPP_INLINE_VISIBILITY
  1222. void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
  1223. {
  1224. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1225. "merging container with incompatible allocator");
  1226. return __table_.__node_handle_merge_multi(__source.__table_);
  1227. }
  1228. template <class _H2, class _P2>
  1229. _LIBCPP_INLINE_VISIBILITY
  1230. void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
  1231. {
  1232. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1233. "merging container with incompatible allocator");
  1234. return __table_.__node_handle_merge_multi(__source.__table_);
  1235. }
  1236. template <class _H2, class _P2>
  1237. _LIBCPP_INLINE_VISIBILITY
  1238. void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
  1239. {
  1240. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1241. "merging container with incompatible allocator");
  1242. return __table_.__node_handle_merge_multi(__source.__table_);
  1243. }
  1244. template <class _H2, class _P2>
  1245. _LIBCPP_INLINE_VISIBILITY
  1246. void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
  1247. {
  1248. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1249. "merging container with incompatible allocator");
  1250. return __table_.__node_handle_merge_multi(__source.__table_);
  1251. }
  1252. #endif
  1253. _LIBCPP_INLINE_VISIBILITY
  1254. iterator erase(const_iterator __p) {return __table_.erase(__p);}
  1255. _LIBCPP_INLINE_VISIBILITY
  1256. size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
  1257. _LIBCPP_INLINE_VISIBILITY
  1258. iterator erase(const_iterator __first, const_iterator __last)
  1259. {return __table_.erase(__first, __last);}
  1260. _LIBCPP_INLINE_VISIBILITY
  1261. void clear() _NOEXCEPT {__table_.clear();}
  1262. _LIBCPP_INLINE_VISIBILITY
  1263. void swap(unordered_multiset& __u)
  1264. _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
  1265. {__table_.swap(__u.__table_);}
  1266. _LIBCPP_INLINE_VISIBILITY
  1267. hasher hash_function() const {return __table_.hash_function();}
  1268. _LIBCPP_INLINE_VISIBILITY
  1269. key_equal key_eq() const {return __table_.key_eq();}
  1270. _LIBCPP_INLINE_VISIBILITY
  1271. iterator find(const key_type& __k) {return __table_.find(__k);}
  1272. _LIBCPP_INLINE_VISIBILITY
  1273. const_iterator find(const key_type& __k) const {return __table_.find(__k);}
  1274. #if _LIBCPP_STD_VER > 17
  1275. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1276. _LIBCPP_INLINE_VISIBILITY
  1277. iterator find(const _K2& __k) {return __table_.find(__k);}
  1278. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1279. _LIBCPP_INLINE_VISIBILITY
  1280. const_iterator find(const _K2& __k) const {return __table_.find(__k);}
  1281. #endif // _LIBCPP_STD_VER > 17
  1282. _LIBCPP_INLINE_VISIBILITY
  1283. size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
  1284. #if _LIBCPP_STD_VER > 17
  1285. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1286. _LIBCPP_INLINE_VISIBILITY
  1287. size_type count(const _K2& __k) const {return __table_.__count_multi(__k);}
  1288. #endif // _LIBCPP_STD_VER > 17
  1289. #if _LIBCPP_STD_VER > 17
  1290. _LIBCPP_INLINE_VISIBILITY
  1291. bool contains(const key_type& __k) const {return find(__k) != end();}
  1292. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1293. _LIBCPP_INLINE_VISIBILITY
  1294. bool contains(const _K2& __k) const {return find(__k) != end();}
  1295. #endif // _LIBCPP_STD_VER > 17
  1296. _LIBCPP_INLINE_VISIBILITY
  1297. pair<iterator, iterator> equal_range(const key_type& __k)
  1298. {return __table_.__equal_range_multi(__k);}
  1299. _LIBCPP_INLINE_VISIBILITY
  1300. pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
  1301. {return __table_.__equal_range_multi(__k);}
  1302. #if _LIBCPP_STD_VER > 17
  1303. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1304. _LIBCPP_INLINE_VISIBILITY
  1305. pair<iterator, iterator> equal_range(const _K2& __k)
  1306. {return __table_.__equal_range_multi(__k);}
  1307. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1308. _LIBCPP_INLINE_VISIBILITY
  1309. pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
  1310. {return __table_.__equal_range_multi(__k);}
  1311. #endif // _LIBCPP_STD_VER > 17
  1312. _LIBCPP_INLINE_VISIBILITY
  1313. size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
  1314. _LIBCPP_INLINE_VISIBILITY
  1315. size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
  1316. _LIBCPP_INLINE_VISIBILITY
  1317. size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
  1318. _LIBCPP_INLINE_VISIBILITY
  1319. size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
  1320. _LIBCPP_INLINE_VISIBILITY
  1321. local_iterator begin(size_type __n) {return __table_.begin(__n);}
  1322. _LIBCPP_INLINE_VISIBILITY
  1323. local_iterator end(size_type __n) {return __table_.end(__n);}
  1324. _LIBCPP_INLINE_VISIBILITY
  1325. const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
  1326. _LIBCPP_INLINE_VISIBILITY
  1327. const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
  1328. _LIBCPP_INLINE_VISIBILITY
  1329. const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
  1330. _LIBCPP_INLINE_VISIBILITY
  1331. const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
  1332. _LIBCPP_INLINE_VISIBILITY
  1333. float load_factor() const _NOEXCEPT {return __table_.load_factor();}
  1334. _LIBCPP_INLINE_VISIBILITY
  1335. float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
  1336. _LIBCPP_INLINE_VISIBILITY
  1337. void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
  1338. _LIBCPP_INLINE_VISIBILITY
  1339. void rehash(size_type __n) {__table_.rehash(__n);}
  1340. _LIBCPP_INLINE_VISIBILITY
  1341. void reserve(size_type __n) {__table_.reserve(__n);}
  1342. #if _LIBCPP_DEBUG_LEVEL == 2
  1343. bool __dereferenceable(const const_iterator* __i) const
  1344. {return __table_.__dereferenceable(__i);}
  1345. bool __decrementable(const const_iterator* __i) const
  1346. {return __table_.__decrementable(__i);}
  1347. bool __addable(const const_iterator* __i, ptrdiff_t __n) const
  1348. {return __table_.__addable(__i, __n);}
  1349. bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
  1350. {return __table_.__addable(__i, __n);}
  1351. #endif // _LIBCPP_DEBUG_LEVEL == 2
  1352. };
  1353. #if _LIBCPP_STD_VER >= 17
  1354. template<class _InputIterator,
  1355. class _Hash = hash<__iter_value_type<_InputIterator>>,
  1356. class _Pred = equal_to<__iter_value_type<_InputIterator>>,
  1357. class _Allocator = allocator<__iter_value_type<_InputIterator>>,
  1358. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  1359. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1360. class = enable_if_t<!is_integral<_Hash>::value>,
  1361. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1362. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1363. unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
  1364. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  1365. -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
  1366. template<class _Tp, class _Hash = hash<_Tp>,
  1367. class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>,
  1368. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1369. class = enable_if_t<!is_integral<_Hash>::value>,
  1370. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1371. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1372. unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
  1373. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  1374. -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
  1375. template<class _InputIterator, class _Allocator,
  1376. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  1377. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1378. unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1379. -> unordered_multiset<__iter_value_type<_InputIterator>,
  1380. hash<__iter_value_type<_InputIterator>>,
  1381. equal_to<__iter_value_type<_InputIterator>>,
  1382. _Allocator>;
  1383. template<class _InputIterator, class _Hash, class _Allocator,
  1384. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  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<_Allocator>::value>>
  1388. unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type,
  1389. _Hash, _Allocator)
  1390. -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash,
  1391. equal_to<__iter_value_type<_InputIterator>>,
  1392. _Allocator>;
  1393. template<class _Tp, class _Allocator,
  1394. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1395. unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1396. -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
  1397. template<class _Tp, class _Hash, class _Allocator,
  1398. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1399. class = enable_if_t<!is_integral<_Hash>::value>,
  1400. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1401. unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  1402. -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
  1403. #endif
  1404. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1405. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1406. size_type __n, const hasher& __hf, const key_equal& __eql)
  1407. : __table_(__hf, __eql)
  1408. {
  1409. _VSTD::__debug_db_insert_c(this);
  1410. __table_.rehash(__n);
  1411. }
  1412. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1413. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1414. size_type __n, const hasher& __hf, const key_equal& __eql,
  1415. const allocator_type& __a)
  1416. : __table_(__hf, __eql, __a)
  1417. {
  1418. _VSTD::__debug_db_insert_c(this);
  1419. __table_.rehash(__n);
  1420. }
  1421. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1422. template <class _InputIterator>
  1423. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1424. _InputIterator __first, _InputIterator __last)
  1425. {
  1426. _VSTD::__debug_db_insert_c(this);
  1427. insert(__first, __last);
  1428. }
  1429. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1430. template <class _InputIterator>
  1431. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1432. _InputIterator __first, _InputIterator __last, size_type __n,
  1433. const hasher& __hf, const key_equal& __eql)
  1434. : __table_(__hf, __eql)
  1435. {
  1436. _VSTD::__debug_db_insert_c(this);
  1437. __table_.rehash(__n);
  1438. insert(__first, __last);
  1439. }
  1440. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1441. template <class _InputIterator>
  1442. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1443. _InputIterator __first, _InputIterator __last, size_type __n,
  1444. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  1445. : __table_(__hf, __eql, __a)
  1446. {
  1447. _VSTD::__debug_db_insert_c(this);
  1448. __table_.rehash(__n);
  1449. insert(__first, __last);
  1450. }
  1451. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1452. inline
  1453. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1454. const allocator_type& __a)
  1455. : __table_(__a)
  1456. {
  1457. _VSTD::__debug_db_insert_c(this);
  1458. }
  1459. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1460. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1461. const unordered_multiset& __u)
  1462. : __table_(__u.__table_)
  1463. {
  1464. _VSTD::__debug_db_insert_c(this);
  1465. __table_.rehash(__u.bucket_count());
  1466. insert(__u.begin(), __u.end());
  1467. }
  1468. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1469. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1470. const unordered_multiset& __u, const allocator_type& __a)
  1471. : __table_(__u.__table_, __a)
  1472. {
  1473. _VSTD::__debug_db_insert_c(this);
  1474. __table_.rehash(__u.bucket_count());
  1475. insert(__u.begin(), __u.end());
  1476. }
  1477. #ifndef _LIBCPP_CXX03_LANG
  1478. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1479. inline
  1480. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1481. unordered_multiset&& __u)
  1482. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
  1483. : __table_(_VSTD::move(__u.__table_))
  1484. {
  1485. _VSTD::__debug_db_insert_c(this);
  1486. #if _LIBCPP_DEBUG_LEVEL == 2
  1487. __get_db()->swap(this, _VSTD::addressof(__u));
  1488. #endif
  1489. }
  1490. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1491. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1492. unordered_multiset&& __u, const allocator_type& __a)
  1493. : __table_(_VSTD::move(__u.__table_), __a)
  1494. {
  1495. _VSTD::__debug_db_insert_c(this);
  1496. if (__a != __u.get_allocator())
  1497. {
  1498. iterator __i = __u.begin();
  1499. while (__u.size() != 0)
  1500. __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
  1501. }
  1502. #if _LIBCPP_DEBUG_LEVEL == 2
  1503. else
  1504. __get_db()->swap(this, _VSTD::addressof(__u));
  1505. #endif
  1506. }
  1507. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1508. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1509. initializer_list<value_type> __il)
  1510. {
  1511. _VSTD::__debug_db_insert_c(this);
  1512. insert(__il.begin(), __il.end());
  1513. }
  1514. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1515. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1516. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  1517. const key_equal& __eql)
  1518. : __table_(__hf, __eql)
  1519. {
  1520. _VSTD::__debug_db_insert_c(this);
  1521. __table_.rehash(__n);
  1522. insert(__il.begin(), __il.end());
  1523. }
  1524. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1525. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1526. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  1527. const key_equal& __eql, const allocator_type& __a)
  1528. : __table_(__hf, __eql, __a)
  1529. {
  1530. _VSTD::__debug_db_insert_c(this);
  1531. __table_.rehash(__n);
  1532. insert(__il.begin(), __il.end());
  1533. }
  1534. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1535. inline
  1536. unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
  1537. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
  1538. unordered_multiset&& __u)
  1539. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
  1540. {
  1541. __table_ = _VSTD::move(__u.__table_);
  1542. return *this;
  1543. }
  1544. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1545. inline
  1546. unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
  1547. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
  1548. initializer_list<value_type> __il)
  1549. {
  1550. __table_.__assign_multi(__il.begin(), __il.end());
  1551. return *this;
  1552. }
  1553. #endif // _LIBCPP_CXX03_LANG
  1554. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1555. template <class _InputIterator>
  1556. inline
  1557. void
  1558. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
  1559. _InputIterator __last)
  1560. {
  1561. for (; __first != __last; ++__first)
  1562. __table_.__insert_multi(*__first);
  1563. }
  1564. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1565. inline _LIBCPP_INLINE_VISIBILITY
  1566. void
  1567. swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  1568. unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  1569. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  1570. {
  1571. __x.swap(__y);
  1572. }
  1573. #if _LIBCPP_STD_VER > 17
  1574. template <class _Value, class _Hash, class _Pred, class _Alloc,
  1575. class _Predicate>
  1576. inline _LIBCPP_INLINE_VISIBILITY
  1577. typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type
  1578. erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c,
  1579. _Predicate __pred) {
  1580. return _VSTD::__libcpp_erase_if_container(__c, __pred);
  1581. }
  1582. #endif
  1583. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1584. bool
  1585. operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  1586. const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  1587. {
  1588. if (__x.size() != __y.size())
  1589. return false;
  1590. typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
  1591. const_iterator;
  1592. typedef pair<const_iterator, const_iterator> _EqRng;
  1593. for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
  1594. {
  1595. _EqRng __xeq = __x.equal_range(*__i);
  1596. _EqRng __yeq = __y.equal_range(*__i);
  1597. if (_VSTD::distance(__xeq.first, __xeq.second) !=
  1598. _VSTD::distance(__yeq.first, __yeq.second) ||
  1599. !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
  1600. return false;
  1601. __i = __xeq.second;
  1602. }
  1603. return true;
  1604. }
  1605. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1606. inline _LIBCPP_INLINE_VISIBILITY
  1607. bool
  1608. operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  1609. const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  1610. {
  1611. return !(__x == __y);
  1612. }
  1613. _LIBCPP_END_NAMESPACE_STD
  1614. #endif // _LIBCPP_UNORDERED_SET