unordered_map 41 KB

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