map.h 22 KB

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