multimap.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. // Debugging multimap implementation -*- C++ -*-
  2. // Copyright (C) 2003-2022 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/multimap.h
  21. * This file is a GNU debug extension to the Standard C++ Library.
  22. */
  23. #ifndef _GLIBCXX_DEBUG_MULTIMAP_H
  24. #define _GLIBCXX_DEBUG_MULTIMAP_H 1
  25. #include <debug/safe_sequence.h>
  26. #include <debug/safe_container.h>
  27. #include <debug/safe_iterator.h>
  28. #include <bits/stl_pair.h>
  29. namespace std _GLIBCXX_VISIBILITY(default)
  30. {
  31. namespace __debug
  32. {
  33. /// Class std::multimap with safety/checking/debug instrumentation.
  34. template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
  35. typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
  36. class multimap
  37. : public __gnu_debug::_Safe_container<
  38. multimap<_Key, _Tp, _Compare, _Allocator>, _Allocator,
  39. __gnu_debug::_Safe_node_sequence>,
  40. public _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator>
  41. {
  42. typedef _GLIBCXX_STD_C::multimap<
  43. _Key, _Tp, _Compare, _Allocator> _Base;
  44. typedef __gnu_debug::_Safe_container<
  45. multimap, _Allocator, __gnu_debug::_Safe_node_sequence> _Safe;
  46. typedef typename _Base::const_iterator _Base_const_iterator;
  47. typedef typename _Base::iterator _Base_iterator;
  48. typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
  49. template<typename _ItT, typename _SeqT, typename _CatT>
  50. friend class ::__gnu_debug::_Safe_iterator;
  51. // Reference wrapper for base class. Disambiguates multimap(const _Base&)
  52. // from copy constructor by requiring a user-defined conversion.
  53. // See PR libstdc++/90102.
  54. struct _Base_ref
  55. {
  56. _Base_ref(const _Base& __r) : _M_ref(__r) { }
  57. const _Base& _M_ref;
  58. };
  59. public:
  60. // types:
  61. typedef _Key key_type;
  62. typedef _Tp mapped_type;
  63. typedef std::pair<const _Key, _Tp> value_type;
  64. typedef _Compare key_compare;
  65. typedef _Allocator allocator_type;
  66. typedef typename _Base::reference reference;
  67. typedef typename _Base::const_reference const_reference;
  68. typedef __gnu_debug::_Safe_iterator<_Base_iterator, multimap>
  69. iterator;
  70. typedef __gnu_debug::_Safe_iterator<_Base_const_iterator,
  71. multimap> const_iterator;
  72. typedef typename _Base::size_type size_type;
  73. typedef typename _Base::difference_type difference_type;
  74. typedef typename _Base::pointer pointer;
  75. typedef typename _Base::const_pointer const_pointer;
  76. typedef std::reverse_iterator<iterator> reverse_iterator;
  77. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  78. // 23.3.1.1 construct/copy/destroy:
  79. #if __cplusplus < 201103L
  80. multimap() : _Base() { }
  81. multimap(const multimap& __x)
  82. : _Base(__x) { }
  83. ~multimap() { }
  84. #else
  85. multimap() = default;
  86. multimap(const multimap&) = default;
  87. multimap(multimap&&) = default;
  88. multimap(initializer_list<value_type> __l,
  89. const _Compare& __c = _Compare(),
  90. const allocator_type& __a = allocator_type())
  91. : _Base(__l, __c, __a) { }
  92. explicit
  93. multimap(const allocator_type& __a)
  94. : _Base(__a) { }
  95. multimap(const multimap& __m,
  96. const __type_identity_t<allocator_type>& __a)
  97. : _Base(__m, __a) { }
  98. multimap(multimap&& __m, const __type_identity_t<allocator_type>& __a)
  99. noexcept( noexcept(_Base(std::move(__m), __a)) )
  100. : _Safe(std::move(__m), __a),
  101. _Base(std::move(__m), __a) { }
  102. multimap(initializer_list<value_type> __l, const allocator_type& __a)
  103. : _Base(__l, __a) { }
  104. template<typename _InputIterator>
  105. multimap(_InputIterator __first, _InputIterator __last,
  106. const allocator_type& __a)
  107. : _Base(__gnu_debug::__base(
  108. __glibcxx_check_valid_constructor_range(__first, __last)),
  109. __gnu_debug::__base(__last), __a) { }
  110. ~multimap() = default;
  111. #endif
  112. explicit multimap(const _Compare& __comp,
  113. const _Allocator& __a = _Allocator())
  114. : _Base(__comp, __a) { }
  115. template<typename _InputIterator>
  116. multimap(_InputIterator __first, _InputIterator __last,
  117. const _Compare& __comp = _Compare(),
  118. const _Allocator& __a = _Allocator())
  119. : _Base(__gnu_debug::__base(
  120. __glibcxx_check_valid_constructor_range(__first, __last)),
  121. __gnu_debug::__base(__last),
  122. __comp, __a) { }
  123. multimap(_Base_ref __x)
  124. : _Base(__x._M_ref) { }
  125. #if __cplusplus >= 201103L
  126. multimap&
  127. operator=(const multimap&) = default;
  128. multimap&
  129. operator=(multimap&&) = default;
  130. multimap&
  131. operator=(initializer_list<value_type> __l)
  132. {
  133. _Base::operator=(__l);
  134. this->_M_invalidate_all();
  135. return *this;
  136. }
  137. #endif
  138. using _Base::get_allocator;
  139. // iterators:
  140. iterator
  141. begin() _GLIBCXX_NOEXCEPT
  142. { return iterator(_Base::begin(), this); }
  143. const_iterator
  144. begin() const _GLIBCXX_NOEXCEPT
  145. { return const_iterator(_Base::begin(), this); }
  146. iterator
  147. end() _GLIBCXX_NOEXCEPT
  148. { return iterator(_Base::end(), this); }
  149. const_iterator
  150. end() const _GLIBCXX_NOEXCEPT
  151. { return const_iterator(_Base::end(), this); }
  152. reverse_iterator
  153. rbegin() _GLIBCXX_NOEXCEPT
  154. { return reverse_iterator(end()); }
  155. const_reverse_iterator
  156. rbegin() const _GLIBCXX_NOEXCEPT
  157. { return const_reverse_iterator(end()); }
  158. reverse_iterator
  159. rend() _GLIBCXX_NOEXCEPT
  160. { return reverse_iterator(begin()); }
  161. const_reverse_iterator
  162. rend() const _GLIBCXX_NOEXCEPT
  163. { return const_reverse_iterator(begin()); }
  164. #if __cplusplus >= 201103L
  165. const_iterator
  166. cbegin() const noexcept
  167. { return const_iterator(_Base::begin(), this); }
  168. const_iterator
  169. cend() const noexcept
  170. { return const_iterator(_Base::end(), this); }
  171. const_reverse_iterator
  172. crbegin() const noexcept
  173. { return const_reverse_iterator(end()); }
  174. const_reverse_iterator
  175. crend() const noexcept
  176. { return const_reverse_iterator(begin()); }
  177. #endif
  178. // capacity:
  179. using _Base::empty;
  180. using _Base::size;
  181. using _Base::max_size;
  182. // modifiers:
  183. #if __cplusplus >= 201103L
  184. template<typename... _Args>
  185. iterator
  186. emplace(_Args&&... __args)
  187. { return { _Base::emplace(std::forward<_Args>(__args)...), this }; }
  188. template<typename... _Args>
  189. iterator
  190. emplace_hint(const_iterator __pos, _Args&&... __args)
  191. {
  192. __glibcxx_check_insert(__pos);
  193. return
  194. {
  195. _Base::emplace_hint(__pos.base(), std::forward<_Args>(__args)...),
  196. this
  197. };
  198. }
  199. #endif
  200. iterator
  201. insert(const value_type& __x)
  202. { return iterator(_Base::insert(__x), this); }
  203. #if __cplusplus >= 201103L
  204. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  205. // 2354. Unnecessary copying when inserting into maps with braced-init
  206. iterator
  207. insert(value_type&& __x)
  208. { return { _Base::insert(std::move(__x)), this }; }
  209. template<typename _Pair, typename = typename
  210. std::enable_if<std::is_constructible<value_type,
  211. _Pair&&>::value>::type>
  212. iterator
  213. insert(_Pair&& __x)
  214. { return { _Base::insert(std::forward<_Pair>(__x)), this }; }
  215. #endif
  216. #if __cplusplus >= 201103L
  217. void
  218. insert(std::initializer_list<value_type> __list)
  219. { _Base::insert(__list); }
  220. #endif
  221. iterator
  222. #if __cplusplus >= 201103L
  223. insert(const_iterator __position, const value_type& __x)
  224. #else
  225. insert(iterator __position, const value_type& __x)
  226. #endif
  227. {
  228. __glibcxx_check_insert(__position);
  229. return iterator(_Base::insert(__position.base(), __x), this);
  230. }
  231. #if __cplusplus >= 201103L
  232. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  233. // 2354. Unnecessary copying when inserting into maps with braced-init
  234. iterator
  235. insert(const_iterator __position, value_type&& __x)
  236. {
  237. __glibcxx_check_insert(__position);
  238. return { _Base::insert(__position.base(), std::move(__x)), this };
  239. }
  240. template<typename _Pair, typename = typename
  241. std::enable_if<std::is_constructible<value_type,
  242. _Pair&&>::value>::type>
  243. iterator
  244. insert(const_iterator __position, _Pair&& __x)
  245. {
  246. __glibcxx_check_insert(__position);
  247. return
  248. {
  249. _Base::insert(__position.base(), std::forward<_Pair>(__x)),
  250. this
  251. };
  252. }
  253. #endif
  254. template<typename _InputIterator>
  255. void
  256. insert(_InputIterator __first, _InputIterator __last)
  257. {
  258. typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
  259. __glibcxx_check_valid_range2(__first, __last, __dist);
  260. if (__dist.second >= __gnu_debug::__dp_sign)
  261. _Base::insert(__gnu_debug::__unsafe(__first),
  262. __gnu_debug::__unsafe(__last));
  263. else
  264. _Base::insert(__first, __last);
  265. }
  266. #if __cplusplus > 201402L
  267. using node_type = typename _Base::node_type;
  268. node_type
  269. extract(const_iterator __position)
  270. {
  271. __glibcxx_check_erase(__position);
  272. this->_M_invalidate_if(_Equal(__position.base()));
  273. return _Base::extract(__position.base());
  274. }
  275. node_type
  276. extract(const key_type& __key)
  277. {
  278. const auto __position = find(__key);
  279. if (__position != end())
  280. return extract(__position);
  281. return {};
  282. }
  283. iterator
  284. insert(node_type&& __nh)
  285. { return { _Base::insert(std::move(__nh)), this }; }
  286. iterator
  287. insert(const_iterator __hint, node_type&& __nh)
  288. {
  289. __glibcxx_check_insert(__hint);
  290. return { _Base::insert(__hint.base(), std::move(__nh)), this };
  291. }
  292. using _Base::merge;
  293. #endif // C++17
  294. #if __cplusplus >= 201103L
  295. iterator
  296. erase(const_iterator __position)
  297. {
  298. __glibcxx_check_erase(__position);
  299. return { erase(__position.base()), this };
  300. }
  301. _Base_iterator
  302. erase(_Base_const_iterator __position)
  303. {
  304. __glibcxx_check_erase2(__position);
  305. this->_M_invalidate_if(_Equal(__position));
  306. return _Base::erase(__position);
  307. }
  308. _GLIBCXX_ABI_TAG_CXX11
  309. iterator
  310. erase(iterator __position)
  311. { return erase(const_iterator(__position)); }
  312. #else
  313. void
  314. erase(iterator __position)
  315. {
  316. __glibcxx_check_erase(__position);
  317. this->_M_invalidate_if(_Equal(__position.base()));
  318. _Base::erase(__position.base());
  319. }
  320. #endif
  321. size_type
  322. erase(const key_type& __x)
  323. {
  324. std::pair<_Base_iterator, _Base_iterator> __victims =
  325. _Base::equal_range(__x);
  326. size_type __count = 0;
  327. _Base_iterator __victim = __victims.first;
  328. while (__victim != __victims.second)
  329. {
  330. this->_M_invalidate_if(_Equal(__victim));
  331. _Base::erase(__victim++);
  332. ++__count;
  333. }
  334. return __count;
  335. }
  336. #if __cplusplus >= 201103L
  337. iterator
  338. erase(const_iterator __first, const_iterator __last)
  339. {
  340. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  341. // 151. can't currently clear() empty container
  342. __glibcxx_check_erase_range(__first, __last);
  343. for (_Base_const_iterator __victim = __first.base();
  344. __victim != __last.base(); ++__victim)
  345. {
  346. _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
  347. _M_message(__gnu_debug::__msg_valid_range)
  348. ._M_iterator(__first, "first")
  349. ._M_iterator(__last, "last"));
  350. this->_M_invalidate_if(_Equal(__victim));
  351. }
  352. return { _Base::erase(__first.base(), __last.base()), this };
  353. }
  354. #else
  355. void
  356. erase(iterator __first, iterator __last)
  357. {
  358. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  359. // 151. can't currently clear() empty container
  360. __glibcxx_check_erase_range(__first, __last);
  361. for (_Base_iterator __victim = __first.base();
  362. __victim != __last.base(); ++__victim)
  363. {
  364. _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
  365. _M_message(__gnu_debug::__msg_valid_range)
  366. ._M_iterator(__first, "first")
  367. ._M_iterator(__last, "last"));
  368. this->_M_invalidate_if(_Equal(__victim));
  369. }
  370. _Base::erase(__first.base(), __last.base());
  371. }
  372. #endif
  373. void
  374. swap(multimap& __x)
  375. _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
  376. {
  377. _Safe::_M_swap(__x);
  378. _Base::swap(__x);
  379. }
  380. void
  381. clear() _GLIBCXX_NOEXCEPT
  382. {
  383. this->_M_invalidate_all();
  384. _Base::clear();
  385. }
  386. // observers:
  387. using _Base::key_comp;
  388. using _Base::value_comp;
  389. // 23.3.1.3 multimap operations:
  390. iterator
  391. find(const key_type& __x)
  392. { return iterator(_Base::find(__x), this); }
  393. #if __cplusplus > 201103L
  394. template<typename _Kt,
  395. typename _Req =
  396. typename __has_is_transparent<_Compare, _Kt>::type>
  397. iterator
  398. find(const _Kt& __x)
  399. { return { _Base::find(__x), this }; }
  400. #endif
  401. const_iterator
  402. find(const key_type& __x) const
  403. { return const_iterator(_Base::find(__x), this); }
  404. #if __cplusplus > 201103L
  405. template<typename _Kt,
  406. typename _Req =
  407. typename __has_is_transparent<_Compare, _Kt>::type>
  408. const_iterator
  409. find(const _Kt& __x) const
  410. { return { _Base::find(__x), this }; }
  411. #endif
  412. using _Base::count;
  413. iterator
  414. lower_bound(const key_type& __x)
  415. { return iterator(_Base::lower_bound(__x), this); }
  416. #if __cplusplus > 201103L
  417. template<typename _Kt,
  418. typename _Req =
  419. typename __has_is_transparent<_Compare, _Kt>::type>
  420. iterator
  421. lower_bound(const _Kt& __x)
  422. { return { _Base::lower_bound(__x), this }; }
  423. #endif
  424. const_iterator
  425. lower_bound(const key_type& __x) const
  426. { return const_iterator(_Base::lower_bound(__x), this); }
  427. #if __cplusplus > 201103L
  428. template<typename _Kt,
  429. typename _Req =
  430. typename __has_is_transparent<_Compare, _Kt>::type>
  431. const_iterator
  432. lower_bound(const _Kt& __x) const
  433. { return { _Base::lower_bound(__x), this }; }
  434. #endif
  435. iterator
  436. upper_bound(const key_type& __x)
  437. { return iterator(_Base::upper_bound(__x), this); }
  438. #if __cplusplus > 201103L
  439. template<typename _Kt,
  440. typename _Req =
  441. typename __has_is_transparent<_Compare, _Kt>::type>
  442. iterator
  443. upper_bound(const _Kt& __x)
  444. { return { _Base::upper_bound(__x), this }; }
  445. #endif
  446. const_iterator
  447. upper_bound(const key_type& __x) const
  448. { return const_iterator(_Base::upper_bound(__x), this); }
  449. #if __cplusplus > 201103L
  450. template<typename _Kt,
  451. typename _Req =
  452. typename __has_is_transparent<_Compare, _Kt>::type>
  453. const_iterator
  454. upper_bound(const _Kt& __x) const
  455. { return { _Base::upper_bound(__x), this }; }
  456. #endif
  457. std::pair<iterator,iterator>
  458. equal_range(const key_type& __x)
  459. {
  460. std::pair<_Base_iterator, _Base_iterator> __res =
  461. _Base::equal_range(__x);
  462. return std::make_pair(iterator(__res.first, this),
  463. iterator(__res.second, this));
  464. }
  465. #if __cplusplus > 201103L
  466. template<typename _Kt,
  467. typename _Req =
  468. typename __has_is_transparent<_Compare, _Kt>::type>
  469. std::pair<iterator, iterator>
  470. equal_range(const _Kt& __x)
  471. {
  472. auto __res = _Base::equal_range(__x);
  473. return { { __res.first, this }, { __res.second, this } };
  474. }
  475. #endif
  476. std::pair<const_iterator,const_iterator>
  477. equal_range(const key_type& __x) const
  478. {
  479. std::pair<_Base_const_iterator, _Base_const_iterator> __res =
  480. _Base::equal_range(__x);
  481. return std::make_pair(const_iterator(__res.first, this),
  482. const_iterator(__res.second, this));
  483. }
  484. #if __cplusplus > 201103L
  485. template<typename _Kt,
  486. typename _Req =
  487. typename __has_is_transparent<_Compare, _Kt>::type>
  488. std::pair<const_iterator, const_iterator>
  489. equal_range(const _Kt& __x) const
  490. {
  491. auto __res = _Base::equal_range(__x);
  492. return { { __res.first, this }, { __res.second, this } };
  493. }
  494. #endif
  495. _Base&
  496. _M_base() _GLIBCXX_NOEXCEPT { return *this; }
  497. const _Base&
  498. _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
  499. };
  500. #if __cpp_deduction_guides >= 201606
  501. template<typename _InputIterator,
  502. typename _Compare = less<__iter_key_t<_InputIterator>>,
  503. typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
  504. typename = _RequireInputIter<_InputIterator>,
  505. typename = _RequireNotAllocator<_Compare>,
  506. typename = _RequireAllocator<_Allocator>>
  507. multimap(_InputIterator, _InputIterator,
  508. _Compare = _Compare(), _Allocator = _Allocator())
  509. -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
  510. _Compare, _Allocator>;
  511. template<typename _Key, typename _Tp, typename _Compare = less<_Key>,
  512. typename _Allocator = allocator<pair<const _Key, _Tp>>,
  513. typename = _RequireNotAllocator<_Compare>,
  514. typename = _RequireAllocator<_Allocator>>
  515. multimap(initializer_list<pair<_Key, _Tp>>,
  516. _Compare = _Compare(), _Allocator = _Allocator())
  517. -> multimap<_Key, _Tp, _Compare, _Allocator>;
  518. template<typename _InputIterator, typename _Allocator,
  519. typename = _RequireInputIter<_InputIterator>,
  520. typename = _RequireAllocator<_Allocator>>
  521. multimap(_InputIterator, _InputIterator, _Allocator)
  522. -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
  523. less<__iter_key_t<_InputIterator>>, _Allocator>;
  524. template<typename _Key, typename _Tp, typename _Allocator,
  525. typename = _RequireAllocator<_Allocator>>
  526. multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
  527. -> multimap<_Key, _Tp, less<_Key>, _Allocator>;
  528. #endif
  529. template<typename _Key, typename _Tp,
  530. typename _Compare, typename _Allocator>
  531. inline bool
  532. operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
  533. const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
  534. { return __lhs._M_base() == __rhs._M_base(); }
  535. #if __cpp_lib_three_way_comparison
  536. template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
  537. inline __detail::__synth3way_t<pair<const _Key, _Tp>>
  538. operator<=>(const multimap<_Key, _Tp, _Compare, _Alloc>& __lhs,
  539. const multimap<_Key, _Tp, _Compare, _Alloc>& __rhs)
  540. { return __lhs._M_base() <=> __rhs._M_base(); }
  541. #else
  542. template<typename _Key, typename _Tp,
  543. typename _Compare, typename _Allocator>
  544. inline bool
  545. operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
  546. const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
  547. { return __lhs._M_base() != __rhs._M_base(); }
  548. template<typename _Key, typename _Tp,
  549. typename _Compare, typename _Allocator>
  550. inline bool
  551. operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
  552. const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
  553. { return __lhs._M_base() < __rhs._M_base(); }
  554. template<typename _Key, typename _Tp,
  555. typename _Compare, typename _Allocator>
  556. inline bool
  557. operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
  558. const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
  559. { return __lhs._M_base() <= __rhs._M_base(); }
  560. template<typename _Key, typename _Tp,
  561. typename _Compare, typename _Allocator>
  562. inline bool
  563. operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
  564. const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
  565. { return __lhs._M_base() >= __rhs._M_base(); }
  566. template<typename _Key, typename _Tp,
  567. typename _Compare, typename _Allocator>
  568. inline bool
  569. operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
  570. const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
  571. { return __lhs._M_base() > __rhs._M_base(); }
  572. #endif // three-way comparison
  573. template<typename _Key, typename _Tp,
  574. typename _Compare, typename _Allocator>
  575. inline void
  576. swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
  577. multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
  578. _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
  579. { __lhs.swap(__rhs); }
  580. } // namespace __debug
  581. } // namespace std
  582. #endif