unordered_set 67 KB

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