You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

798 lines
22KB

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