1 // Debugging map implementation -*- C++ -*-
2 
3 // Copyright (C) 2003-2018 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /** @file debug/map.h
26  *  This file is a GNU debug extension to the Standard C++ Library.
27  */
28 
29 #ifndef _GLIBCXX_DEBUG_MAP_H
30 #define _GLIBCXX_DEBUG_MAP_H 1
31 
32 #include <debug/safe_sequence.h>
33 #include <debug/safe_container.h>
34 #include <debug/safe_iterator.h>
35 #include <utility>
36 
37 namespace std _GLIBCXX_VISIBILITY(default)
38 {
39 namespace __debug
40 {
41   /// Class std::map with safety/checking/debug instrumentation.
42   template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
43 	   typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
44     class map
45     : public __gnu_debug::_Safe_container<
46 	map<_Key, _Tp, _Compare, _Allocator>, _Allocator,
47 	__gnu_debug::_Safe_node_sequence>,
48       public _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Allocator>
49     {
50       typedef _GLIBCXX_STD_C::map<
51 	_Key, _Tp, _Compare, _Allocator>			_Base;
52       typedef __gnu_debug::_Safe_container<
53 	map, _Allocator, __gnu_debug::_Safe_node_sequence>	_Safe;
54 
55       typedef typename _Base::const_iterator	_Base_const_iterator;
56       typedef typename _Base::iterator		_Base_iterator;
57       typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
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 
69       typedef __gnu_debug::_Safe_iterator<_Base_iterator, map>
70 							iterator;
71       typedef __gnu_debug::_Safe_iterator<_Base_const_iterator, map>
72 							const_iterator;
73 
74       typedef typename _Base::size_type			size_type;
75       typedef typename _Base::difference_type		difference_type;
76       typedef typename _Base::pointer			pointer;
77       typedef typename _Base::const_pointer		const_pointer;
78       typedef std::reverse_iterator<iterator>		reverse_iterator;
79       typedef std::reverse_iterator<const_iterator>	const_reverse_iterator;
80 
81       // 23.3.1.1 construct/copy/destroy:
82 
83 #if __cplusplus < 201103L
84       map() : _Base() { }
85 
86       map(const map& __x)
87       : _Base(__x) { }
88 
89       ~map() { }
90 #else
91       map() = default;
92       map(const map&) = default;
93       map(map&&) = default;
94 
95       map(initializer_list<value_type> __l,
96 	  const _Compare& __c = _Compare(),
97 	  const allocator_type& __a = allocator_type())
98       : _Base(__l, __c, __a) { }
99 
100       explicit
101       map(const allocator_type& __a)
102       : _Base(__a) { }
103 
104       map(const map& __m, const allocator_type& __a)
105       : _Base(__m, __a) { }
106 
107       map(map&& __m, const allocator_type& __a)
108       : _Safe(std::move(__m._M_safe()), __a),
109 	_Base(std::move(__m._M_base()), __a) { }
110 
111       map(initializer_list<value_type> __l, const allocator_type& __a)
112       : _Base(__l, __a) { }
113 
114       template<typename _InputIterator>
115 	map(_InputIterator __first, _InputIterator __last,
116 	    const allocator_type& __a)
117 	: _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
118 								     __last)),
119 		__gnu_debug::__base(__last), __a)
120 	{ }
121 
122       ~map() = default;
123 #endif
124 
125       map(const _Base& __x)
126       : _Base(__x) { }
127 
128       explicit map(const _Compare& __comp,
129 		   const _Allocator& __a = _Allocator())
130       : _Base(__comp, __a) { }
131 
132       template<typename _InputIterator>
133 	map(_InputIterator __first, _InputIterator __last,
134 	    const _Compare& __comp = _Compare(),
135 	    const _Allocator& __a = _Allocator())
136 	: _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
137 								     __last)),
138 		__gnu_debug::__base(__last),
139 		__comp, __a) { }
140 
141 #if __cplusplus < 201103L
142       map&
143       operator=(const map& __x)
144       {
145 	this->_M_safe() = __x;
146 	_M_base() = __x;
147 	return *this;
148       }
149 #else
150       map&
151       operator=(const map&) = default;
152 
153       map&
154       operator=(map&&) = default;
155 
156       map&
157       operator=(initializer_list<value_type> __l)
158       {
159 	_M_base() = __l;
160 	this->_M_invalidate_all();
161 	return *this;
162       }
163 #endif
164 
165       // _GLIBCXX_RESOLVE_LIB_DEFECTS
166       // 133. map missing get_allocator()
167       using _Base::get_allocator;
168 
169       // iterators:
170       iterator
171       begin() _GLIBCXX_NOEXCEPT
172       { return iterator(_Base::begin(), this); }
173 
174       const_iterator
175       begin() const _GLIBCXX_NOEXCEPT
176       { return const_iterator(_Base::begin(), this); }
177 
178       iterator
179       end() _GLIBCXX_NOEXCEPT
180       { return iterator(_Base::end(), this); }
181 
182       const_iterator
183       end() const _GLIBCXX_NOEXCEPT
184       { return const_iterator(_Base::end(), this); }
185 
186       reverse_iterator
187       rbegin() _GLIBCXX_NOEXCEPT
188       { return reverse_iterator(end()); }
189 
190       const_reverse_iterator
191       rbegin() const _GLIBCXX_NOEXCEPT
192       { return const_reverse_iterator(end()); }
193 
194       reverse_iterator
195       rend() _GLIBCXX_NOEXCEPT
196       { return reverse_iterator(begin()); }
197 
198       const_reverse_iterator
199       rend() const _GLIBCXX_NOEXCEPT
200       { return const_reverse_iterator(begin()); }
201 
202 #if __cplusplus >= 201103L
203       const_iterator
204       cbegin() const noexcept
205       { return const_iterator(_Base::begin(), this); }
206 
207       const_iterator
208       cend() const noexcept
209       { return const_iterator(_Base::end(), this); }
210 
211       const_reverse_iterator
212       crbegin() const noexcept
213       { return const_reverse_iterator(end()); }
214 
215       const_reverse_iterator
216       crend() const noexcept
217       { return const_reverse_iterator(begin()); }
218 #endif
219 
220       // capacity:
221       using _Base::empty;
222       using _Base::size;
223       using _Base::max_size;
224 
225       // 23.3.1.2 element access:
226       using _Base::operator[];
227 
228       // _GLIBCXX_RESOLVE_LIB_DEFECTS
229       // DR 464. Suggestion for new member functions in standard containers.
230       using _Base::at;
231 
232       // modifiers:
233 #if __cplusplus >= 201103L
234       template<typename... _Args>
235 	std::pair<iterator, bool>
236 	emplace(_Args&&... __args)
237 	{
238 	  auto __res = _Base::emplace(std::forward<_Args>(__args)...);
239 	  return std::pair<iterator, bool>(iterator(__res.first, this),
240 					   __res.second);
241 	}
242 
243       template<typename... _Args>
244 	iterator
245 	emplace_hint(const_iterator __pos, _Args&&... __args)
246 	{
247 	  __glibcxx_check_insert(__pos);
248 	  return iterator(_Base::emplace_hint(__pos.base(),
249 					      std::forward<_Args>(__args)...),
250 			  this);
251 	}
252 #endif
253 
254       std::pair<iterator, bool>
255       insert(const value_type& __x)
256       {
257 	std::pair<_Base_iterator, bool> __res = _Base::insert(__x);
258 	return std::pair<iterator, bool>(iterator(__res.first, this),
259 					 __res.second);
260       }
261 
262 #if __cplusplus >= 201103L
263       // _GLIBCXX_RESOLVE_LIB_DEFECTS
264       // 2354. Unnecessary copying when inserting into maps with braced-init
265       std::pair<iterator, bool>
266       insert(value_type&& __x)
267       {
268 	auto __res = _Base::insert(std::move(__x));
269 	return { iterator(__res.first, this), __res.second };
270       }
271 
272       template<typename _Pair, typename = typename
273 	       std::enable_if<std::is_constructible<value_type,
274 						    _Pair&&>::value>::type>
275 	std::pair<iterator, bool>
276 	insert(_Pair&& __x)
277 	{
278 	  std::pair<_Base_iterator, bool> __res
279 	    = _Base::insert(std::forward<_Pair>(__x));
280 	  return std::pair<iterator, bool>(iterator(__res.first, this),
281 					   __res.second);
282 	}
283 #endif
284 
285 #if __cplusplus >= 201103L
286       void
287       insert(std::initializer_list<value_type> __list)
288       { _Base::insert(__list); }
289 #endif
290 
291       iterator
292 #if __cplusplus >= 201103L
293       insert(const_iterator __position, const value_type& __x)
294 #else
295       insert(iterator __position, const value_type& __x)
296 #endif
297       {
298 	__glibcxx_check_insert(__position);
299 	return iterator(_Base::insert(__position.base(), __x), this);
300       }
301 
302 #if __cplusplus >= 201103L
303       // _GLIBCXX_RESOLVE_LIB_DEFECTS
304       // 2354. Unnecessary copying when inserting into maps with braced-init
305       iterator
306       insert(const_iterator __position, value_type&& __x)
307       {
308 	__glibcxx_check_insert(__position);
309 	return { _Base::insert(__position.base(), std::move(__x)), this };
310       }
311 
312       template<typename _Pair, typename = typename
313 	       std::enable_if<std::is_constructible<value_type,
314 						    _Pair&&>::value>::type>
315 	iterator
316 	insert(const_iterator __position, _Pair&& __x)
317 	{
318 	  __glibcxx_check_insert(__position);
319 	  return iterator(_Base::insert(__position.base(),
320 					std::forward<_Pair>(__x)), this);
321 	}
322 #endif
323 
324       template<typename _InputIterator>
325 	void
326 	insert(_InputIterator __first, _InputIterator __last)
327 	{
328 	  typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
329 	  __glibcxx_check_valid_range2(__first, __last, __dist);
330 
331 	  if (__dist.second >= __gnu_debug::__dp_sign)
332 	    _Base::insert(__gnu_debug::__unsafe(__first),
333 			  __gnu_debug::__unsafe(__last));
334 	  else
335 	    _Base::insert(__first, __last);
336 	}
337 
338 
339 #if __cplusplus > 201402L
340       template <typename... _Args>
341         pair<iterator, bool>
342         try_emplace(const key_type& __k, _Args&&... __args)
343         {
344 	  auto __res = _Base::try_emplace(__k,
345 					  std::forward<_Args>(__args)...);
346 	  return { iterator(__res.first, this), __res.second };
347 	}
348 
349       template <typename... _Args>
350         pair<iterator, bool>
351         try_emplace(key_type&& __k, _Args&&... __args)
352         {
353 	  auto __res = _Base::try_emplace(std::move(__k),
354 					  std::forward<_Args>(__args)...);
355 	  return { iterator(__res.first, this), __res.second };
356 	}
357 
358       template <typename... _Args>
359         iterator
360         try_emplace(const_iterator __hint, const key_type& __k,
361                     _Args&&... __args)
362         {
363 	  __glibcxx_check_insert(__hint);
364 	  return iterator(_Base::try_emplace(__hint.base(), __k,
365 					     std::forward<_Args>(__args)...),
366 			  this);
367 	}
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 
379       template <typename _Obj>
380         std::pair<iterator, bool>
381         insert_or_assign(const key_type& __k, _Obj&& __obj)
382 	{
383 	  auto __res = _Base::insert_or_assign(__k,
384 					       std::forward<_Obj>(__obj));
385 	  return { iterator(__res.first, this), __res.second };
386 	}
387 
388       template <typename _Obj>
389         std::pair<iterator, bool>
390         insert_or_assign(key_type&& __k, _Obj&& __obj)
391 	{
392 	  auto __res = _Base::insert_or_assign(std::move(__k),
393 					       std::forward<_Obj>(__obj));
394 	  return { iterator(__res.first, this), __res.second };
395 	}
396 
397       template <typename _Obj>
398         iterator
399         insert_or_assign(const_iterator __hint,
400                          const key_type& __k, _Obj&& __obj)
401 	{
402 	  __glibcxx_check_insert(__hint);
403 	  return iterator(_Base::insert_or_assign(__hint.base(), __k,
404 						  std::forward<_Obj>(__obj)),
405 			  this);
406 	}
407 
408       template <typename _Obj>
409         iterator
410         insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
411         {
412 	  __glibcxx_check_insert(__hint);
413 	  return iterator(_Base::insert_or_assign(__hint.base(),
414 						  std::move(__k),
415 						  std::forward<_Obj>(__obj)),
416 			  this);
417 	}
418 #endif // C++17
419 
420 #if __cplusplus > 201402L
421       using node_type = typename _Base::node_type;
422       using insert_return_type = _Node_insert_return<iterator, node_type>;
423 
424       node_type
425       extract(const_iterator __position)
426       {
427 	__glibcxx_check_erase(__position);
428 	this->_M_invalidate_if(_Equal(__position.base()));
429 	return _Base::extract(__position.base());
430       }
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 
441       insert_return_type
442       insert(node_type&& __nh)
443       {
444 	auto __ret = _Base::insert(std::move(__nh));
445 	iterator __pos = iterator(__ret.position, this);
446 	return { __pos, __ret.inserted, std::move(__ret.node) };
447       }
448 
449       iterator
450       insert(const_iterator __hint, node_type&& __nh)
451       {
452 	__glibcxx_check_insert(__hint);
453 	return iterator(_Base::insert(__hint.base(), std::move(__nh)), this);
454       }
455 
456       using _Base::merge;
457 #endif // C++17
458 
459 #if __cplusplus >= 201103L
460       iterator
461       erase(const_iterator __position)
462       {
463 	__glibcxx_check_erase(__position);
464 	this->_M_invalidate_if(_Equal(__position.base()));
465 	return iterator(_Base::erase(__position.base()), this);
466       }
467 
468       iterator
469       erase(iterator __position)
470       { return erase(const_iterator(__position)); }
471 #else
472       void
473       erase(iterator __position)
474       {
475 	__glibcxx_check_erase(__position);
476 	this->_M_invalidate_if(_Equal(__position.base()));
477 	_Base::erase(__position.base());
478       }
479 #endif
480 
481       size_type
482       erase(const key_type& __x)
483       {
484 	_Base_iterator __victim = _Base::find(__x);
485 	if (__victim == _Base::end())
486 	  return 0;
487 	else
488 	  {
489 	    this->_M_invalidate_if(_Equal(__victim));
490 	    _Base::erase(__victim);
491 	    return 1;
492 	  }
493       }
494 
495 #if __cplusplus >= 201103L
496       iterator
497       erase(const_iterator __first, const_iterator __last)
498       {
499 	// _GLIBCXX_RESOLVE_LIB_DEFECTS
500 	// 151. can't currently clear() empty container
501 	__glibcxx_check_erase_range(__first, __last);
502 	for (_Base_const_iterator __victim = __first.base();
503 	     __victim != __last.base(); ++__victim)
504 	  {
505 	    _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
506 				  _M_message(__gnu_debug::__msg_valid_range)
507 				  ._M_iterator(__first, "first")
508 				  ._M_iterator(__last, "last"));
509 	    this->_M_invalidate_if(_Equal(__victim));
510 	  }
511 	return iterator(_Base::erase(__first.base(), __last.base()), this);
512       }
513 #else
514       void
515       erase(iterator __first, iterator __last)
516       {
517 	// _GLIBCXX_RESOLVE_LIB_DEFECTS
518 	// 151. can't currently clear() empty container
519 	__glibcxx_check_erase_range(__first, __last);
520 	for (_Base_iterator __victim = __first.base();
521 	     __victim != __last.base(); ++__victim)
522 	  {
523 	    _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
524 				  _M_message(__gnu_debug::__msg_valid_range)
525 				  ._M_iterator(__first, "first")
526 				  ._M_iterator(__last, "last"));
527 	    this->_M_invalidate_if(_Equal(__victim));
528 	  }
529 	_Base::erase(__first.base(), __last.base());
530       }
531 #endif
532 
533       void
534       swap(map& __x)
535       _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
536       {
537 	_Safe::_M_swap(__x);
538 	_Base::swap(__x);
539       }
540 
541       void
542       clear() _GLIBCXX_NOEXCEPT
543       {
544 	this->_M_invalidate_all();
545 	_Base::clear();
546       }
547 
548       // observers:
549       using _Base::key_comp;
550       using _Base::value_comp;
551 
552       // 23.3.1.3 map operations:
553       iterator
554       find(const key_type& __x)
555       { return iterator(_Base::find(__x), this); }
556 
557 #if __cplusplus > 201103L
558       template<typename _Kt,
559 	       typename _Req =
560 		 typename __has_is_transparent<_Compare, _Kt>::type>
561 	iterator
562 	find(const _Kt& __x)
563 	{ return { _Base::find(__x), this }; }
564 #endif
565 
566       const_iterator
567       find(const key_type& __x) const
568       { return const_iterator(_Base::find(__x), this); }
569 
570 #if __cplusplus > 201103L
571       template<typename _Kt,
572 	       typename _Req =
573 		 typename __has_is_transparent<_Compare, _Kt>::type>
574 	const_iterator
575 	find(const _Kt& __x) const
576 	{ return { _Base::find(__x), this }; }
577 #endif
578 
579       using _Base::count;
580 
581       iterator
582       lower_bound(const key_type& __x)
583       { return iterator(_Base::lower_bound(__x), this); }
584 
585 #if __cplusplus > 201103L
586       template<typename _Kt,
587 	       typename _Req =
588 		 typename __has_is_transparent<_Compare, _Kt>::type>
589 	iterator
590 	lower_bound(const _Kt& __x)
591 	{ return { _Base::lower_bound(__x), this }; }
592 #endif
593 
594       const_iterator
595       lower_bound(const key_type& __x) const
596       { return const_iterator(_Base::lower_bound(__x), this); }
597 
598 #if __cplusplus > 201103L
599       template<typename _Kt,
600 	       typename _Req =
601 		 typename __has_is_transparent<_Compare, _Kt>::type>
602 	const_iterator
603 	lower_bound(const _Kt& __x) const
604 	{ return { _Base::lower_bound(__x), this }; }
605 #endif
606 
607       iterator
608       upper_bound(const key_type& __x)
609       { return iterator(_Base::upper_bound(__x), this); }
610 
611 #if __cplusplus > 201103L
612       template<typename _Kt,
613 	       typename _Req =
614 		 typename __has_is_transparent<_Compare, _Kt>::type>
615 	iterator
616 	upper_bound(const _Kt& __x)
617 	{ return { _Base::upper_bound(__x), this }; }
618 #endif
619 
620       const_iterator
621       upper_bound(const key_type& __x) const
622       { return const_iterator(_Base::upper_bound(__x), this); }
623 
624 #if __cplusplus > 201103L
625       template<typename _Kt,
626 	       typename _Req =
627 		 typename __has_is_transparent<_Compare, _Kt>::type>
628 	const_iterator
629 	upper_bound(const _Kt& __x) const
630 	{ return { _Base::upper_bound(__x), this }; }
631 #endif
632 
633       std::pair<iterator,iterator>
634       equal_range(const key_type& __x)
635       {
636 	std::pair<_Base_iterator, _Base_iterator> __res =
637 	_Base::equal_range(__x);
638 	return std::make_pair(iterator(__res.first, this),
639 			      iterator(__res.second, this));
640       }
641 
642 #if __cplusplus > 201103L
643       template<typename _Kt,
644 	       typename _Req =
645 		 typename __has_is_transparent<_Compare, _Kt>::type>
646 	std::pair<iterator, iterator>
647 	equal_range(const _Kt& __x)
648 	{
649 	  auto __res = _Base::equal_range(__x);
650 	  return { { __res.first, this }, { __res.second, this } };
651 	}
652 #endif
653 
654       std::pair<const_iterator,const_iterator>
655       equal_range(const key_type& __x) const
656       {
657 	std::pair<_Base_const_iterator, _Base_const_iterator> __res =
658 	_Base::equal_range(__x);
659 	return std::make_pair(const_iterator(__res.first, this),
660 			      const_iterator(__res.second, this));
661       }
662 
663 #if __cplusplus > 201103L
664       template<typename _Kt,
665 	       typename _Req =
666 		 typename __has_is_transparent<_Compare, _Kt>::type>
667 	std::pair<const_iterator, const_iterator>
668 	equal_range(const _Kt& __x) const
669 	{
670 	  auto __res = _Base::equal_range(__x);
671 	  return { { __res.first, this }, { __res.second, this } };
672 	}
673 #endif
674 
675       _Base&
676       _M_base() _GLIBCXX_NOEXCEPT	{ return *this; }
677 
678       const _Base&
679       _M_base() const _GLIBCXX_NOEXCEPT	{ return *this; }
680     };
681 
682 #if __cpp_deduction_guides >= 201606
683 
684  template<typename _InputIterator,
685 	  typename _Compare = less<__iter_key_t<_InputIterator>>,
686 	  typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
687 	  typename = _RequireInputIter<_InputIterator>,
688 	  typename = _RequireAllocator<_Allocator>>
689   map(_InputIterator, _InputIterator,
690       _Compare = _Compare(), _Allocator = _Allocator())
691   -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
692 	 _Compare, _Allocator>;
693 
694  template<typename _Key, typename _Tp, typename _Compare = less<_Key>,
695 	  typename _Allocator = allocator<pair<const _Key, _Tp>>,
696 	  typename = _RequireAllocator<_Allocator>>
697    map(initializer_list<pair<_Key, _Tp>>,
698        _Compare = _Compare(), _Allocator = _Allocator())
699    -> map<_Key, _Tp, _Compare, _Allocator>;
700 
701  template <typename _InputIterator, typename _Allocator,
702 	   typename = _RequireInputIter<_InputIterator>,
703 	   typename = _RequireAllocator<_Allocator>>
704    map(_InputIterator, _InputIterator, _Allocator)
705    -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
706 	  less<__iter_key_t<_InputIterator>>, _Allocator>;
707 
708  template<typename _Key, typename _Tp, typename _Allocator,
709 	  typename = _RequireAllocator<_Allocator>>
710    map(initializer_list<pair<_Key, _Tp>>, _Allocator)
711    -> map<_Key, _Tp, less<_Key>, _Allocator>;
712 
713 #endif
714 
715   template<typename _Key, typename _Tp,
716 	   typename _Compare, typename _Allocator>
717     inline bool
718     operator==(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
719 	       const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
720     { return __lhs._M_base() == __rhs._M_base(); }
721 
722   template<typename _Key, typename _Tp,
723 	   typename _Compare, typename _Allocator>
724     inline bool
725     operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
726 	       const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
727     { return __lhs._M_base() != __rhs._M_base(); }
728 
729   template<typename _Key, typename _Tp,
730 	   typename _Compare, typename _Allocator>
731     inline bool
732     operator<(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
733 	      const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
734     { return __lhs._M_base() < __rhs._M_base(); }
735 
736   template<typename _Key, typename _Tp,
737 	   typename _Compare, typename _Allocator>
738     inline bool
739     operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
740 	       const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
741     { return __lhs._M_base() <= __rhs._M_base(); }
742 
743   template<typename _Key, typename _Tp,
744 	   typename _Compare, typename _Allocator>
745     inline bool
746     operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
747 	       const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
748     { return __lhs._M_base() >= __rhs._M_base(); }
749 
750   template<typename _Key, typename _Tp,
751 	   typename _Compare, typename _Allocator>
752     inline bool
753     operator>(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
754 	      const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
755     { return __lhs._M_base() > __rhs._M_base(); }
756 
757   template<typename _Key, typename _Tp,
758 	   typename _Compare, typename _Allocator>
759     inline void
760     swap(map<_Key, _Tp, _Compare, _Allocator>& __lhs,
761 	 map<_Key, _Tp, _Compare, _Allocator>& __rhs)
762     _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
763     { __lhs.swap(__rhs); }
764 
765 } // namespace __debug
766 } // namespace std
767 
768 #endif
769