unordered_map 40 KB

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