unordered_set 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. // Debugging unordered_set/unordered_multiset implementation -*- C++ -*-
  2. // Copyright (C) 2003-2023 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file debug/unordered_set
  21. * This file is a GNU debug extension to the Standard C++ Library.
  22. */
  23. #ifndef _GLIBCXX_DEBUG_UNORDERED_SET
  24. #define _GLIBCXX_DEBUG_UNORDERED_SET 1
  25. #pragma GCC system_header
  26. #if __cplusplus < 201103L
  27. # include <bits/c++0x_warning.h>
  28. #else
  29. # include <bits/c++config.h>
  30. namespace std _GLIBCXX_VISIBILITY(default) { namespace __debug {
  31. template<typename _Key, typename _Hash, typename _Pred, typename _Allocator>
  32. class unordered_set;
  33. template<typename _Key, typename _Hash, typename _Pred, typename _Allocator>
  34. class unordered_multiset;
  35. } } // namespace std::__debug
  36. # include <unordered_set>
  37. #include <debug/safe_unordered_container.h>
  38. #include <debug/safe_container.h>
  39. #include <debug/safe_iterator.h>
  40. #include <debug/safe_local_iterator.h>
  41. namespace std _GLIBCXX_VISIBILITY(default)
  42. {
  43. namespace __debug
  44. {
  45. /// Class std::unordered_set with safety/checking/debug instrumentation.
  46. template<typename _Value,
  47. typename _Hash = std::hash<_Value>,
  48. typename _Pred = std::equal_to<_Value>,
  49. typename _Alloc = std::allocator<_Value> >
  50. class unordered_set
  51. : public __gnu_debug::_Safe_container<
  52. unordered_set<_Value, _Hash, _Pred, _Alloc>, _Alloc,
  53. __gnu_debug::_Safe_unordered_container>,
  54. public _GLIBCXX_STD_C::unordered_set<_Value, _Hash, _Pred, _Alloc>
  55. {
  56. typedef _GLIBCXX_STD_C::unordered_set<
  57. _Value, _Hash, _Pred, _Alloc> _Base;
  58. typedef __gnu_debug::_Safe_container<
  59. unordered_set, _Alloc, __gnu_debug::_Safe_unordered_container> _Safe;
  60. typedef typename _Base::const_iterator _Base_const_iterator;
  61. typedef typename _Base::iterator _Base_iterator;
  62. typedef typename _Base::const_local_iterator _Base_const_local_iterator;
  63. typedef typename _Base::local_iterator _Base_local_iterator;
  64. template<typename _ItT, typename _SeqT, typename _CatT>
  65. friend class ::__gnu_debug::_Safe_iterator;
  66. template<typename _ItT, typename _SeqT>
  67. friend class ::__gnu_debug::_Safe_local_iterator;
  68. // Reference wrapper for base class. See PR libstdc++/90102.
  69. struct _Base_ref
  70. {
  71. _Base_ref(const _Base& __r) : _M_ref(__r) { }
  72. const _Base& _M_ref;
  73. };
  74. public:
  75. typedef typename _Base::size_type size_type;
  76. typedef typename _Base::difference_type difference_type;
  77. typedef typename _Base::hasher hasher;
  78. typedef typename _Base::key_equal key_equal;
  79. typedef typename _Base::allocator_type allocator_type;
  80. typedef typename _Base::key_type key_type;
  81. typedef typename _Base::value_type value_type;
  82. typedef typename _Base::pointer pointer;
  83. typedef typename _Base::const_pointer const_pointer;
  84. typedef typename _Base::reference reference;
  85. typedef typename _Base::const_reference const_reference;
  86. typedef __gnu_debug::_Safe_iterator<
  87. _Base_iterator, unordered_set> iterator;
  88. typedef __gnu_debug::_Safe_iterator<
  89. _Base_const_iterator, unordered_set> const_iterator;
  90. typedef __gnu_debug::_Safe_local_iterator<
  91. _Base_local_iterator, unordered_set> local_iterator;
  92. typedef __gnu_debug::_Safe_local_iterator<
  93. _Base_const_local_iterator, unordered_set> const_local_iterator;
  94. unordered_set() = default;
  95. explicit
  96. unordered_set(size_type __n,
  97. const hasher& __hf = hasher(),
  98. const key_equal& __eql = key_equal(),
  99. const allocator_type& __a = allocator_type())
  100. : _Base(__n, __hf, __eql, __a) { }
  101. template<typename _InputIterator>
  102. unordered_set(_InputIterator __first, _InputIterator __last,
  103. size_type __n = 0,
  104. const hasher& __hf = hasher(),
  105. const key_equal& __eql = key_equal(),
  106. const allocator_type& __a = allocator_type())
  107. : _Base(__gnu_debug::__base(
  108. __glibcxx_check_valid_constructor_range(__first, __last)),
  109. __gnu_debug::__base(__last), __n,
  110. __hf, __eql, __a) { }
  111. unordered_set(const unordered_set&) = default;
  112. unordered_set(_Base_ref __x)
  113. : _Base(__x._M_ref) { }
  114. unordered_set(unordered_set&&) = default;
  115. explicit
  116. unordered_set(const allocator_type& __a)
  117. : _Base(__a) { }
  118. unordered_set(const unordered_set& __uset,
  119. const allocator_type& __a)
  120. : _Base(__uset, __a) { }
  121. unordered_set(unordered_set&& __uset,
  122. const allocator_type& __a)
  123. noexcept( noexcept(_Base(std::move(__uset), __a)) )
  124. : _Safe(std::move(__uset), __a),
  125. _Base(std::move(__uset), __a) { }
  126. unordered_set(initializer_list<value_type> __l,
  127. size_type __n = 0,
  128. const hasher& __hf = hasher(),
  129. const key_equal& __eql = key_equal(),
  130. const allocator_type& __a = allocator_type())
  131. : _Base(__l, __n, __hf, __eql, __a) { }
  132. unordered_set(size_type __n, const allocator_type& __a)
  133. : unordered_set(__n, hasher(), key_equal(), __a)
  134. { }
  135. unordered_set(size_type __n, const hasher& __hf,
  136. const allocator_type& __a)
  137. : unordered_set(__n, __hf, key_equal(), __a)
  138. { }
  139. template<typename _InputIterator>
  140. unordered_set(_InputIterator __first, _InputIterator __last,
  141. size_type __n,
  142. const allocator_type& __a)
  143. : unordered_set(__first, __last, __n, hasher(), key_equal(), __a)
  144. { }
  145. template<typename _InputIterator>
  146. unordered_set(_InputIterator __first, _InputIterator __last,
  147. size_type __n, const hasher& __hf,
  148. const allocator_type& __a)
  149. : unordered_set(__first, __last, __n, __hf, key_equal(), __a)
  150. { }
  151. unordered_set(initializer_list<value_type> __l,
  152. size_type __n,
  153. const allocator_type& __a)
  154. : unordered_set(__l, __n, hasher(), key_equal(), __a)
  155. { }
  156. unordered_set(initializer_list<value_type> __l,
  157. size_type __n, const hasher& __hf,
  158. const allocator_type& __a)
  159. : unordered_set(__l, __n, __hf, key_equal(), __a)
  160. { }
  161. ~unordered_set() = default;
  162. unordered_set&
  163. operator=(const unordered_set&) = default;
  164. unordered_set&
  165. operator=(unordered_set&&) = default;
  166. unordered_set&
  167. operator=(initializer_list<value_type> __l)
  168. {
  169. _Base::operator=(__l);
  170. this->_M_invalidate_all();
  171. return *this;
  172. }
  173. using _Base::get_allocator;
  174. using _Base::empty;
  175. using _Base::size;
  176. using _Base::max_size;
  177. void
  178. swap(unordered_set& __x)
  179. noexcept( noexcept(declval<_Base&>().swap(__x)) )
  180. {
  181. _Safe::_M_swap(__x);
  182. _Base::swap(__x);
  183. }
  184. void
  185. clear() noexcept
  186. {
  187. _Base::clear();
  188. this->_M_invalidate_all();
  189. }
  190. iterator
  191. begin() noexcept
  192. { return { _Base::begin(), this }; }
  193. const_iterator
  194. begin() const noexcept
  195. { return { _Base::begin(), this }; }
  196. iterator
  197. end() noexcept
  198. { return { _Base::end(), this }; }
  199. const_iterator
  200. end() const noexcept
  201. { return { _Base::end(), this }; }
  202. const_iterator
  203. cbegin() const noexcept
  204. { return { _Base::cbegin(), this }; }
  205. const_iterator
  206. cend() const noexcept
  207. { return { _Base::cend(), this }; }
  208. // local versions
  209. local_iterator
  210. begin(size_type __b)
  211. {
  212. __glibcxx_check_bucket_index(__b);
  213. return { _Base::begin(__b), this };
  214. }
  215. local_iterator
  216. end(size_type __b)
  217. {
  218. __glibcxx_check_bucket_index(__b);
  219. return { _Base::end(__b), this };
  220. }
  221. const_local_iterator
  222. begin(size_type __b) const
  223. {
  224. __glibcxx_check_bucket_index(__b);
  225. return { _Base::begin(__b), this };
  226. }
  227. const_local_iterator
  228. end(size_type __b) const
  229. {
  230. __glibcxx_check_bucket_index(__b);
  231. return { _Base::end(__b), this };
  232. }
  233. const_local_iterator
  234. cbegin(size_type __b) const
  235. {
  236. __glibcxx_check_bucket_index(__b);
  237. return { _Base::cbegin(__b), this };
  238. }
  239. const_local_iterator
  240. cend(size_type __b) const
  241. {
  242. __glibcxx_check_bucket_index(__b);
  243. return { _Base::cend(__b), this };
  244. }
  245. using _Base::bucket_count;
  246. using _Base::max_bucket_count;
  247. size_type
  248. bucket_size(size_type __b) const
  249. {
  250. __glibcxx_check_bucket_index(__b);
  251. return _Base::bucket_size(__b);
  252. }
  253. using _Base::bucket;
  254. using _Base::load_factor;
  255. float
  256. max_load_factor() const noexcept
  257. { return _Base::max_load_factor(); }
  258. void
  259. max_load_factor(float __f)
  260. {
  261. __glibcxx_check_max_load_factor(__f);
  262. _Base::max_load_factor(__f);
  263. }
  264. using _Base::rehash;
  265. using _Base::reserve;
  266. template<typename... _Args>
  267. std::pair<iterator, bool>
  268. emplace(_Args&&... __args)
  269. {
  270. size_type __bucket_count = this->bucket_count();
  271. auto __res = _Base::emplace(std::forward<_Args>(__args)...);
  272. _M_check_rehashed(__bucket_count);
  273. return { { __res.first, this }, __res.second };
  274. }
  275. template<typename... _Args>
  276. iterator
  277. emplace_hint(const_iterator __hint, _Args&&... __args)
  278. {
  279. __glibcxx_check_insert(__hint);
  280. size_type __bucket_count = this->bucket_count();
  281. auto __it = _Base::emplace_hint(__hint.base(),
  282. std::forward<_Args>(__args)...);
  283. _M_check_rehashed(__bucket_count);
  284. return { __it, this };
  285. }
  286. std::pair<iterator, bool>
  287. insert(const value_type& __obj)
  288. {
  289. size_type __bucket_count = this->bucket_count();
  290. auto __res = _Base::insert(__obj);
  291. _M_check_rehashed(__bucket_count);
  292. return { { __res.first, this }, __res.second };
  293. }
  294. iterator
  295. insert(const_iterator __hint, const value_type& __obj)
  296. {
  297. __glibcxx_check_insert(__hint);
  298. size_type __bucket_count = this->bucket_count();
  299. auto __it = _Base::insert(__hint.base(), __obj);
  300. _M_check_rehashed(__bucket_count);
  301. return { __it, this };
  302. }
  303. std::pair<iterator, bool>
  304. insert(value_type&& __obj)
  305. {
  306. size_type __bucket_count = this->bucket_count();
  307. auto __res = _Base::insert(std::move(__obj));
  308. _M_check_rehashed(__bucket_count);
  309. return { { __res.first, this }, __res.second };
  310. }
  311. iterator
  312. insert(const_iterator __hint, value_type&& __obj)
  313. {
  314. __glibcxx_check_insert(__hint);
  315. size_type __bucket_count = this->bucket_count();
  316. auto __it = _Base::insert(__hint.base(), std::move(__obj));
  317. _M_check_rehashed(__bucket_count);
  318. return { __it, this };
  319. }
  320. void
  321. insert(std::initializer_list<value_type> __l)
  322. {
  323. size_type __bucket_count = this->bucket_count();
  324. _Base::insert(__l);
  325. _M_check_rehashed(__bucket_count);
  326. }
  327. template<typename _InputIterator>
  328. void
  329. insert(_InputIterator __first, _InputIterator __last)
  330. {
  331. typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
  332. __glibcxx_check_valid_range2(__first, __last, __dist);
  333. size_type __bucket_count = this->bucket_count();
  334. if (__dist.second >= __gnu_debug::__dp_sign)
  335. _Base::insert(__gnu_debug::__unsafe(__first),
  336. __gnu_debug::__unsafe(__last));
  337. else
  338. _Base::insert(__first, __last);
  339. _M_check_rehashed(__bucket_count);
  340. }
  341. #if __cplusplus > 201402L
  342. using node_type = typename _Base::node_type;
  343. using insert_return_type = _Node_insert_return<iterator, node_type>;
  344. node_type
  345. extract(const_iterator __position)
  346. {
  347. __glibcxx_check_erase(__position);
  348. return _M_extract(__position.base());
  349. }
  350. node_type
  351. extract(const key_type& __key)
  352. {
  353. const auto __position = _Base::find(__key);
  354. if (__position != _Base::end())
  355. return _M_extract(__position);
  356. return {};
  357. }
  358. insert_return_type
  359. insert(node_type&& __nh)
  360. {
  361. auto __ret = _Base::insert(std::move(__nh));
  362. return
  363. { { __ret.position, this }, __ret.inserted, std::move(__ret.node) };
  364. }
  365. iterator
  366. insert(const_iterator __hint, node_type&& __nh)
  367. {
  368. __glibcxx_check_insert(__hint);
  369. return { _Base::insert(__hint.base(), std::move(__nh)), this };
  370. }
  371. template<typename _H2, typename _P2>
  372. void
  373. merge(unordered_set<_Value, _H2, _P2, _Alloc>& __source)
  374. {
  375. auto __guard
  376. = _Safe::_S_uc_guard(std::__detail::_Identity{}, __source);
  377. _Base::merge(__source);
  378. }
  379. template<typename _H2, typename _P2>
  380. void
  381. merge(unordered_set<_Value, _H2, _P2, _Alloc>&& __source)
  382. { merge(__source); }
  383. template<typename _H2, typename _P2>
  384. void
  385. merge(unordered_multiset<_Value, _H2, _P2, _Alloc>& __source)
  386. {
  387. auto __guard
  388. = _Safe::_S_umc_guard(std::__detail::_Identity{}, __source);
  389. _Base::merge(__source);
  390. }
  391. template<typename _H2, typename _P2>
  392. void
  393. merge(unordered_multiset<_Value, _H2, _P2, _Alloc>&& __source)
  394. { merge(__source); }
  395. #endif // C++17
  396. using _Base::hash_function;
  397. using _Base::key_eq;
  398. iterator
  399. find(const key_type& __key)
  400. { return { _Base::find(__key), this }; }
  401. #if __cplusplus > 201703L
  402. template<typename _Kt,
  403. typename = std::__has_is_transparent_t<_Hash, _Kt>,
  404. typename = std::__has_is_transparent_t<_Pred, _Kt>>
  405. iterator
  406. find(const _Kt& __k)
  407. { return { _Base::find(__k), this }; }
  408. #endif
  409. const_iterator
  410. find(const key_type& __key) const
  411. { return { _Base::find(__key), this }; }
  412. #if __cplusplus > 201703L
  413. template<typename _Kt,
  414. typename = std::__has_is_transparent_t<_Hash, _Kt>,
  415. typename = std::__has_is_transparent_t<_Pred, _Kt>>
  416. const_iterator
  417. find(const _Kt& __k) const
  418. { return { _Base::find(__k), this }; }
  419. #endif
  420. using _Base::count;
  421. #if __cplusplus > 201703L
  422. using _Base::contains;
  423. #endif
  424. std::pair<iterator, iterator>
  425. equal_range(const key_type& __key)
  426. {
  427. auto __res = _Base::equal_range(__key);
  428. return { { __res.first, this }, { __res.second, this } };
  429. }
  430. #if __cplusplus > 201703L
  431. template<typename _Kt,
  432. typename = std::__has_is_transparent_t<_Hash, _Kt>,
  433. typename = std::__has_is_transparent_t<_Pred, _Kt>>
  434. std::pair<iterator, iterator>
  435. equal_range(const _Kt& __k)
  436. {
  437. auto __res = _Base::equal_range(__k);
  438. return { { __res.first, this }, { __res.second, this } };
  439. }
  440. #endif
  441. std::pair<const_iterator, const_iterator>
  442. equal_range(const key_type& __key) const
  443. {
  444. auto __res = _Base::equal_range(__key);
  445. return { { __res.first, this }, { __res.second, this } };
  446. }
  447. #if __cplusplus > 201703L
  448. template<typename _Kt,
  449. typename = std::__has_is_transparent_t<_Hash, _Kt>,
  450. typename = std::__has_is_transparent_t<_Pred, _Kt>>
  451. std::pair<const_iterator, const_iterator>
  452. equal_range(const _Kt& __k) const
  453. {
  454. auto __res = _Base::equal_range(__k);
  455. return { { __res.first, this }, { __res.second, this } };
  456. }
  457. #endif
  458. size_type
  459. erase(const key_type& __key)
  460. {
  461. size_type __ret(0);
  462. auto __victim = _Base::find(__key);
  463. if (__victim != _Base::end())
  464. {
  465. _M_erase(__victim);
  466. __ret = 1;
  467. }
  468. return __ret;
  469. }
  470. iterator
  471. erase(const_iterator __it)
  472. {
  473. __glibcxx_check_erase(__it);
  474. return { _M_erase(__it.base()), this };
  475. }
  476. _Base_iterator
  477. erase(_Base_const_iterator __it)
  478. {
  479. __glibcxx_check_erase2(__it);
  480. return _M_erase(__it);
  481. }
  482. iterator
  483. erase(iterator __it)
  484. {
  485. __glibcxx_check_erase(__it);
  486. return { _M_erase(__it.base()), this };
  487. }
  488. iterator
  489. erase(const_iterator __first, const_iterator __last)
  490. {
  491. __glibcxx_check_erase_range(__first, __last);
  492. for (auto __tmp = __first.base(); __tmp != __last.base(); ++__tmp)
  493. {
  494. _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::cend(),
  495. _M_message(__gnu_debug::__msg_valid_range)
  496. ._M_iterator(__first, "first")
  497. ._M_iterator(__last, "last"));
  498. _M_invalidate(__tmp);
  499. }
  500. size_type __bucket_count = this->bucket_count();
  501. auto __next = _Base::erase(__first.base(), __last.base());
  502. _M_check_rehashed(__bucket_count);
  503. return { __next, this };
  504. }
  505. _Base&
  506. _M_base() noexcept { return *this; }
  507. const _Base&
  508. _M_base() const noexcept { return *this; }
  509. private:
  510. void
  511. _M_check_rehashed(size_type __prev_count)
  512. {
  513. if (__prev_count != this->bucket_count())
  514. this->_M_invalidate_all();
  515. }
  516. void
  517. _M_invalidate(_Base_const_iterator __victim)
  518. {
  519. this->_M_invalidate_if(
  520. [__victim](_Base_const_iterator __it) { return __it == __victim; });
  521. this->_M_invalidate_local_if(
  522. [__victim](_Base_const_local_iterator __it)
  523. { return __it == __victim; });
  524. }
  525. _Base_iterator
  526. _M_erase(_Base_const_iterator __victim)
  527. {
  528. _M_invalidate(__victim);
  529. size_type __bucket_count = this->bucket_count();
  530. _Base_iterator __next = _Base::erase(__victim);
  531. _M_check_rehashed(__bucket_count);
  532. return __next;
  533. }
  534. #if __cplusplus > 201402L
  535. node_type
  536. _M_extract(_Base_const_iterator __victim)
  537. {
  538. _M_invalidate(__victim);
  539. return _Base::extract(__victim);
  540. }
  541. #endif
  542. };
  543. #if __cpp_deduction_guides >= 201606
  544. template<typename _InputIterator,
  545. typename _Hash =
  546. hash<typename iterator_traits<_InputIterator>::value_type>,
  547. typename _Pred =
  548. equal_to<typename iterator_traits<_InputIterator>::value_type>,
  549. typename _Allocator =
  550. allocator<typename iterator_traits<_InputIterator>::value_type>,
  551. typename = _RequireInputIter<_InputIterator>,
  552. typename = _RequireNotAllocatorOrIntegral<_Hash>,
  553. typename = _RequireNotAllocator<_Pred>,
  554. typename = _RequireAllocator<_Allocator>>
  555. unordered_set(_InputIterator, _InputIterator,
  556. unordered_set<int>::size_type = {},
  557. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  558. -> unordered_set<typename iterator_traits<_InputIterator>::value_type,
  559. _Hash, _Pred, _Allocator>;
  560. template<typename _Tp, typename _Hash = hash<_Tp>,
  561. typename _Pred = equal_to<_Tp>,
  562. typename _Allocator = allocator<_Tp>,
  563. typename = _RequireNotAllocatorOrIntegral<_Hash>,
  564. typename = _RequireNotAllocator<_Pred>,
  565. typename = _RequireAllocator<_Allocator>>
  566. unordered_set(initializer_list<_Tp>,
  567. unordered_set<int>::size_type = {},
  568. _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
  569. -> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
  570. template<typename _InputIterator, typename _Allocator,
  571. typename = _RequireInputIter<_InputIterator>,
  572. typename = _RequireAllocator<_Allocator>>
  573. unordered_set(_InputIterator, _InputIterator,
  574. unordered_set<int>::size_type, _Allocator)
  575. -> unordered_set<typename iterator_traits<_InputIterator>::value_type,
  576. hash<
  577. typename iterator_traits<_InputIterator>::value_type>,
  578. equal_to<
  579. typename iterator_traits<_InputIterator>::value_type>,
  580. _Allocator>;
  581. template<typename _InputIterator, typename _Hash, typename _Allocator,
  582. typename = _RequireInputIter<_InputIterator>,
  583. typename = _RequireNotAllocatorOrIntegral<_Hash>,
  584. typename = _RequireAllocator<_Allocator>>
  585. unordered_set(_InputIterator, _InputIterator,
  586. unordered_set<int>::size_type,
  587. _Hash, _Allocator)
  588. -> unordered_set<typename iterator_traits<_InputIterator>::value_type,
  589. _Hash,
  590. equal_to<
  591. typename iterator_traits<_InputIterator>::value_type>,
  592. _Allocator>;
  593. template<typename _Tp, typename _Allocator,
  594. typename = _RequireAllocator<_Allocator>>
  595. unordered_set(initializer_list<_Tp>,
  596. unordered_set<int>::size_type, _Allocator)
  597. -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
  598. template<typename _Tp, typename _Hash, typename _Allocator,
  599. typename = _RequireNotAllocatorOrIntegral<_Hash>,
  600. typename = _RequireAllocator<_Allocator>>
  601. unordered_set(initializer_list<_Tp>,
  602. unordered_set<int>::size_type, _Hash, _Allocator)
  603. -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
  604. #endif
  605. template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
  606. inline void
  607. swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  608. unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  609. noexcept(noexcept(__x.swap(__y)))
  610. { __x.swap(__y); }
  611. template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
  612. inline bool
  613. operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  614. const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  615. { return __x._M_base() == __y._M_base(); }
  616. #if __cpp_impl_three_way_comparison < 201907L
  617. template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
  618. inline bool
  619. operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  620. const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  621. { return !(__x == __y); }
  622. #endif
  623. /// Class std::unordered_multiset with safety/checking/debug instrumentation.
  624. template<typename _Value,
  625. typename _Hash = std::hash<_Value>,
  626. typename _Pred = std::equal_to<_Value>,
  627. typename _Alloc = std::allocator<_Value> >
  628. class unordered_multiset
  629. : public __gnu_debug::_Safe_container<
  630. unordered_multiset<_Value, _Hash, _Pred, _Alloc>, _Alloc,
  631. __gnu_debug::_Safe_unordered_container>,
  632. public _GLIBCXX_STD_C::unordered_multiset<_Value, _Hash, _Pred, _Alloc>
  633. {
  634. typedef _GLIBCXX_STD_C::unordered_multiset<
  635. _Value, _Hash, _Pred, _Alloc> _Base;
  636. typedef __gnu_debug::_Safe_container<unordered_multiset,
  637. _Alloc, __gnu_debug::_Safe_unordered_container> _Safe;
  638. typedef typename _Base::const_iterator _Base_const_iterator;
  639. typedef typename _Base::iterator _Base_iterator;
  640. typedef typename _Base::const_local_iterator
  641. _Base_const_local_iterator;
  642. typedef typename _Base::local_iterator _Base_local_iterator;
  643. template<typename _ItT, typename _SeqT, typename _CatT>
  644. friend class ::__gnu_debug::_Safe_iterator;
  645. template<typename _ItT, typename _SeqT>
  646. friend class ::__gnu_debug::_Safe_local_iterator;
  647. // Reference wrapper for base class. See PR libstdc++/90102.
  648. struct _Base_ref
  649. {
  650. _Base_ref(const _Base& __r) : _M_ref(__r) { }
  651. const _Base& _M_ref;
  652. };
  653. public:
  654. typedef typename _Base::size_type size_type;
  655. typedef typename _Base::difference_type difference_type;
  656. typedef typename _Base::hasher hasher;
  657. typedef typename _Base::key_equal key_equal;
  658. typedef typename _Base::allocator_type allocator_type;
  659. typedef typename _Base::key_type key_type;
  660. typedef typename _Base::value_type value_type;
  661. typedef typename _Base::pointer pointer;
  662. typedef typename _Base::const_pointer const_pointer;
  663. typedef typename _Base::reference reference;
  664. typedef typename _Base::const_reference const_reference;
  665. typedef __gnu_debug::_Safe_iterator<
  666. _Base_iterator, unordered_multiset> iterator;
  667. typedef __gnu_debug::_Safe_iterator<
  668. _Base_const_iterator, unordered_multiset> const_iterator;
  669. typedef __gnu_debug::_Safe_local_iterator<
  670. _Base_local_iterator, unordered_multiset> local_iterator;
  671. typedef __gnu_debug::_Safe_local_iterator<
  672. _Base_const_local_iterator, unordered_multiset> const_local_iterator;
  673. unordered_multiset() = default;
  674. explicit
  675. unordered_multiset(size_type __n,
  676. const hasher& __hf = hasher(),
  677. const key_equal& __eql = key_equal(),
  678. const allocator_type& __a = allocator_type())
  679. : _Base(__n, __hf, __eql, __a) { }
  680. template<typename _InputIterator>
  681. unordered_multiset(_InputIterator __first, _InputIterator __last,
  682. size_type __n = 0,
  683. const hasher& __hf = hasher(),
  684. const key_equal& __eql = key_equal(),
  685. const allocator_type& __a = allocator_type())
  686. : _Base(__gnu_debug::__base(
  687. __glibcxx_check_valid_constructor_range(__first, __last)),
  688. __gnu_debug::__base(__last), __n,
  689. __hf, __eql, __a) { }
  690. unordered_multiset(const unordered_multiset&) = default;
  691. unordered_multiset(_Base_ref __x)
  692. : _Base(__x._M_ref) { }
  693. unordered_multiset(unordered_multiset&&) = default;
  694. explicit
  695. unordered_multiset(const allocator_type& __a)
  696. : _Base(__a) { }
  697. unordered_multiset(const unordered_multiset& __uset,
  698. const allocator_type& __a)
  699. : _Base(__uset, __a) { }
  700. unordered_multiset(unordered_multiset&& __uset,
  701. const allocator_type& __a)
  702. noexcept( noexcept(_Base(std::move(__uset), __a)) )
  703. : _Safe(std::move(__uset), __a),
  704. _Base(std::move(__uset), __a) { }
  705. unordered_multiset(initializer_list<value_type> __l,
  706. size_type __n = 0,
  707. const hasher& __hf = hasher(),
  708. const key_equal& __eql = key_equal(),
  709. const allocator_type& __a = allocator_type())
  710. : _Base(__l, __n, __hf, __eql, __a) { }
  711. unordered_multiset(size_type __n, const allocator_type& __a)
  712. : unordered_multiset(__n, hasher(), key_equal(), __a)
  713. { }
  714. unordered_multiset(size_type __n, const hasher& __hf,
  715. const allocator_type& __a)
  716. : unordered_multiset(__n, __hf, key_equal(), __a)
  717. { }
  718. template<typename _InputIterator>
  719. unordered_multiset(_InputIterator __first, _InputIterator __last,
  720. size_type __n,
  721. const allocator_type& __a)
  722. : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a)
  723. { }
  724. template<typename _InputIterator>
  725. unordered_multiset(_InputIterator __first, _InputIterator __last,
  726. size_type __n, const hasher& __hf,
  727. const allocator_type& __a)
  728. : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a)
  729. { }
  730. unordered_multiset(initializer_list<value_type> __l,
  731. size_type __n,
  732. const allocator_type& __a)
  733. : unordered_multiset(__l, __n, hasher(), key_equal(), __a)
  734. { }
  735. unordered_multiset(initializer_list<value_type> __l,
  736. size_type __n, const hasher& __hf,
  737. const allocator_type& __a)
  738. : unordered_multiset(__l, __n, __hf, key_equal(), __a)
  739. { }
  740. ~unordered_multiset() = default;
  741. unordered_multiset&
  742. operator=(const unordered_multiset&) = default;
  743. unordered_multiset&
  744. operator=(unordered_multiset&&) = default;
  745. unordered_multiset&
  746. operator=(initializer_list<value_type> __l)
  747. {
  748. _Base::operator=(__l);
  749. this->_M_invalidate_all();
  750. return *this;
  751. }
  752. using _Base::get_allocator;
  753. using _Base::empty;
  754. using _Base::size;
  755. using _Base::max_size;
  756. void
  757. swap(unordered_multiset& __x)
  758. noexcept( noexcept(declval<_Base&>().swap(__x)) )
  759. {
  760. _Safe::_M_swap(__x);
  761. _Base::swap(__x);
  762. }
  763. void
  764. clear() noexcept
  765. {
  766. _Base::clear();
  767. this->_M_invalidate_all();
  768. }
  769. iterator
  770. begin() noexcept
  771. { return { _Base::begin(), this }; }
  772. const_iterator
  773. begin() const noexcept
  774. { return { _Base::begin(), this }; }
  775. iterator
  776. end() noexcept
  777. { return { _Base::end(), this }; }
  778. const_iterator
  779. end() const noexcept
  780. { return { _Base::end(), this }; }
  781. const_iterator
  782. cbegin() const noexcept
  783. { return { _Base::cbegin(), this }; }
  784. const_iterator
  785. cend() const noexcept
  786. { return { _Base::cend(), this }; }
  787. // local versions
  788. local_iterator
  789. begin(size_type __b)
  790. {
  791. __glibcxx_check_bucket_index(__b);
  792. return { _Base::begin(__b), this };
  793. }
  794. local_iterator
  795. end(size_type __b)
  796. {
  797. __glibcxx_check_bucket_index(__b);
  798. return { _Base::end(__b), this };
  799. }
  800. const_local_iterator
  801. begin(size_type __b) const
  802. {
  803. __glibcxx_check_bucket_index(__b);
  804. return { _Base::begin(__b), this };
  805. }
  806. const_local_iterator
  807. end(size_type __b) const
  808. {
  809. __glibcxx_check_bucket_index(__b);
  810. return { _Base::end(__b), this };
  811. }
  812. const_local_iterator
  813. cbegin(size_type __b) const
  814. {
  815. __glibcxx_check_bucket_index(__b);
  816. return { _Base::cbegin(__b), this };
  817. }
  818. const_local_iterator
  819. cend(size_type __b) const
  820. {
  821. __glibcxx_check_bucket_index(__b);
  822. return { _Base::cend(__b), this };
  823. }
  824. using _Base::bucket_count;
  825. using _Base::max_bucket_count;
  826. size_type
  827. bucket_size(size_type __b) const
  828. {
  829. __glibcxx_check_bucket_index(__b);
  830. return _Base::bucket_size(__b);
  831. }
  832. using _Base::bucket;
  833. using _Base::load_factor;
  834. float
  835. max_load_factor() const noexcept
  836. { return _Base::max_load_factor(); }
  837. void
  838. max_load_factor(float __f)
  839. {
  840. __glibcxx_check_max_load_factor(__f);
  841. _Base::max_load_factor(__f);
  842. }
  843. using _Base::rehash;
  844. using _Base::reserve;
  845. template<typename... _Args>
  846. iterator
  847. emplace(_Args&&... __args)
  848. {
  849. size_type __bucket_count = this->bucket_count();
  850. auto __it = _Base::emplace(std::forward<_Args>(__args)...);
  851. _M_check_rehashed(__bucket_count);
  852. return { __it, this };
  853. }
  854. template<typename... _Args>
  855. iterator
  856. emplace_hint(const_iterator __hint, _Args&&... __args)
  857. {
  858. __glibcxx_check_insert(__hint);
  859. size_type __bucket_count = this->bucket_count();
  860. auto __it = _Base::emplace_hint(__hint.base(),
  861. std::forward<_Args>(__args)...);
  862. _M_check_rehashed(__bucket_count);
  863. return { __it, this };
  864. }
  865. iterator
  866. insert(const value_type& __obj)
  867. {
  868. size_type __bucket_count = this->bucket_count();
  869. auto __it = _Base::insert(__obj);
  870. _M_check_rehashed(__bucket_count);
  871. return { __it, this };
  872. }
  873. iterator
  874. insert(const_iterator __hint, const value_type& __obj)
  875. {
  876. __glibcxx_check_insert(__hint);
  877. size_type __bucket_count = this->bucket_count();
  878. auto __it = _Base::insert(__hint.base(), __obj);
  879. _M_check_rehashed(__bucket_count);
  880. return { __it, this };
  881. }
  882. iterator
  883. insert(value_type&& __obj)
  884. {
  885. size_type __bucket_count = this->bucket_count();
  886. auto __it = _Base::insert(std::move(__obj));
  887. _M_check_rehashed(__bucket_count);
  888. return { __it, this };
  889. }
  890. iterator
  891. insert(const_iterator __hint, value_type&& __obj)
  892. {
  893. __glibcxx_check_insert(__hint);
  894. size_type __bucket_count = this->bucket_count();
  895. auto __it = _Base::insert(__hint.base(), std::move(__obj));
  896. _M_check_rehashed(__bucket_count);
  897. return { __it, this };
  898. }
  899. void
  900. insert(std::initializer_list<value_type> __l)
  901. {
  902. size_type __bucket_count = this->bucket_count();
  903. _Base::insert(__l);
  904. _M_check_rehashed(__bucket_count);
  905. }
  906. template<typename _InputIterator>
  907. void
  908. insert(_InputIterator __first, _InputIterator __last)
  909. {
  910. typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
  911. __glibcxx_check_valid_range2(__first, __last, __dist);
  912. size_type __bucket_count = this->bucket_count();
  913. if (__dist.second >= __gnu_debug::__dp_sign)
  914. _Base::insert(__gnu_debug::__unsafe(__first),
  915. __gnu_debug::__unsafe(__last));
  916. else
  917. _Base::insert(__first, __last);
  918. _M_check_rehashed(__bucket_count);
  919. }
  920. #if __cplusplus > 201402L
  921. using node_type = typename _Base::node_type;
  922. node_type
  923. extract(const_iterator __position)
  924. {
  925. __glibcxx_check_erase(__position);
  926. return _M_extract(__position.base());
  927. }
  928. node_type
  929. extract(const key_type& __key)
  930. {
  931. const auto __position = _Base::find(__key);
  932. if (__position != _Base::end())
  933. return _M_extract(__position);
  934. return {};
  935. }
  936. iterator
  937. insert(node_type&& __nh)
  938. { return { _Base::insert(std::move(__nh)), this }; }
  939. iterator
  940. insert(const_iterator __hint, node_type&& __nh)
  941. {
  942. __glibcxx_check_insert(__hint);
  943. return { _Base::insert(__hint.base(), std::move(__nh)), this };
  944. }
  945. template<typename _H2, typename _P2>
  946. void
  947. merge(unordered_multiset<_Value, _H2, _P2, _Alloc>& __source)
  948. {
  949. auto __guard
  950. = _Safe::_S_umc_guard(std::__detail::_Identity{}, __source);
  951. _Base::merge(__source);
  952. }
  953. template<typename _H2, typename _P2>
  954. void
  955. merge(unordered_multiset<_Value, _H2, _P2, _Alloc>&& __source)
  956. { merge(__source); }
  957. template<typename _H2, typename _P2>
  958. void
  959. merge(unordered_set<_Value, _H2, _P2, _Alloc>& __source)
  960. {
  961. auto __guard
  962. = _Safe::_S_uc_guard(std::__detail::_Identity{}, __source);
  963. _Base::merge(__source);
  964. }
  965. template<typename _H2, typename _P2>
  966. void
  967. merge(unordered_set<_Value, _H2, _P2, _Alloc>&& __source)
  968. { merge(__source); }
  969. #endif // C++17
  970. using _Base::hash_function;
  971. using _Base::key_eq;
  972. iterator
  973. find(const key_type& __key)
  974. { return { _Base::find(__key), this }; }
  975. #if __cplusplus > 201703L
  976. template<typename _Kt,
  977. typename = std::__has_is_transparent_t<_Hash, _Kt>,
  978. typename = std::__has_is_transparent_t<_Pred, _Kt>>
  979. iterator
  980. find(const _Kt& __k)
  981. { return { _Base::find(__k), this }; }
  982. #endif
  983. const_iterator
  984. find(const key_type& __key) const
  985. { return { _Base::find(__key), this }; }
  986. #if __cplusplus > 201703L
  987. template<typename _Kt,
  988. typename = std::__has_is_transparent_t<_Hash, _Kt>,
  989. typename = std::__has_is_transparent_t<_Pred, _Kt>>
  990. const_iterator
  991. find(const _Kt& __k) const
  992. { return { _Base::find(__k), this }; }
  993. #endif
  994. using _Base::count;
  995. #if __cplusplus > 201703L
  996. using _Base::contains;
  997. #endif
  998. std::pair<iterator, iterator>
  999. equal_range(const key_type& __key)
  1000. {
  1001. auto __res = _Base::equal_range(__key);
  1002. return { { __res.first, this }, { __res.second, this } };
  1003. }
  1004. #if __cplusplus > 201703L
  1005. template<typename _Kt,
  1006. typename = std::__has_is_transparent_t<_Hash, _Kt>,
  1007. typename = std::__has_is_transparent_t<_Pred, _Kt>>
  1008. std::pair<iterator, iterator>
  1009. equal_range(const _Kt& __k)
  1010. {
  1011. auto __res = _Base::equal_range(__k);
  1012. return { { __res.first, this }, { __res.second, this } };
  1013. }
  1014. #endif
  1015. std::pair<const_iterator, const_iterator>
  1016. equal_range(const key_type& __key) const
  1017. {
  1018. auto __res = _Base::equal_range(__key);
  1019. return { { __res.first, this }, { __res.second, this } };
  1020. }
  1021. #if __cplusplus > 201703L
  1022. template<typename _Kt,
  1023. typename = std::__has_is_transparent_t<_Hash, _Kt>,
  1024. typename = std::__has_is_transparent_t<_Pred, _Kt>>
  1025. std::pair<const_iterator, const_iterator>
  1026. equal_range(const _Kt& __k) const
  1027. {
  1028. auto __res = _Base::equal_range(__k);
  1029. return { { __res.first, this }, { __res.second, this } };
  1030. }
  1031. #endif
  1032. size_type
  1033. erase(const key_type& __key)
  1034. {
  1035. size_type __ret(0);
  1036. auto __pair = _Base::equal_range(__key);
  1037. for (auto __victim = __pair.first; __victim != __pair.second;)
  1038. {
  1039. _M_invalidate(__victim);
  1040. __victim = _Base::erase(__victim);
  1041. ++__ret;
  1042. }
  1043. return __ret;
  1044. }
  1045. iterator
  1046. erase(const_iterator __it)
  1047. {
  1048. __glibcxx_check_erase(__it);
  1049. return { _M_erase(__it.base()), this };
  1050. }
  1051. _Base_iterator
  1052. erase(_Base_const_iterator __it)
  1053. {
  1054. __glibcxx_check_erase2(__it);
  1055. return _M_erase(__it);
  1056. }
  1057. iterator
  1058. erase(iterator __it)
  1059. {
  1060. __glibcxx_check_erase(__it);
  1061. return { _M_erase(__it.base()), this };
  1062. }
  1063. iterator
  1064. erase(const_iterator __first, const_iterator __last)
  1065. {
  1066. __glibcxx_check_erase_range(__first, __last);
  1067. for (auto __tmp = __first.base(); __tmp != __last.base(); ++__tmp)
  1068. {
  1069. _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::cend(),
  1070. _M_message(__gnu_debug::__msg_valid_range)
  1071. ._M_iterator(__first, "first")
  1072. ._M_iterator(__last, "last"));
  1073. _M_invalidate(__tmp);
  1074. }
  1075. return { _Base::erase(__first.base(), __last.base()), this };
  1076. }
  1077. _Base&
  1078. _M_base() noexcept { return *this; }
  1079. const _Base&
  1080. _M_base() const noexcept { return *this; }
  1081. private:
  1082. void
  1083. _M_check_rehashed(size_type __prev_count)
  1084. {
  1085. if (__prev_count != this->bucket_count())
  1086. this->_M_invalidate_all();
  1087. }
  1088. void
  1089. _M_invalidate(_Base_const_iterator __victim)
  1090. {
  1091. this->_M_invalidate_if(
  1092. [__victim](_Base_const_iterator __it) { return __it == __victim; });
  1093. this->_M_invalidate_local_if(
  1094. [__victim](_Base_const_local_iterator __it)
  1095. { return __it == __victim; });
  1096. }
  1097. _Base_iterator
  1098. _M_erase(_Base_const_iterator __victim)
  1099. {
  1100. _M_invalidate(__victim);
  1101. size_type __bucket_count = this->bucket_count();
  1102. _Base_iterator __next = _Base::erase(__victim);
  1103. _M_check_rehashed(__bucket_count);
  1104. return __next;
  1105. }
  1106. #if __cplusplus > 201402L
  1107. node_type
  1108. _M_extract(_Base_const_iterator __victim)
  1109. {
  1110. _M_invalidate(__victim);
  1111. return _Base::extract(__victim);
  1112. }
  1113. #endif
  1114. };
  1115. #if __cpp_deduction_guides >= 201606
  1116. template<typename _InputIterator,
  1117. typename _Hash =
  1118. hash<typename iterator_traits<_InputIterator>::value_type>,
  1119. typename _Pred =
  1120. equal_to<typename iterator_traits<_InputIterator>::value_type>,
  1121. typename _Allocator =
  1122. allocator<typename iterator_traits<_InputIterator>::value_type>,
  1123. typename = _RequireInputIter<_InputIterator>,
  1124. typename = _RequireNotAllocatorOrIntegral<_Hash>,
  1125. typename = _RequireNotAllocator<_Pred>,
  1126. typename = _RequireAllocator<_Allocator>>
  1127. unordered_multiset(_InputIterator, _InputIterator,
  1128. unordered_multiset<int>::size_type = {},
  1129. _Hash = _Hash(), _Pred = _Pred(),
  1130. _Allocator = _Allocator())
  1131. -> unordered_multiset<typename iterator_traits<_InputIterator>::value_type,
  1132. _Hash, _Pred, _Allocator>;
  1133. template<typename _Tp, typename _Hash = hash<_Tp>,
  1134. typename _Pred = equal_to<_Tp>,
  1135. typename _Allocator = allocator<_Tp>,
  1136. typename = _RequireNotAllocatorOrIntegral<_Hash>,
  1137. typename = _RequireNotAllocator<_Pred>,
  1138. typename = _RequireAllocator<_Allocator>>
  1139. unordered_multiset(initializer_list<_Tp>,
  1140. unordered_multiset<int>::size_type = {},
  1141. _Hash = _Hash(), _Pred = _Pred(),
  1142. _Allocator = _Allocator())
  1143. -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
  1144. template<typename _InputIterator, typename _Allocator,
  1145. typename = _RequireInputIter<_InputIterator>,
  1146. typename = _RequireAllocator<_Allocator>>
  1147. unordered_multiset(_InputIterator, _InputIterator,
  1148. unordered_multiset<int>::size_type, _Allocator)
  1149. -> unordered_multiset<typename iterator_traits<_InputIterator>::value_type,
  1150. hash<typename
  1151. iterator_traits<_InputIterator>::value_type>,
  1152. equal_to<typename
  1153. iterator_traits<_InputIterator>::value_type>,
  1154. _Allocator>;
  1155. template<typename _InputIterator, typename _Hash, typename _Allocator,
  1156. typename = _RequireInputIter<_InputIterator>,
  1157. typename = _RequireNotAllocatorOrIntegral<_Hash>,
  1158. typename = _RequireAllocator<_Allocator>>
  1159. unordered_multiset(_InputIterator, _InputIterator,
  1160. unordered_multiset<int>::size_type,
  1161. _Hash, _Allocator)
  1162. -> unordered_multiset<typename
  1163. iterator_traits<_InputIterator>::value_type,
  1164. _Hash,
  1165. equal_to<
  1166. typename
  1167. iterator_traits<_InputIterator>::value_type>,
  1168. _Allocator>;
  1169. template<typename _Tp, typename _Allocator,
  1170. typename = _RequireAllocator<_Allocator>>
  1171. unordered_multiset(initializer_list<_Tp>,
  1172. unordered_multiset<int>::size_type, _Allocator)
  1173. -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
  1174. template<typename _Tp, typename _Hash, typename _Allocator,
  1175. typename = _RequireNotAllocatorOrIntegral<_Hash>,
  1176. typename = _RequireAllocator<_Allocator>>
  1177. unordered_multiset(initializer_list<_Tp>,
  1178. unordered_multiset<int>::size_type, _Hash, _Allocator)
  1179. -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
  1180. #endif
  1181. template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
  1182. inline void
  1183. swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  1184. unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  1185. noexcept(noexcept(__x.swap(__y)))
  1186. { __x.swap(__y); }
  1187. template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
  1188. inline bool
  1189. operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  1190. const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  1191. { return __x._M_base() == __y._M_base(); }
  1192. #if __cpp_impl_three_way_comparison < 201907L
  1193. template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
  1194. inline bool
  1195. operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  1196. const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  1197. { return !(__x == __y); }
  1198. #endif
  1199. } // namespace __debug
  1200. } // namespace std
  1201. #endif // C++11
  1202. #endif