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