unordered_set 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824
  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> // all public C++ headers provide the assertion handler
  400. #include <__config>
  401. #include <__debug>
  402. #include <__functional/is_transparent.h>
  403. #include <__functional/operations.h>
  404. #include <__hash_table>
  405. #include <__iterator/distance.h>
  406. #include <__iterator/erase_if_container.h>
  407. #include <__iterator/iterator_traits.h>
  408. #include <__memory/addressof.h>
  409. #include <__memory/allocator.h>
  410. #include <__memory_resource/polymorphic_allocator.h>
  411. #include <__node_handle>
  412. #include <__type_traits/is_allocator.h>
  413. #include <__utility/forward.h>
  414. #include <version>
  415. // standard-mandated includes
  416. // [iterator.range]
  417. #include <__iterator/access.h>
  418. #include <__iterator/data.h>
  419. #include <__iterator/empty.h>
  420. #include <__iterator/reverse_access.h>
  421. #include <__iterator/size.h>
  422. // [unord.set.syn]
  423. #include <compare>
  424. #include <initializer_list>
  425. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  426. # pragma GCC system_header
  427. #endif
  428. _LIBCPP_BEGIN_NAMESPACE_STD
  429. template <class _Value, class _Hash, class _Pred, class _Alloc>
  430. class unordered_multiset;
  431. template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
  432. class _Alloc = allocator<_Value> >
  433. class _LIBCPP_TEMPLATE_VIS unordered_set
  434. {
  435. public:
  436. // types
  437. typedef _Value key_type;
  438. typedef key_type value_type;
  439. typedef __type_identity_t<_Hash> hasher;
  440. typedef __type_identity_t<_Pred> key_equal;
  441. typedef __type_identity_t<_Alloc> allocator_type;
  442. typedef value_type& reference;
  443. typedef const value_type& const_reference;
  444. static_assert((is_same<value_type, typename allocator_type::value_type>::value),
  445. "Invalid allocator::value_type");
  446. static_assert(is_same<allocator_type, __rebind_alloc<allocator_traits<allocator_type>, value_type> >::value,
  447. "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
  448. "original allocator");
  449. private:
  450. typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
  451. __table __table_;
  452. public:
  453. typedef typename __table::pointer pointer;
  454. typedef typename __table::const_pointer const_pointer;
  455. typedef typename __table::size_type size_type;
  456. typedef typename __table::difference_type difference_type;
  457. typedef typename __table::const_iterator iterator;
  458. typedef typename __table::const_iterator const_iterator;
  459. typedef typename __table::const_local_iterator local_iterator;
  460. typedef typename __table::const_local_iterator const_local_iterator;
  461. #if _LIBCPP_STD_VER > 14
  462. typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
  463. typedef __insert_return_type<iterator, node_type> insert_return_type;
  464. #endif
  465. template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
  466. friend class _LIBCPP_TEMPLATE_VIS unordered_set;
  467. template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
  468. friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
  469. _LIBCPP_INLINE_VISIBILITY
  470. unordered_set()
  471. _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
  472. {
  473. _VSTD::__debug_db_insert_c(this);
  474. }
  475. explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
  476. const key_equal& __eql = key_equal());
  477. #if _LIBCPP_STD_VER > 11
  478. inline _LIBCPP_INLINE_VISIBILITY
  479. unordered_set(size_type __n, const allocator_type& __a)
  480. : unordered_set(__n, hasher(), key_equal(), __a) {}
  481. inline _LIBCPP_INLINE_VISIBILITY
  482. unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
  483. : unordered_set(__n, __hf, key_equal(), __a) {}
  484. #endif
  485. unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
  486. const allocator_type& __a);
  487. template <class _InputIterator>
  488. unordered_set(_InputIterator __first, _InputIterator __last);
  489. template <class _InputIterator>
  490. unordered_set(_InputIterator __first, _InputIterator __last,
  491. size_type __n, const hasher& __hf = hasher(),
  492. const key_equal& __eql = key_equal());
  493. template <class _InputIterator>
  494. unordered_set(_InputIterator __first, _InputIterator __last,
  495. size_type __n, const hasher& __hf, const key_equal& __eql,
  496. const allocator_type& __a);
  497. #if _LIBCPP_STD_VER > 11
  498. template <class _InputIterator>
  499. inline _LIBCPP_INLINE_VISIBILITY
  500. unordered_set(_InputIterator __first, _InputIterator __last,
  501. size_type __n, const allocator_type& __a)
  502. : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
  503. template <class _InputIterator>
  504. unordered_set(_InputIterator __first, _InputIterator __last,
  505. size_type __n, const hasher& __hf, const allocator_type& __a)
  506. : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
  507. #endif
  508. _LIBCPP_INLINE_VISIBILITY
  509. explicit unordered_set(const allocator_type& __a);
  510. unordered_set(const unordered_set& __u);
  511. unordered_set(const unordered_set& __u, const allocator_type& __a);
  512. #ifndef _LIBCPP_CXX03_LANG
  513. _LIBCPP_INLINE_VISIBILITY
  514. unordered_set(unordered_set&& __u)
  515. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
  516. unordered_set(unordered_set&& __u, const allocator_type& __a);
  517. unordered_set(initializer_list<value_type> __il);
  518. unordered_set(initializer_list<value_type> __il, size_type __n,
  519. const hasher& __hf = hasher(),
  520. const key_equal& __eql = key_equal());
  521. unordered_set(initializer_list<value_type> __il, size_type __n,
  522. const hasher& __hf, const key_equal& __eql,
  523. const allocator_type& __a);
  524. #if _LIBCPP_STD_VER > 11
  525. inline _LIBCPP_INLINE_VISIBILITY
  526. unordered_set(initializer_list<value_type> __il, size_type __n,
  527. const allocator_type& __a)
  528. : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
  529. inline _LIBCPP_INLINE_VISIBILITY
  530. unordered_set(initializer_list<value_type> __il, size_type __n,
  531. const hasher& __hf, const allocator_type& __a)
  532. : unordered_set(__il, __n, __hf, key_equal(), __a) {}
  533. #endif
  534. #endif // _LIBCPP_CXX03_LANG
  535. _LIBCPP_INLINE_VISIBILITY
  536. ~unordered_set() {
  537. static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
  538. }
  539. _LIBCPP_INLINE_VISIBILITY
  540. unordered_set& operator=(const unordered_set& __u)
  541. {
  542. __table_ = __u.__table_;
  543. return *this;
  544. }
  545. #ifndef _LIBCPP_CXX03_LANG
  546. _LIBCPP_INLINE_VISIBILITY
  547. unordered_set& operator=(unordered_set&& __u)
  548. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
  549. _LIBCPP_INLINE_VISIBILITY
  550. unordered_set& operator=(initializer_list<value_type> __il);
  551. #endif // _LIBCPP_CXX03_LANG
  552. _LIBCPP_INLINE_VISIBILITY
  553. allocator_type get_allocator() const _NOEXCEPT
  554. {return allocator_type(__table_.__node_alloc());}
  555. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  556. bool empty() const _NOEXCEPT {return __table_.size() == 0;}
  557. _LIBCPP_INLINE_VISIBILITY
  558. size_type size() const _NOEXCEPT {return __table_.size();}
  559. _LIBCPP_INLINE_VISIBILITY
  560. size_type max_size() const _NOEXCEPT {return __table_.max_size();}
  561. _LIBCPP_INLINE_VISIBILITY
  562. iterator begin() _NOEXCEPT {return __table_.begin();}
  563. _LIBCPP_INLINE_VISIBILITY
  564. iterator end() _NOEXCEPT {return __table_.end();}
  565. _LIBCPP_INLINE_VISIBILITY
  566. const_iterator begin() const _NOEXCEPT {return __table_.begin();}
  567. _LIBCPP_INLINE_VISIBILITY
  568. const_iterator end() const _NOEXCEPT {return __table_.end();}
  569. _LIBCPP_INLINE_VISIBILITY
  570. const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
  571. _LIBCPP_INLINE_VISIBILITY
  572. const_iterator cend() const _NOEXCEPT {return __table_.end();}
  573. #ifndef _LIBCPP_CXX03_LANG
  574. template <class... _Args>
  575. _LIBCPP_INLINE_VISIBILITY
  576. pair<iterator, bool> emplace(_Args&&... __args)
  577. {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
  578. template <class... _Args>
  579. _LIBCPP_INLINE_VISIBILITY
  580. iterator emplace_hint(const_iterator __p, _Args&&... __args) {
  581. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this,
  582. "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
  583. " referring to this unordered_set");
  584. (void)__p;
  585. return __table_.__emplace_unique(std::forward<_Args>(__args)...).first;
  586. }
  587. _LIBCPP_INLINE_VISIBILITY
  588. pair<iterator, bool> insert(value_type&& __x)
  589. {return __table_.__insert_unique(_VSTD::move(__x));}
  590. _LIBCPP_INLINE_VISIBILITY
  591. iterator insert(const_iterator __p, value_type&& __x) {
  592. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this,
  593. "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
  594. " referring to this unordered_set");
  595. (void)__p;
  596. return insert(std::move(__x)).first;
  597. }
  598. _LIBCPP_INLINE_VISIBILITY
  599. void insert(initializer_list<value_type> __il)
  600. {insert(__il.begin(), __il.end());}
  601. #endif // _LIBCPP_CXX03_LANG
  602. _LIBCPP_INLINE_VISIBILITY
  603. pair<iterator, bool> insert(const value_type& __x)
  604. {return __table_.__insert_unique(__x);}
  605. _LIBCPP_INLINE_VISIBILITY
  606. iterator insert(const_iterator __p, const value_type& __x) {
  607. _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this,
  608. "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
  609. " referring to this unordered_set");
  610. (void)__p;
  611. return insert(__x).first;
  612. }
  613. template <class _InputIterator>
  614. _LIBCPP_INLINE_VISIBILITY
  615. void insert(_InputIterator __first, _InputIterator __last);
  616. _LIBCPP_INLINE_VISIBILITY
  617. iterator erase(const_iterator __p) {return __table_.erase(__p);}
  618. _LIBCPP_INLINE_VISIBILITY
  619. size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
  620. _LIBCPP_INLINE_VISIBILITY
  621. iterator erase(const_iterator __first, const_iterator __last)
  622. {return __table_.erase(__first, __last);}
  623. _LIBCPP_INLINE_VISIBILITY
  624. void clear() _NOEXCEPT {__table_.clear();}
  625. #if _LIBCPP_STD_VER > 14
  626. _LIBCPP_INLINE_VISIBILITY
  627. insert_return_type insert(node_type&& __nh)
  628. {
  629. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  630. "node_type with incompatible allocator passed to unordered_set::insert()");
  631. return __table_.template __node_handle_insert_unique<
  632. node_type, insert_return_type>(_VSTD::move(__nh));
  633. }
  634. _LIBCPP_INLINE_VISIBILITY
  635. iterator insert(const_iterator __h, node_type&& __nh)
  636. {
  637. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  638. "node_type with incompatible allocator passed to unordered_set::insert()");
  639. return __table_.template __node_handle_insert_unique<node_type>(
  640. __h, _VSTD::move(__nh));
  641. }
  642. _LIBCPP_INLINE_VISIBILITY
  643. node_type extract(key_type const& __key)
  644. {
  645. return __table_.template __node_handle_extract<node_type>(__key);
  646. }
  647. _LIBCPP_INLINE_VISIBILITY
  648. node_type extract(const_iterator __it)
  649. {
  650. return __table_.template __node_handle_extract<node_type>(__it);
  651. }
  652. template<class _H2, class _P2>
  653. _LIBCPP_INLINE_VISIBILITY
  654. void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
  655. {
  656. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  657. "merging container with incompatible allocator");
  658. __table_.__node_handle_merge_unique(__source.__table_);
  659. }
  660. template<class _H2, class _P2>
  661. _LIBCPP_INLINE_VISIBILITY
  662. void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
  663. {
  664. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  665. "merging container with incompatible allocator");
  666. __table_.__node_handle_merge_unique(__source.__table_);
  667. }
  668. template<class _H2, class _P2>
  669. _LIBCPP_INLINE_VISIBILITY
  670. void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
  671. {
  672. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  673. "merging container with incompatible allocator");
  674. __table_.__node_handle_merge_unique(__source.__table_);
  675. }
  676. template<class _H2, class _P2>
  677. _LIBCPP_INLINE_VISIBILITY
  678. void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
  679. {
  680. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  681. "merging container with incompatible allocator");
  682. __table_.__node_handle_merge_unique(__source.__table_);
  683. }
  684. #endif
  685. _LIBCPP_INLINE_VISIBILITY
  686. void swap(unordered_set& __u)
  687. _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
  688. {__table_.swap(__u.__table_);}
  689. _LIBCPP_INLINE_VISIBILITY
  690. hasher hash_function() const {return __table_.hash_function();}
  691. _LIBCPP_INLINE_VISIBILITY
  692. key_equal key_eq() const {return __table_.key_eq();}
  693. _LIBCPP_INLINE_VISIBILITY
  694. iterator find(const key_type& __k) {return __table_.find(__k);}
  695. _LIBCPP_INLINE_VISIBILITY
  696. const_iterator find(const key_type& __k) const {return __table_.find(__k);}
  697. #if _LIBCPP_STD_VER > 17
  698. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  699. _LIBCPP_INLINE_VISIBILITY
  700. iterator find(const _K2& __k) {return __table_.find(__k);}
  701. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  702. _LIBCPP_INLINE_VISIBILITY
  703. const_iterator find(const _K2& __k) const {return __table_.find(__k);}
  704. #endif // _LIBCPP_STD_VER > 17
  705. _LIBCPP_INLINE_VISIBILITY
  706. size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
  707. #if _LIBCPP_STD_VER > 17
  708. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  709. _LIBCPP_INLINE_VISIBILITY
  710. size_type count(const _K2& __k) const {return __table_.__count_unique(__k);}
  711. #endif // _LIBCPP_STD_VER > 17
  712. #if _LIBCPP_STD_VER > 17
  713. _LIBCPP_INLINE_VISIBILITY
  714. bool contains(const key_type& __k) const {return find(__k) != end();}
  715. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  716. _LIBCPP_INLINE_VISIBILITY
  717. bool contains(const _K2& __k) const {return find(__k) != end();}
  718. #endif // _LIBCPP_STD_VER > 17
  719. _LIBCPP_INLINE_VISIBILITY
  720. pair<iterator, iterator> equal_range(const key_type& __k)
  721. {return __table_.__equal_range_unique(__k);}
  722. _LIBCPP_INLINE_VISIBILITY
  723. pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
  724. {return __table_.__equal_range_unique(__k);}
  725. #if _LIBCPP_STD_VER > 17
  726. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  727. _LIBCPP_INLINE_VISIBILITY
  728. pair<iterator, iterator> equal_range(const _K2& __k)
  729. {return __table_.__equal_range_unique(__k);}
  730. template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  731. _LIBCPP_INLINE_VISIBILITY
  732. pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
  733. {return __table_.__equal_range_unique(__k);}
  734. #endif // _LIBCPP_STD_VER > 17
  735. _LIBCPP_INLINE_VISIBILITY
  736. size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
  737. _LIBCPP_INLINE_VISIBILITY
  738. size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
  739. _LIBCPP_INLINE_VISIBILITY
  740. size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
  741. _LIBCPP_INLINE_VISIBILITY
  742. size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
  743. _LIBCPP_INLINE_VISIBILITY
  744. local_iterator begin(size_type __n) {return __table_.begin(__n);}
  745. _LIBCPP_INLINE_VISIBILITY
  746. local_iterator end(size_type __n) {return __table_.end(__n);}
  747. _LIBCPP_INLINE_VISIBILITY
  748. const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
  749. _LIBCPP_INLINE_VISIBILITY
  750. const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
  751. _LIBCPP_INLINE_VISIBILITY
  752. const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
  753. _LIBCPP_INLINE_VISIBILITY
  754. const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
  755. _LIBCPP_INLINE_VISIBILITY
  756. float load_factor() const _NOEXCEPT {return __table_.load_factor();}
  757. _LIBCPP_INLINE_VISIBILITY
  758. float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
  759. _LIBCPP_INLINE_VISIBILITY
  760. void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
  761. _LIBCPP_INLINE_VISIBILITY
  762. void rehash(size_type __n) {__table_.__rehash_unique(__n);}
  763. _LIBCPP_INLINE_VISIBILITY
  764. void reserve(size_type __n) {__table_.__reserve_unique(__n);}
  765. #ifdef _LIBCPP_ENABLE_DEBUG_MODE
  766. bool __dereferenceable(const const_iterator* __i) const
  767. {return __table_.__dereferenceable(__i);}
  768. bool __decrementable(const const_iterator* __i) const
  769. {return __table_.__decrementable(__i);}
  770. bool __addable(const const_iterator* __i, ptrdiff_t __n) const
  771. {return __table_.__addable(__i, __n);}
  772. bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
  773. {return __table_.__addable(__i, __n);}
  774. #endif // _LIBCPP_ENABLE_DEBUG_MODE
  775. };
  776. #if _LIBCPP_STD_VER >= 17
  777. template<class _InputIterator,
  778. class _Hash = hash<__iter_value_type<_InputIterator>>,
  779. class _Pred = equal_to<__iter_value_type<_InputIterator>>,
  780. class _Allocator = allocator<__iter_value_type<_InputIterator>>,
  781. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  782. class = enable_if_t<!__is_allocator<_Hash>::value>,
  783. class = enable_if_t<!is_integral<_Hash>::value>,
  784. class = enable_if_t<!__is_allocator<_Pred>::value>,
  785. class = enable_if_t<__is_allocator<_Allocator>::value>>
  786. unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
  787. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  788. -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
  789. template<class _Tp, class _Hash = hash<_Tp>,
  790. class _Pred = equal_to<_Tp>,
  791. class _Allocator = allocator<_Tp>,
  792. class = enable_if_t<!__is_allocator<_Hash>::value>,
  793. class = enable_if_t<!is_integral<_Hash>::value>,
  794. class = enable_if_t<!__is_allocator<_Pred>::value>,
  795. class = enable_if_t<__is_allocator<_Allocator>::value>>
  796. unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
  797. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  798. -> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
  799. template<class _InputIterator, class _Allocator,
  800. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  801. class = enable_if_t<__is_allocator<_Allocator>::value>>
  802. unordered_set(_InputIterator, _InputIterator,
  803. typename allocator_traits<_Allocator>::size_type, _Allocator)
  804. -> unordered_set<__iter_value_type<_InputIterator>,
  805. hash<__iter_value_type<_InputIterator>>,
  806. equal_to<__iter_value_type<_InputIterator>>,
  807. _Allocator>;
  808. template<class _InputIterator, class _Hash, class _Allocator,
  809. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  810. class = enable_if_t<!__is_allocator<_Hash>::value>,
  811. class = enable_if_t<!is_integral<_Hash>::value>,
  812. class = enable_if_t<__is_allocator<_Allocator>::value>>
  813. unordered_set(_InputIterator, _InputIterator,
  814. typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  815. -> unordered_set<__iter_value_type<_InputIterator>, _Hash,
  816. equal_to<__iter_value_type<_InputIterator>>,
  817. _Allocator>;
  818. template<class _Tp, class _Allocator,
  819. class = enable_if_t<__is_allocator<_Allocator>::value>>
  820. unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
  821. -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
  822. template<class _Tp, class _Hash, class _Allocator,
  823. class = enable_if_t<!__is_allocator<_Hash>::value>,
  824. class = enable_if_t<!is_integral<_Hash>::value>,
  825. class = enable_if_t<__is_allocator<_Allocator>::value>>
  826. unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  827. -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
  828. #endif
  829. template <class _Value, class _Hash, class _Pred, class _Alloc>
  830. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
  831. const hasher& __hf, const key_equal& __eql)
  832. : __table_(__hf, __eql)
  833. {
  834. _VSTD::__debug_db_insert_c(this);
  835. __table_.__rehash_unique(__n);
  836. }
  837. template <class _Value, class _Hash, class _Pred, class _Alloc>
  838. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
  839. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  840. : __table_(__hf, __eql, __a)
  841. {
  842. _VSTD::__debug_db_insert_c(this);
  843. __table_.__rehash_unique(__n);
  844. }
  845. template <class _Value, class _Hash, class _Pred, class _Alloc>
  846. template <class _InputIterator>
  847. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  848. _InputIterator __first, _InputIterator __last)
  849. {
  850. _VSTD::__debug_db_insert_c(this);
  851. insert(__first, __last);
  852. }
  853. template <class _Value, class _Hash, class _Pred, class _Alloc>
  854. template <class _InputIterator>
  855. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  856. _InputIterator __first, _InputIterator __last, size_type __n,
  857. const hasher& __hf, const key_equal& __eql)
  858. : __table_(__hf, __eql)
  859. {
  860. _VSTD::__debug_db_insert_c(this);
  861. __table_.__rehash_unique(__n);
  862. insert(__first, __last);
  863. }
  864. template <class _Value, class _Hash, class _Pred, class _Alloc>
  865. template <class _InputIterator>
  866. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  867. _InputIterator __first, _InputIterator __last, size_type __n,
  868. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  869. : __table_(__hf, __eql, __a)
  870. {
  871. _VSTD::__debug_db_insert_c(this);
  872. __table_.__rehash_unique(__n);
  873. insert(__first, __last);
  874. }
  875. template <class _Value, class _Hash, class _Pred, class _Alloc>
  876. inline
  877. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  878. const allocator_type& __a)
  879. : __table_(__a)
  880. {
  881. _VSTD::__debug_db_insert_c(this);
  882. }
  883. template <class _Value, class _Hash, class _Pred, class _Alloc>
  884. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  885. const unordered_set& __u)
  886. : __table_(__u.__table_)
  887. {
  888. _VSTD::__debug_db_insert_c(this);
  889. __table_.__rehash_unique(__u.bucket_count());
  890. insert(__u.begin(), __u.end());
  891. }
  892. template <class _Value, class _Hash, class _Pred, class _Alloc>
  893. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  894. const unordered_set& __u, const allocator_type& __a)
  895. : __table_(__u.__table_, __a)
  896. {
  897. _VSTD::__debug_db_insert_c(this);
  898. __table_.__rehash_unique(__u.bucket_count());
  899. insert(__u.begin(), __u.end());
  900. }
  901. #ifndef _LIBCPP_CXX03_LANG
  902. template <class _Value, class _Hash, class _Pred, class _Alloc>
  903. inline
  904. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  905. unordered_set&& __u)
  906. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
  907. : __table_(_VSTD::move(__u.__table_))
  908. {
  909. _VSTD::__debug_db_insert_c(this);
  910. std::__debug_db_swap(this, std::addressof(__u));
  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. else
  925. std::__debug_db_swap(this, std::addressof(__u));
  926. }
  927. template <class _Value, class _Hash, class _Pred, class _Alloc>
  928. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  929. initializer_list<value_type> __il)
  930. {
  931. _VSTD::__debug_db_insert_c(this);
  932. insert(__il.begin(), __il.end());
  933. }
  934. template <class _Value, class _Hash, class _Pred, class _Alloc>
  935. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  936. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  937. const key_equal& __eql)
  938. : __table_(__hf, __eql)
  939. {
  940. _VSTD::__debug_db_insert_c(this);
  941. __table_.__rehash_unique(__n);
  942. insert(__il.begin(), __il.end());
  943. }
  944. template <class _Value, class _Hash, class _Pred, class _Alloc>
  945. unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
  946. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  947. const key_equal& __eql, const allocator_type& __a)
  948. : __table_(__hf, __eql, __a)
  949. {
  950. _VSTD::__debug_db_insert_c(this);
  951. __table_.__rehash_unique(__n);
  952. insert(__il.begin(), __il.end());
  953. }
  954. template <class _Value, class _Hash, class _Pred, class _Alloc>
  955. inline
  956. unordered_set<_Value, _Hash, _Pred, _Alloc>&
  957. unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
  958. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
  959. {
  960. __table_ = _VSTD::move(__u.__table_);
  961. return *this;
  962. }
  963. template <class _Value, class _Hash, class _Pred, class _Alloc>
  964. inline
  965. unordered_set<_Value, _Hash, _Pred, _Alloc>&
  966. unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
  967. initializer_list<value_type> __il)
  968. {
  969. __table_.__assign_unique(__il.begin(), __il.end());
  970. return *this;
  971. }
  972. #endif // _LIBCPP_CXX03_LANG
  973. template <class _Value, class _Hash, class _Pred, class _Alloc>
  974. template <class _InputIterator>
  975. inline
  976. void
  977. unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
  978. _InputIterator __last)
  979. {
  980. for (; __first != __last; ++__first)
  981. __table_.__insert_unique(*__first);
  982. }
  983. template <class _Value, class _Hash, class _Pred, class _Alloc>
  984. inline _LIBCPP_INLINE_VISIBILITY
  985. void
  986. swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  987. unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  988. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  989. {
  990. __x.swap(__y);
  991. }
  992. #if _LIBCPP_STD_VER > 17
  993. template <class _Value, class _Hash, class _Pred, class _Alloc,
  994. class _Predicate>
  995. inline _LIBCPP_INLINE_VISIBILITY
  996. typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type
  997. erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c,
  998. _Predicate __pred) {
  999. return _VSTD::__libcpp_erase_if_container(__c, __pred);
  1000. }
  1001. #endif
  1002. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1003. _LIBCPP_HIDE_FROM_ABI bool
  1004. operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  1005. const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  1006. {
  1007. if (__x.size() != __y.size())
  1008. return false;
  1009. typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
  1010. const_iterator;
  1011. for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
  1012. __i != __ex; ++__i)
  1013. {
  1014. const_iterator __j = __y.find(*__i);
  1015. if (__j == __ey || !(*__i == *__j))
  1016. return false;
  1017. }
  1018. return true;
  1019. }
  1020. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1021. inline _LIBCPP_INLINE_VISIBILITY
  1022. bool
  1023. operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  1024. const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  1025. {
  1026. return !(__x == __y);
  1027. }
  1028. template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
  1029. class _Alloc = allocator<_Value> >
  1030. class _LIBCPP_TEMPLATE_VIS unordered_multiset
  1031. {
  1032. public:
  1033. // types
  1034. typedef _Value key_type;
  1035. typedef key_type value_type;
  1036. typedef __type_identity_t<_Hash> hasher;
  1037. typedef __type_identity_t<_Pred> key_equal;
  1038. typedef __type_identity_t<_Alloc> allocator_type;
  1039. typedef value_type& reference;
  1040. typedef const value_type& const_reference;
  1041. static_assert((is_same<value_type, typename allocator_type::value_type>::value),
  1042. "Invalid allocator::value_type");
  1043. private:
  1044. typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
  1045. __table __table_;
  1046. public:
  1047. typedef typename __table::pointer pointer;
  1048. typedef typename __table::const_pointer const_pointer;
  1049. typedef typename __table::size_type size_type;
  1050. typedef typename __table::difference_type difference_type;
  1051. typedef typename __table::const_iterator iterator;
  1052. typedef typename __table::const_iterator const_iterator;
  1053. typedef typename __table::const_local_iterator local_iterator;
  1054. typedef typename __table::const_local_iterator const_local_iterator;
  1055. #if _LIBCPP_STD_VER > 14
  1056. typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
  1057. #endif
  1058. template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
  1059. friend class _LIBCPP_TEMPLATE_VIS unordered_set;
  1060. template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
  1061. friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
  1062. _LIBCPP_INLINE_VISIBILITY
  1063. unordered_multiset()
  1064. _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
  1065. {
  1066. _VSTD::__debug_db_insert_c(this);
  1067. }
  1068. explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
  1069. const key_equal& __eql = key_equal());
  1070. unordered_multiset(size_type __n, const hasher& __hf,
  1071. const key_equal& __eql, const allocator_type& __a);
  1072. #if _LIBCPP_STD_VER > 11
  1073. inline _LIBCPP_INLINE_VISIBILITY
  1074. unordered_multiset(size_type __n, const allocator_type& __a)
  1075. : unordered_multiset(__n, hasher(), key_equal(), __a) {}
  1076. inline _LIBCPP_INLINE_VISIBILITY
  1077. unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
  1078. : unordered_multiset(__n, __hf, key_equal(), __a) {}
  1079. #endif
  1080. template <class _InputIterator>
  1081. unordered_multiset(_InputIterator __first, _InputIterator __last);
  1082. template <class _InputIterator>
  1083. unordered_multiset(_InputIterator __first, _InputIterator __last,
  1084. size_type __n, const hasher& __hf = hasher(),
  1085. const key_equal& __eql = key_equal());
  1086. template <class _InputIterator>
  1087. unordered_multiset(_InputIterator __first, _InputIterator __last,
  1088. size_type __n , const hasher& __hf,
  1089. const key_equal& __eql, const allocator_type& __a);
  1090. #if _LIBCPP_STD_VER > 11
  1091. template <class _InputIterator>
  1092. inline _LIBCPP_INLINE_VISIBILITY
  1093. unordered_multiset(_InputIterator __first, _InputIterator __last,
  1094. size_type __n, const allocator_type& __a)
  1095. : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
  1096. template <class _InputIterator>
  1097. inline _LIBCPP_INLINE_VISIBILITY
  1098. unordered_multiset(_InputIterator __first, _InputIterator __last,
  1099. size_type __n, const hasher& __hf, const allocator_type& __a)
  1100. : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
  1101. #endif
  1102. _LIBCPP_INLINE_VISIBILITY
  1103. explicit unordered_multiset(const allocator_type& __a);
  1104. unordered_multiset(const unordered_multiset& __u);
  1105. unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
  1106. #ifndef _LIBCPP_CXX03_LANG
  1107. _LIBCPP_INLINE_VISIBILITY
  1108. unordered_multiset(unordered_multiset&& __u)
  1109. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
  1110. unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
  1111. unordered_multiset(initializer_list<value_type> __il);
  1112. unordered_multiset(initializer_list<value_type> __il, size_type __n,
  1113. const hasher& __hf = hasher(),
  1114. const key_equal& __eql = key_equal());
  1115. unordered_multiset(initializer_list<value_type> __il, size_type __n,
  1116. const hasher& __hf, const key_equal& __eql,
  1117. const allocator_type& __a);
  1118. #if _LIBCPP_STD_VER > 11
  1119. inline _LIBCPP_INLINE_VISIBILITY
  1120. unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
  1121. : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
  1122. inline _LIBCPP_INLINE_VISIBILITY
  1123. unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
  1124. : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
  1125. #endif
  1126. #endif // _LIBCPP_CXX03_LANG
  1127. _LIBCPP_INLINE_VISIBILITY
  1128. ~unordered_multiset() {
  1129. static_assert(sizeof(std::__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
  1130. }
  1131. _LIBCPP_INLINE_VISIBILITY
  1132. unordered_multiset& operator=(const unordered_multiset& __u)
  1133. {
  1134. __table_ = __u.__table_;
  1135. return *this;
  1136. }
  1137. #ifndef _LIBCPP_CXX03_LANG
  1138. _LIBCPP_INLINE_VISIBILITY
  1139. unordered_multiset& operator=(unordered_multiset&& __u)
  1140. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
  1141. unordered_multiset& operator=(initializer_list<value_type> __il);
  1142. #endif // _LIBCPP_CXX03_LANG
  1143. _LIBCPP_INLINE_VISIBILITY
  1144. allocator_type get_allocator() const _NOEXCEPT
  1145. {return allocator_type(__table_.__node_alloc());}
  1146. _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
  1147. bool empty() const _NOEXCEPT {return __table_.size() == 0;}
  1148. _LIBCPP_INLINE_VISIBILITY
  1149. size_type size() const _NOEXCEPT {return __table_.size();}
  1150. _LIBCPP_INLINE_VISIBILITY
  1151. size_type max_size() const _NOEXCEPT {return __table_.max_size();}
  1152. _LIBCPP_INLINE_VISIBILITY
  1153. iterator begin() _NOEXCEPT {return __table_.begin();}
  1154. _LIBCPP_INLINE_VISIBILITY
  1155. iterator end() _NOEXCEPT {return __table_.end();}
  1156. _LIBCPP_INLINE_VISIBILITY
  1157. const_iterator begin() const _NOEXCEPT {return __table_.begin();}
  1158. _LIBCPP_INLINE_VISIBILITY
  1159. const_iterator end() const _NOEXCEPT {return __table_.end();}
  1160. _LIBCPP_INLINE_VISIBILITY
  1161. const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
  1162. _LIBCPP_INLINE_VISIBILITY
  1163. const_iterator cend() const _NOEXCEPT {return __table_.end();}
  1164. #ifndef _LIBCPP_CXX03_LANG
  1165. template <class... _Args>
  1166. _LIBCPP_INLINE_VISIBILITY
  1167. iterator emplace(_Args&&... __args)
  1168. {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
  1169. template <class... _Args>
  1170. _LIBCPP_INLINE_VISIBILITY
  1171. iterator emplace_hint(const_iterator __p, _Args&&... __args)
  1172. {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
  1173. _LIBCPP_INLINE_VISIBILITY
  1174. iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
  1175. _LIBCPP_INLINE_VISIBILITY
  1176. iterator insert(const_iterator __p, value_type&& __x)
  1177. {return __table_.__insert_multi(__p, _VSTD::move(__x));}
  1178. _LIBCPP_INLINE_VISIBILITY
  1179. void insert(initializer_list<value_type> __il)
  1180. {insert(__il.begin(), __il.end());}
  1181. #endif // _LIBCPP_CXX03_LANG
  1182. _LIBCPP_INLINE_VISIBILITY
  1183. iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
  1184. _LIBCPP_INLINE_VISIBILITY
  1185. iterator insert(const_iterator __p, const value_type& __x)
  1186. {return __table_.__insert_multi(__p, __x);}
  1187. template <class _InputIterator>
  1188. _LIBCPP_INLINE_VISIBILITY
  1189. void insert(_InputIterator __first, _InputIterator __last);
  1190. #if _LIBCPP_STD_VER > 14
  1191. _LIBCPP_INLINE_VISIBILITY
  1192. iterator insert(node_type&& __nh)
  1193. {
  1194. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1195. "node_type with incompatible allocator passed to unordered_multiset::insert()");
  1196. return __table_.template __node_handle_insert_multi<node_type>(
  1197. _VSTD::move(__nh));
  1198. }
  1199. _LIBCPP_INLINE_VISIBILITY
  1200. iterator insert(const_iterator __hint, node_type&& __nh)
  1201. {
  1202. _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
  1203. "node_type with incompatible allocator passed to unordered_multiset::insert()");
  1204. return __table_.template __node_handle_insert_multi<node_type>(
  1205. __hint, _VSTD::move(__nh));
  1206. }
  1207. _LIBCPP_INLINE_VISIBILITY
  1208. node_type extract(const_iterator __position)
  1209. {
  1210. return __table_.template __node_handle_extract<node_type>(
  1211. __position);
  1212. }
  1213. _LIBCPP_INLINE_VISIBILITY
  1214. node_type extract(key_type const& __key)
  1215. {
  1216. return __table_.template __node_handle_extract<node_type>(__key);
  1217. }
  1218. template <class _H2, class _P2>
  1219. _LIBCPP_INLINE_VISIBILITY
  1220. void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
  1221. {
  1222. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1223. "merging container with incompatible allocator");
  1224. return __table_.__node_handle_merge_multi(__source.__table_);
  1225. }
  1226. template <class _H2, class _P2>
  1227. _LIBCPP_INLINE_VISIBILITY
  1228. void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
  1229. {
  1230. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1231. "merging container with incompatible allocator");
  1232. return __table_.__node_handle_merge_multi(__source.__table_);
  1233. }
  1234. template <class _H2, class _P2>
  1235. _LIBCPP_INLINE_VISIBILITY
  1236. void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
  1237. {
  1238. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1239. "merging container with incompatible allocator");
  1240. return __table_.__node_handle_merge_multi(__source.__table_);
  1241. }
  1242. template <class _H2, class _P2>
  1243. _LIBCPP_INLINE_VISIBILITY
  1244. void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
  1245. {
  1246. _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
  1247. "merging container with incompatible allocator");
  1248. return __table_.__node_handle_merge_multi(__source.__table_);
  1249. }
  1250. #endif
  1251. _LIBCPP_INLINE_VISIBILITY
  1252. iterator erase(const_iterator __p) {return __table_.erase(__p);}
  1253. _LIBCPP_INLINE_VISIBILITY
  1254. size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
  1255. _LIBCPP_INLINE_VISIBILITY
  1256. iterator erase(const_iterator __first, const_iterator __last)
  1257. {return __table_.erase(__first, __last);}
  1258. _LIBCPP_INLINE_VISIBILITY
  1259. void clear() _NOEXCEPT {__table_.clear();}
  1260. _LIBCPP_INLINE_VISIBILITY
  1261. void swap(unordered_multiset& __u)
  1262. _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
  1263. {__table_.swap(__u.__table_);}
  1264. _LIBCPP_INLINE_VISIBILITY
  1265. hasher hash_function() const {return __table_.hash_function();}
  1266. _LIBCPP_INLINE_VISIBILITY
  1267. key_equal key_eq() const {return __table_.key_eq();}
  1268. _LIBCPP_INLINE_VISIBILITY
  1269. iterator find(const key_type& __k) {return __table_.find(__k);}
  1270. _LIBCPP_INLINE_VISIBILITY
  1271. const_iterator find(const key_type& __k) const {return __table_.find(__k);}
  1272. #if _LIBCPP_STD_VER > 17
  1273. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1274. _LIBCPP_INLINE_VISIBILITY
  1275. iterator find(const _K2& __k) {return __table_.find(__k);}
  1276. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1277. _LIBCPP_INLINE_VISIBILITY
  1278. const_iterator find(const _K2& __k) const {return __table_.find(__k);}
  1279. #endif // _LIBCPP_STD_VER > 17
  1280. _LIBCPP_INLINE_VISIBILITY
  1281. size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
  1282. #if _LIBCPP_STD_VER > 17
  1283. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1284. _LIBCPP_INLINE_VISIBILITY
  1285. size_type count(const _K2& __k) const {return __table_.__count_multi(__k);}
  1286. #endif // _LIBCPP_STD_VER > 17
  1287. #if _LIBCPP_STD_VER > 17
  1288. _LIBCPP_INLINE_VISIBILITY
  1289. bool contains(const key_type& __k) const {return find(__k) != end();}
  1290. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1291. _LIBCPP_INLINE_VISIBILITY
  1292. bool contains(const _K2& __k) const {return find(__k) != end();}
  1293. #endif // _LIBCPP_STD_VER > 17
  1294. _LIBCPP_INLINE_VISIBILITY
  1295. pair<iterator, iterator> equal_range(const key_type& __k)
  1296. {return __table_.__equal_range_multi(__k);}
  1297. _LIBCPP_INLINE_VISIBILITY
  1298. pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
  1299. {return __table_.__equal_range_multi(__k);}
  1300. #if _LIBCPP_STD_VER > 17
  1301. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1302. _LIBCPP_INLINE_VISIBILITY
  1303. pair<iterator, iterator> equal_range(const _K2& __k)
  1304. {return __table_.__equal_range_multi(__k);}
  1305. template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
  1306. _LIBCPP_INLINE_VISIBILITY
  1307. pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
  1308. {return __table_.__equal_range_multi(__k);}
  1309. #endif // _LIBCPP_STD_VER > 17
  1310. _LIBCPP_INLINE_VISIBILITY
  1311. size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
  1312. _LIBCPP_INLINE_VISIBILITY
  1313. size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
  1314. _LIBCPP_INLINE_VISIBILITY
  1315. size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
  1316. _LIBCPP_INLINE_VISIBILITY
  1317. size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
  1318. _LIBCPP_INLINE_VISIBILITY
  1319. local_iterator begin(size_type __n) {return __table_.begin(__n);}
  1320. _LIBCPP_INLINE_VISIBILITY
  1321. local_iterator end(size_type __n) {return __table_.end(__n);}
  1322. _LIBCPP_INLINE_VISIBILITY
  1323. const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
  1324. _LIBCPP_INLINE_VISIBILITY
  1325. const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
  1326. _LIBCPP_INLINE_VISIBILITY
  1327. const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
  1328. _LIBCPP_INLINE_VISIBILITY
  1329. const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
  1330. _LIBCPP_INLINE_VISIBILITY
  1331. float load_factor() const _NOEXCEPT {return __table_.load_factor();}
  1332. _LIBCPP_INLINE_VISIBILITY
  1333. float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
  1334. _LIBCPP_INLINE_VISIBILITY
  1335. void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
  1336. _LIBCPP_INLINE_VISIBILITY
  1337. void rehash(size_type __n) {__table_.__rehash_multi(__n);}
  1338. _LIBCPP_INLINE_VISIBILITY
  1339. void reserve(size_type __n) {__table_.__reserve_multi(__n);}
  1340. #ifdef _LIBCPP_ENABLE_DEBUG_MODE
  1341. bool __dereferenceable(const const_iterator* __i) const
  1342. {return __table_.__dereferenceable(__i);}
  1343. bool __decrementable(const const_iterator* __i) const
  1344. {return __table_.__decrementable(__i);}
  1345. bool __addable(const const_iterator* __i, ptrdiff_t __n) const
  1346. {return __table_.__addable(__i, __n);}
  1347. bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
  1348. {return __table_.__addable(__i, __n);}
  1349. #endif // _LIBCPP_ENABLE_DEBUG_MODE
  1350. };
  1351. #if _LIBCPP_STD_VER >= 17
  1352. template<class _InputIterator,
  1353. class _Hash = hash<__iter_value_type<_InputIterator>>,
  1354. class _Pred = equal_to<__iter_value_type<_InputIterator>>,
  1355. class _Allocator = allocator<__iter_value_type<_InputIterator>>,
  1356. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  1357. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1358. class = enable_if_t<!is_integral<_Hash>::value>,
  1359. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1360. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1361. unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
  1362. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  1363. -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
  1364. template<class _Tp, class _Hash = hash<_Tp>,
  1365. class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>,
  1366. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1367. class = enable_if_t<!is_integral<_Hash>::value>,
  1368. class = enable_if_t<!__is_allocator<_Pred>::value>,
  1369. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1370. unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
  1371. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  1372. -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
  1373. template<class _InputIterator, class _Allocator,
  1374. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  1375. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1376. unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1377. -> unordered_multiset<__iter_value_type<_InputIterator>,
  1378. hash<__iter_value_type<_InputIterator>>,
  1379. equal_to<__iter_value_type<_InputIterator>>,
  1380. _Allocator>;
  1381. template<class _InputIterator, class _Hash, class _Allocator,
  1382. class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
  1383. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1384. class = enable_if_t<!is_integral<_Hash>::value>,
  1385. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1386. unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type,
  1387. _Hash, _Allocator)
  1388. -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash,
  1389. equal_to<__iter_value_type<_InputIterator>>,
  1390. _Allocator>;
  1391. template<class _Tp, class _Allocator,
  1392. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1393. unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
  1394. -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
  1395. template<class _Tp, class _Hash, class _Allocator,
  1396. class = enable_if_t<!__is_allocator<_Hash>::value>,
  1397. class = enable_if_t<!is_integral<_Hash>::value>,
  1398. class = enable_if_t<__is_allocator<_Allocator>::value>>
  1399. unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
  1400. -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
  1401. #endif
  1402. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1403. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1404. size_type __n, const hasher& __hf, const key_equal& __eql)
  1405. : __table_(__hf, __eql)
  1406. {
  1407. _VSTD::__debug_db_insert_c(this);
  1408. __table_.__rehash_multi(__n);
  1409. }
  1410. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1411. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1412. size_type __n, const hasher& __hf, const key_equal& __eql,
  1413. const allocator_type& __a)
  1414. : __table_(__hf, __eql, __a)
  1415. {
  1416. _VSTD::__debug_db_insert_c(this);
  1417. __table_.__rehash_multi(__n);
  1418. }
  1419. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1420. template <class _InputIterator>
  1421. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1422. _InputIterator __first, _InputIterator __last)
  1423. {
  1424. _VSTD::__debug_db_insert_c(this);
  1425. insert(__first, __last);
  1426. }
  1427. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1428. template <class _InputIterator>
  1429. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1430. _InputIterator __first, _InputIterator __last, size_type __n,
  1431. const hasher& __hf, const key_equal& __eql)
  1432. : __table_(__hf, __eql)
  1433. {
  1434. _VSTD::__debug_db_insert_c(this);
  1435. __table_.__rehash_multi(__n);
  1436. insert(__first, __last);
  1437. }
  1438. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1439. template <class _InputIterator>
  1440. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1441. _InputIterator __first, _InputIterator __last, size_type __n,
  1442. const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
  1443. : __table_(__hf, __eql, __a)
  1444. {
  1445. _VSTD::__debug_db_insert_c(this);
  1446. __table_.__rehash_multi(__n);
  1447. insert(__first, __last);
  1448. }
  1449. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1450. inline
  1451. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1452. const allocator_type& __a)
  1453. : __table_(__a)
  1454. {
  1455. _VSTD::__debug_db_insert_c(this);
  1456. }
  1457. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1458. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1459. const unordered_multiset& __u)
  1460. : __table_(__u.__table_)
  1461. {
  1462. _VSTD::__debug_db_insert_c(this);
  1463. __table_.__rehash_multi(__u.bucket_count());
  1464. insert(__u.begin(), __u.end());
  1465. }
  1466. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1467. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1468. const unordered_multiset& __u, const allocator_type& __a)
  1469. : __table_(__u.__table_, __a)
  1470. {
  1471. _VSTD::__debug_db_insert_c(this);
  1472. __table_.__rehash_multi(__u.bucket_count());
  1473. insert(__u.begin(), __u.end());
  1474. }
  1475. #ifndef _LIBCPP_CXX03_LANG
  1476. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1477. inline
  1478. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1479. unordered_multiset&& __u)
  1480. _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
  1481. : __table_(_VSTD::move(__u.__table_))
  1482. {
  1483. _VSTD::__debug_db_insert_c(this);
  1484. std::__debug_db_swap(this, std::addressof(__u));
  1485. }
  1486. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1487. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1488. unordered_multiset&& __u, const allocator_type& __a)
  1489. : __table_(_VSTD::move(__u.__table_), __a)
  1490. {
  1491. _VSTD::__debug_db_insert_c(this);
  1492. if (__a != __u.get_allocator())
  1493. {
  1494. iterator __i = __u.begin();
  1495. while (__u.size() != 0)
  1496. __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
  1497. }
  1498. else
  1499. std::__debug_db_swap(this, std::addressof(__u));
  1500. }
  1501. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1502. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1503. initializer_list<value_type> __il)
  1504. {
  1505. _VSTD::__debug_db_insert_c(this);
  1506. insert(__il.begin(), __il.end());
  1507. }
  1508. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1509. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1510. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  1511. const key_equal& __eql)
  1512. : __table_(__hf, __eql)
  1513. {
  1514. _VSTD::__debug_db_insert_c(this);
  1515. __table_.__rehash_multi(__n);
  1516. insert(__il.begin(), __il.end());
  1517. }
  1518. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1519. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
  1520. initializer_list<value_type> __il, size_type __n, const hasher& __hf,
  1521. const key_equal& __eql, const allocator_type& __a)
  1522. : __table_(__hf, __eql, __a)
  1523. {
  1524. _VSTD::__debug_db_insert_c(this);
  1525. __table_.__rehash_multi(__n);
  1526. insert(__il.begin(), __il.end());
  1527. }
  1528. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1529. inline
  1530. unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
  1531. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
  1532. unordered_multiset&& __u)
  1533. _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
  1534. {
  1535. __table_ = _VSTD::move(__u.__table_);
  1536. return *this;
  1537. }
  1538. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1539. inline
  1540. unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
  1541. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
  1542. initializer_list<value_type> __il)
  1543. {
  1544. __table_.__assign_multi(__il.begin(), __il.end());
  1545. return *this;
  1546. }
  1547. #endif // _LIBCPP_CXX03_LANG
  1548. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1549. template <class _InputIterator>
  1550. inline
  1551. void
  1552. unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
  1553. _InputIterator __last)
  1554. {
  1555. for (; __first != __last; ++__first)
  1556. __table_.__insert_multi(*__first);
  1557. }
  1558. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1559. inline _LIBCPP_INLINE_VISIBILITY
  1560. void
  1561. swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  1562. unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  1563. _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
  1564. {
  1565. __x.swap(__y);
  1566. }
  1567. #if _LIBCPP_STD_VER > 17
  1568. template <class _Value, class _Hash, class _Pred, class _Alloc,
  1569. class _Predicate>
  1570. inline _LIBCPP_INLINE_VISIBILITY
  1571. typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type
  1572. erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c,
  1573. _Predicate __pred) {
  1574. return _VSTD::__libcpp_erase_if_container(__c, __pred);
  1575. }
  1576. #endif
  1577. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1578. _LIBCPP_HIDE_FROM_ABI bool
  1579. operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  1580. const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  1581. {
  1582. if (__x.size() != __y.size())
  1583. return false;
  1584. typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
  1585. const_iterator;
  1586. typedef pair<const_iterator, const_iterator> _EqRng;
  1587. for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
  1588. {
  1589. _EqRng __xeq = __x.equal_range(*__i);
  1590. _EqRng __yeq = __y.equal_range(*__i);
  1591. if (_VSTD::distance(__xeq.first, __xeq.second) !=
  1592. _VSTD::distance(__yeq.first, __yeq.second) ||
  1593. !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
  1594. return false;
  1595. __i = __xeq.second;
  1596. }
  1597. return true;
  1598. }
  1599. template <class _Value, class _Hash, class _Pred, class _Alloc>
  1600. inline _LIBCPP_INLINE_VISIBILITY
  1601. bool
  1602. operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  1603. const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  1604. {
  1605. return !(__x == __y);
  1606. }
  1607. _LIBCPP_END_NAMESPACE_STD
  1608. #if _LIBCPP_STD_VER > 14
  1609. _LIBCPP_BEGIN_NAMESPACE_STD
  1610. namespace pmr {
  1611. template <class _KeyT, class _HashT = std::hash<_KeyT>, class _PredT = std::equal_to<_KeyT>>
  1612. using unordered_set = std::unordered_set<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>;
  1613. template <class _KeyT, class _HashT = std::hash<_KeyT>, class _PredT = std::equal_to<_KeyT>>
  1614. using unordered_multiset = std::unordered_multiset<_KeyT, _HashT, _PredT, polymorphic_allocator<_KeyT>>;
  1615. } // namespace pmr
  1616. _LIBCPP_END_NAMESPACE_STD
  1617. #endif
  1618. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  1619. # include <concepts>
  1620. # include <functional>
  1621. # include <iterator>
  1622. #endif
  1623. #endif // _LIBCPP_UNORDERED_SET