xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/bits/stl_iterator.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj // Iterators -*- C++ -*-
2*38fd1498Szrj 
3*38fd1498Szrj // Copyright (C) 2001-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 /*
26*38fd1498Szrj  *
27*38fd1498Szrj  * Copyright (c) 1994
28*38fd1498Szrj  * Hewlett-Packard Company
29*38fd1498Szrj  *
30*38fd1498Szrj  * Permission to use, copy, modify, distribute and sell this software
31*38fd1498Szrj  * and its documentation for any purpose is hereby granted without fee,
32*38fd1498Szrj  * provided that the above copyright notice appear in all copies and
33*38fd1498Szrj  * that both that copyright notice and this permission notice appear
34*38fd1498Szrj  * in supporting documentation.  Hewlett-Packard Company makes no
35*38fd1498Szrj  * representations about the suitability of this software for any
36*38fd1498Szrj  * purpose.  It is provided "as is" without express or implied warranty.
37*38fd1498Szrj  *
38*38fd1498Szrj  *
39*38fd1498Szrj  * Copyright (c) 1996-1998
40*38fd1498Szrj  * Silicon Graphics Computer Systems, Inc.
41*38fd1498Szrj  *
42*38fd1498Szrj  * Permission to use, copy, modify, distribute and sell this software
43*38fd1498Szrj  * and its documentation for any purpose is hereby granted without fee,
44*38fd1498Szrj  * provided that the above copyright notice appear in all copies and
45*38fd1498Szrj  * that both that copyright notice and this permission notice appear
46*38fd1498Szrj  * in supporting documentation.  Silicon Graphics makes no
47*38fd1498Szrj  * representations about the suitability of this software for any
48*38fd1498Szrj  * purpose.  It is provided "as is" without express or implied warranty.
49*38fd1498Szrj  */
50*38fd1498Szrj 
51*38fd1498Szrj /** @file bits/stl_iterator.h
52*38fd1498Szrj  *  This is an internal header file, included by other library headers.
53*38fd1498Szrj  *  Do not attempt to use it directly. @headername{iterator}
54*38fd1498Szrj  *
55*38fd1498Szrj  *  This file implements reverse_iterator, back_insert_iterator,
56*38fd1498Szrj  *  front_insert_iterator, insert_iterator, __normal_iterator, and their
57*38fd1498Szrj  *  supporting functions and overloaded operators.
58*38fd1498Szrj  */
59*38fd1498Szrj 
60*38fd1498Szrj #ifndef _STL_ITERATOR_H
61*38fd1498Szrj #define _STL_ITERATOR_H 1
62*38fd1498Szrj 
63*38fd1498Szrj #include <bits/cpp_type_traits.h>
64*38fd1498Szrj #include <ext/type_traits.h>
65*38fd1498Szrj #include <bits/move.h>
66*38fd1498Szrj #include <bits/ptr_traits.h>
67*38fd1498Szrj 
68*38fd1498Szrj #if __cplusplus > 201402L
69*38fd1498Szrj # define __cpp_lib_array_constexpr 201603
70*38fd1498Szrj #endif
71*38fd1498Szrj 
72*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
73*38fd1498Szrj {
74*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
75*38fd1498Szrj 
76*38fd1498Szrj   /**
77*38fd1498Szrj    * @addtogroup iterators
78*38fd1498Szrj    * @{
79*38fd1498Szrj    */
80*38fd1498Szrj 
81*38fd1498Szrj   // 24.4.1 Reverse iterators
82*38fd1498Szrj   /**
83*38fd1498Szrj    *  Bidirectional and random access iterators have corresponding reverse
84*38fd1498Szrj    *  %iterator adaptors that iterate through the data structure in the
85*38fd1498Szrj    *  opposite direction.  They have the same signatures as the corresponding
86*38fd1498Szrj    *  iterators.  The fundamental relation between a reverse %iterator and its
87*38fd1498Szrj    *  corresponding %iterator @c i is established by the identity:
88*38fd1498Szrj    *  @code
89*38fd1498Szrj    *      &*(reverse_iterator(i)) == &*(i - 1)
90*38fd1498Szrj    *  @endcode
91*38fd1498Szrj    *
92*38fd1498Szrj    *  <em>This mapping is dictated by the fact that while there is always a
93*38fd1498Szrj    *  pointer past the end of an array, there might not be a valid pointer
94*38fd1498Szrj    *  before the beginning of an array.</em> [24.4.1]/1,2
95*38fd1498Szrj    *
96*38fd1498Szrj    *  Reverse iterators can be tricky and surprising at first.  Their
97*38fd1498Szrj    *  semantics make sense, however, and the trickiness is a side effect of
98*38fd1498Szrj    *  the requirement that the iterators must be safe.
99*38fd1498Szrj   */
100*38fd1498Szrj   template<typename _Iterator>
101*38fd1498Szrj     class reverse_iterator
102*38fd1498Szrj     : public iterator<typename iterator_traits<_Iterator>::iterator_category,
103*38fd1498Szrj 		      typename iterator_traits<_Iterator>::value_type,
104*38fd1498Szrj 		      typename iterator_traits<_Iterator>::difference_type,
105*38fd1498Szrj 		      typename iterator_traits<_Iterator>::pointer,
106*38fd1498Szrj                       typename iterator_traits<_Iterator>::reference>
107*38fd1498Szrj     {
108*38fd1498Szrj     protected:
109*38fd1498Szrj       _Iterator current;
110*38fd1498Szrj 
111*38fd1498Szrj       typedef iterator_traits<_Iterator>		__traits_type;
112*38fd1498Szrj 
113*38fd1498Szrj     public:
114*38fd1498Szrj       typedef _Iterator					iterator_type;
115*38fd1498Szrj       typedef typename __traits_type::difference_type	difference_type;
116*38fd1498Szrj       typedef typename __traits_type::pointer		pointer;
117*38fd1498Szrj       typedef typename __traits_type::reference		reference;
118*38fd1498Szrj 
119*38fd1498Szrj       /**
120*38fd1498Szrj        *  The default constructor value-initializes member @p current.
121*38fd1498Szrj        *  If it is a pointer, that means it is zero-initialized.
122*38fd1498Szrj       */
123*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
124*38fd1498Szrj       // 235 No specification of default ctor for reverse_iterator
125*38fd1498Szrj       _GLIBCXX17_CONSTEXPR
126*38fd1498Szrj       reverse_iterator() : current() { }
127*38fd1498Szrj 
128*38fd1498Szrj       /**
129*38fd1498Szrj        *  This %iterator will move in the opposite direction that @p x does.
130*38fd1498Szrj       */
131*38fd1498Szrj       explicit _GLIBCXX17_CONSTEXPR
132*38fd1498Szrj       reverse_iterator(iterator_type __x) : current(__x) { }
133*38fd1498Szrj 
134*38fd1498Szrj       /**
135*38fd1498Szrj        *  The copy constructor is normal.
136*38fd1498Szrj       */
137*38fd1498Szrj       _GLIBCXX17_CONSTEXPR
138*38fd1498Szrj       reverse_iterator(const reverse_iterator& __x)
139*38fd1498Szrj       : current(__x.current) { }
140*38fd1498Szrj 
141*38fd1498Szrj       /**
142*38fd1498Szrj        *  A %reverse_iterator across other types can be copied if the
143*38fd1498Szrj        *  underlying %iterator can be converted to the type of @c current.
144*38fd1498Szrj       */
145*38fd1498Szrj       template<typename _Iter>
146*38fd1498Szrj 	_GLIBCXX17_CONSTEXPR
147*38fd1498Szrj         reverse_iterator(const reverse_iterator<_Iter>& __x)
148*38fd1498Szrj 	: current(__x.base()) { }
149*38fd1498Szrj 
150*38fd1498Szrj       /**
151*38fd1498Szrj        *  @return  @c current, the %iterator used for underlying work.
152*38fd1498Szrj       */
153*38fd1498Szrj       _GLIBCXX17_CONSTEXPR iterator_type
154*38fd1498Szrj       base() const
155*38fd1498Szrj       { return current; }
156*38fd1498Szrj 
157*38fd1498Szrj       /**
158*38fd1498Szrj        *  @return  A reference to the value at @c --current
159*38fd1498Szrj        *
160*38fd1498Szrj        *  This requires that @c --current is dereferenceable.
161*38fd1498Szrj        *
162*38fd1498Szrj        *  @warning This implementation requires that for an iterator of the
163*38fd1498Szrj        *           underlying iterator type, @c x, a reference obtained by
164*38fd1498Szrj        *           @c *x remains valid after @c x has been modified or
165*38fd1498Szrj        *           destroyed. This is a bug: http://gcc.gnu.org/PR51823
166*38fd1498Szrj       */
167*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reference
168*38fd1498Szrj       operator*() const
169*38fd1498Szrj       {
170*38fd1498Szrj 	_Iterator __tmp = current;
171*38fd1498Szrj 	return *--__tmp;
172*38fd1498Szrj       }
173*38fd1498Szrj 
174*38fd1498Szrj       /**
175*38fd1498Szrj        *  @return  A pointer to the value at @c --current
176*38fd1498Szrj        *
177*38fd1498Szrj        *  This requires that @c --current is dereferenceable.
178*38fd1498Szrj       */
179*38fd1498Szrj       _GLIBCXX17_CONSTEXPR pointer
180*38fd1498Szrj       operator->() const
181*38fd1498Szrj       { return &(operator*()); }
182*38fd1498Szrj 
183*38fd1498Szrj       /**
184*38fd1498Szrj        *  @return  @c *this
185*38fd1498Szrj        *
186*38fd1498Szrj        *  Decrements the underlying iterator.
187*38fd1498Szrj       */
188*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reverse_iterator&
189*38fd1498Szrj       operator++()
190*38fd1498Szrj       {
191*38fd1498Szrj 	--current;
192*38fd1498Szrj 	return *this;
193*38fd1498Szrj       }
194*38fd1498Szrj 
195*38fd1498Szrj       /**
196*38fd1498Szrj        *  @return  The original value of @c *this
197*38fd1498Szrj        *
198*38fd1498Szrj        *  Decrements the underlying iterator.
199*38fd1498Szrj       */
200*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reverse_iterator
201*38fd1498Szrj       operator++(int)
202*38fd1498Szrj       {
203*38fd1498Szrj 	reverse_iterator __tmp = *this;
204*38fd1498Szrj 	--current;
205*38fd1498Szrj 	return __tmp;
206*38fd1498Szrj       }
207*38fd1498Szrj 
208*38fd1498Szrj       /**
209*38fd1498Szrj        *  @return  @c *this
210*38fd1498Szrj        *
211*38fd1498Szrj        *  Increments the underlying iterator.
212*38fd1498Szrj       */
213*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reverse_iterator&
214*38fd1498Szrj       operator--()
215*38fd1498Szrj       {
216*38fd1498Szrj 	++current;
217*38fd1498Szrj 	return *this;
218*38fd1498Szrj       }
219*38fd1498Szrj 
220*38fd1498Szrj       /**
221*38fd1498Szrj        *  @return  A reverse_iterator with the previous value of @c *this
222*38fd1498Szrj        *
223*38fd1498Szrj        *  Increments the underlying iterator.
224*38fd1498Szrj       */
225*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reverse_iterator
226*38fd1498Szrj       operator--(int)
227*38fd1498Szrj       {
228*38fd1498Szrj 	reverse_iterator __tmp = *this;
229*38fd1498Szrj 	++current;
230*38fd1498Szrj 	return __tmp;
231*38fd1498Szrj       }
232*38fd1498Szrj 
233*38fd1498Szrj       /**
234*38fd1498Szrj        *  @return  A reverse_iterator that refers to @c current - @a __n
235*38fd1498Szrj        *
236*38fd1498Szrj        *  The underlying iterator must be a Random Access Iterator.
237*38fd1498Szrj       */
238*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reverse_iterator
239*38fd1498Szrj       operator+(difference_type __n) const
240*38fd1498Szrj       { return reverse_iterator(current - __n); }
241*38fd1498Szrj 
242*38fd1498Szrj       /**
243*38fd1498Szrj        *  @return  *this
244*38fd1498Szrj        *
245*38fd1498Szrj        *  Moves the underlying iterator backwards @a __n steps.
246*38fd1498Szrj        *  The underlying iterator must be a Random Access Iterator.
247*38fd1498Szrj       */
248*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reverse_iterator&
249*38fd1498Szrj       operator+=(difference_type __n)
250*38fd1498Szrj       {
251*38fd1498Szrj 	current -= __n;
252*38fd1498Szrj 	return *this;
253*38fd1498Szrj       }
254*38fd1498Szrj 
255*38fd1498Szrj       /**
256*38fd1498Szrj        *  @return  A reverse_iterator that refers to @c current - @a __n
257*38fd1498Szrj        *
258*38fd1498Szrj        *  The underlying iterator must be a Random Access Iterator.
259*38fd1498Szrj       */
260*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reverse_iterator
261*38fd1498Szrj       operator-(difference_type __n) const
262*38fd1498Szrj       { return reverse_iterator(current + __n); }
263*38fd1498Szrj 
264*38fd1498Szrj       /**
265*38fd1498Szrj        *  @return  *this
266*38fd1498Szrj        *
267*38fd1498Szrj        *  Moves the underlying iterator forwards @a __n steps.
268*38fd1498Szrj        *  The underlying iterator must be a Random Access Iterator.
269*38fd1498Szrj       */
270*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reverse_iterator&
271*38fd1498Szrj       operator-=(difference_type __n)
272*38fd1498Szrj       {
273*38fd1498Szrj 	current += __n;
274*38fd1498Szrj 	return *this;
275*38fd1498Szrj       }
276*38fd1498Szrj 
277*38fd1498Szrj       /**
278*38fd1498Szrj        *  @return  The value at @c current - @a __n - 1
279*38fd1498Szrj        *
280*38fd1498Szrj        *  The underlying iterator must be a Random Access Iterator.
281*38fd1498Szrj       */
282*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reference
283*38fd1498Szrj       operator[](difference_type __n) const
284*38fd1498Szrj       { return *(*this + __n); }
285*38fd1498Szrj     };
286*38fd1498Szrj 
287*38fd1498Szrj   //@{
288*38fd1498Szrj   /**
289*38fd1498Szrj    *  @param  __x  A %reverse_iterator.
290*38fd1498Szrj    *  @param  __y  A %reverse_iterator.
291*38fd1498Szrj    *  @return  A simple bool.
292*38fd1498Szrj    *
293*38fd1498Szrj    *  Reverse iterators forward many operations to their underlying base()
294*38fd1498Szrj    *  iterators.  Others are implemented in terms of one another.
295*38fd1498Szrj    *
296*38fd1498Szrj   */
297*38fd1498Szrj   template<typename _Iterator>
298*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
299*38fd1498Szrj     operator==(const reverse_iterator<_Iterator>& __x,
300*38fd1498Szrj 	       const reverse_iterator<_Iterator>& __y)
301*38fd1498Szrj     { return __x.base() == __y.base(); }
302*38fd1498Szrj 
303*38fd1498Szrj   template<typename _Iterator>
304*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
305*38fd1498Szrj     operator<(const reverse_iterator<_Iterator>& __x,
306*38fd1498Szrj 	      const reverse_iterator<_Iterator>& __y)
307*38fd1498Szrj     { return __y.base() < __x.base(); }
308*38fd1498Szrj 
309*38fd1498Szrj   template<typename _Iterator>
310*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
311*38fd1498Szrj     operator!=(const reverse_iterator<_Iterator>& __x,
312*38fd1498Szrj 	       const reverse_iterator<_Iterator>& __y)
313*38fd1498Szrj     { return !(__x == __y); }
314*38fd1498Szrj 
315*38fd1498Szrj   template<typename _Iterator>
316*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
317*38fd1498Szrj     operator>(const reverse_iterator<_Iterator>& __x,
318*38fd1498Szrj 	      const reverse_iterator<_Iterator>& __y)
319*38fd1498Szrj     { return __y < __x; }
320*38fd1498Szrj 
321*38fd1498Szrj   template<typename _Iterator>
322*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
323*38fd1498Szrj     operator<=(const reverse_iterator<_Iterator>& __x,
324*38fd1498Szrj 	       const reverse_iterator<_Iterator>& __y)
325*38fd1498Szrj     { return !(__y < __x); }
326*38fd1498Szrj 
327*38fd1498Szrj   template<typename _Iterator>
328*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
329*38fd1498Szrj     operator>=(const reverse_iterator<_Iterator>& __x,
330*38fd1498Szrj 	       const reverse_iterator<_Iterator>& __y)
331*38fd1498Szrj     { return !(__x < __y); }
332*38fd1498Szrj 
333*38fd1498Szrj   // _GLIBCXX_RESOLVE_LIB_DEFECTS
334*38fd1498Szrj   // DR 280. Comparison of reverse_iterator to const reverse_iterator.
335*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
336*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
337*38fd1498Szrj     operator==(const reverse_iterator<_IteratorL>& __x,
338*38fd1498Szrj 	       const reverse_iterator<_IteratorR>& __y)
339*38fd1498Szrj     { return __x.base() == __y.base(); }
340*38fd1498Szrj 
341*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
342*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
343*38fd1498Szrj     operator<(const reverse_iterator<_IteratorL>& __x,
344*38fd1498Szrj 	      const reverse_iterator<_IteratorR>& __y)
345*38fd1498Szrj     { return __y.base() < __x.base(); }
346*38fd1498Szrj 
347*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
348*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
349*38fd1498Szrj     operator!=(const reverse_iterator<_IteratorL>& __x,
350*38fd1498Szrj 	       const reverse_iterator<_IteratorR>& __y)
351*38fd1498Szrj     { return !(__x == __y); }
352*38fd1498Szrj 
353*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
354*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
355*38fd1498Szrj     operator>(const reverse_iterator<_IteratorL>& __x,
356*38fd1498Szrj 	      const reverse_iterator<_IteratorR>& __y)
357*38fd1498Szrj     { return __y < __x; }
358*38fd1498Szrj 
359*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
360*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
361*38fd1498Szrj     operator<=(const reverse_iterator<_IteratorL>& __x,
362*38fd1498Szrj 	       const reverse_iterator<_IteratorR>& __y)
363*38fd1498Szrj     { return !(__y < __x); }
364*38fd1498Szrj 
365*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
366*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
367*38fd1498Szrj     operator>=(const reverse_iterator<_IteratorL>& __x,
368*38fd1498Szrj 	       const reverse_iterator<_IteratorR>& __y)
369*38fd1498Szrj     { return !(__x < __y); }
370*38fd1498Szrj   //@}
371*38fd1498Szrj 
372*38fd1498Szrj #if __cplusplus < 201103L
373*38fd1498Szrj   template<typename _Iterator>
374*38fd1498Szrj     inline typename reverse_iterator<_Iterator>::difference_type
375*38fd1498Szrj     operator-(const reverse_iterator<_Iterator>& __x,
376*38fd1498Szrj 	      const reverse_iterator<_Iterator>& __y)
377*38fd1498Szrj     { return __y.base() - __x.base(); }
378*38fd1498Szrj 
379*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
380*38fd1498Szrj     inline typename reverse_iterator<_IteratorL>::difference_type
381*38fd1498Szrj     operator-(const reverse_iterator<_IteratorL>& __x,
382*38fd1498Szrj 	      const reverse_iterator<_IteratorR>& __y)
383*38fd1498Szrj     { return __y.base() - __x.base(); }
384*38fd1498Szrj #else
385*38fd1498Szrj   // _GLIBCXX_RESOLVE_LIB_DEFECTS
386*38fd1498Szrj   // DR 685. reverse_iterator/move_iterator difference has invalid signatures
387*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
388*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR auto
389*38fd1498Szrj     operator-(const reverse_iterator<_IteratorL>& __x,
390*38fd1498Szrj 	      const reverse_iterator<_IteratorR>& __y)
391*38fd1498Szrj     -> decltype(__y.base() - __x.base())
392*38fd1498Szrj     { return __y.base() - __x.base(); }
393*38fd1498Szrj #endif
394*38fd1498Szrj 
395*38fd1498Szrj   template<typename _Iterator>
396*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
397*38fd1498Szrj     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
398*38fd1498Szrj 	      const reverse_iterator<_Iterator>& __x)
399*38fd1498Szrj     { return reverse_iterator<_Iterator>(__x.base() - __n); }
400*38fd1498Szrj 
401*38fd1498Szrj #if __cplusplus >= 201103L
402*38fd1498Szrj   // Same as C++14 make_reverse_iterator but used in C++03 mode too.
403*38fd1498Szrj   template<typename _Iterator>
404*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
405*38fd1498Szrj     __make_reverse_iterator(_Iterator __i)
406*38fd1498Szrj     { return reverse_iterator<_Iterator>(__i); }
407*38fd1498Szrj 
408*38fd1498Szrj # if __cplusplus > 201103L
409*38fd1498Szrj #  define __cpp_lib_make_reverse_iterator 201402
410*38fd1498Szrj 
411*38fd1498Szrj   // _GLIBCXX_RESOLVE_LIB_DEFECTS
412*38fd1498Szrj   // DR 2285. make_reverse_iterator
413*38fd1498Szrj   /// Generator function for reverse_iterator.
414*38fd1498Szrj   template<typename _Iterator>
415*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR reverse_iterator<_Iterator>
416*38fd1498Szrj     make_reverse_iterator(_Iterator __i)
417*38fd1498Szrj     { return reverse_iterator<_Iterator>(__i); }
418*38fd1498Szrj # endif
419*38fd1498Szrj #endif
420*38fd1498Szrj 
421*38fd1498Szrj #if __cplusplus >= 201103L
422*38fd1498Szrj   template<typename _Iterator>
423*38fd1498Szrj     auto
424*38fd1498Szrj     __niter_base(reverse_iterator<_Iterator> __it)
425*38fd1498Szrj     -> decltype(__make_reverse_iterator(__niter_base(__it.base())))
426*38fd1498Szrj     { return __make_reverse_iterator(__niter_base(__it.base())); }
427*38fd1498Szrj 
428*38fd1498Szrj   template<typename _Iterator>
429*38fd1498Szrj     struct __is_move_iterator<reverse_iterator<_Iterator> >
430*38fd1498Szrj       : __is_move_iterator<_Iterator>
431*38fd1498Szrj     { };
432*38fd1498Szrj 
433*38fd1498Szrj   template<typename _Iterator>
434*38fd1498Szrj     auto
435*38fd1498Szrj     __miter_base(reverse_iterator<_Iterator> __it)
436*38fd1498Szrj     -> decltype(__make_reverse_iterator(__miter_base(__it.base())))
437*38fd1498Szrj     { return __make_reverse_iterator(__miter_base(__it.base())); }
438*38fd1498Szrj #endif
439*38fd1498Szrj 
440*38fd1498Szrj   // 24.4.2.2.1 back_insert_iterator
441*38fd1498Szrj   /**
442*38fd1498Szrj    *  @brief  Turns assignment into insertion.
443*38fd1498Szrj    *
444*38fd1498Szrj    *  These are output iterators, constructed from a container-of-T.
445*38fd1498Szrj    *  Assigning a T to the iterator appends it to the container using
446*38fd1498Szrj    *  push_back.
447*38fd1498Szrj    *
448*38fd1498Szrj    *  Tip:  Using the back_inserter function to create these iterators can
449*38fd1498Szrj    *  save typing.
450*38fd1498Szrj   */
451*38fd1498Szrj   template<typename _Container>
452*38fd1498Szrj     class back_insert_iterator
453*38fd1498Szrj     : public iterator<output_iterator_tag, void, void, void, void>
454*38fd1498Szrj     {
455*38fd1498Szrj     protected:
456*38fd1498Szrj       _Container* container;
457*38fd1498Szrj 
458*38fd1498Szrj     public:
459*38fd1498Szrj       /// A nested typedef for the type of whatever container you used.
460*38fd1498Szrj       typedef _Container          container_type;
461*38fd1498Szrj 
462*38fd1498Szrj       /// The only way to create this %iterator is with a container.
463*38fd1498Szrj       explicit
464*38fd1498Szrj       back_insert_iterator(_Container& __x)
465*38fd1498Szrj       : container(std::__addressof(__x)) { }
466*38fd1498Szrj 
467*38fd1498Szrj       /**
468*38fd1498Szrj        *  @param  __value  An instance of whatever type
469*38fd1498Szrj        *                 container_type::const_reference is; presumably a
470*38fd1498Szrj        *                 reference-to-const T for container<T>.
471*38fd1498Szrj        *  @return  This %iterator, for chained operations.
472*38fd1498Szrj        *
473*38fd1498Szrj        *  This kind of %iterator doesn't really have a @a position in the
474*38fd1498Szrj        *  container (you can think of the position as being permanently at
475*38fd1498Szrj        *  the end, if you like).  Assigning a value to the %iterator will
476*38fd1498Szrj        *  always append the value to the end of the container.
477*38fd1498Szrj       */
478*38fd1498Szrj #if __cplusplus < 201103L
479*38fd1498Szrj       back_insert_iterator&
480*38fd1498Szrj       operator=(typename _Container::const_reference __value)
481*38fd1498Szrj       {
482*38fd1498Szrj 	container->push_back(__value);
483*38fd1498Szrj 	return *this;
484*38fd1498Szrj       }
485*38fd1498Szrj #else
486*38fd1498Szrj       back_insert_iterator&
487*38fd1498Szrj       operator=(const typename _Container::value_type& __value)
488*38fd1498Szrj       {
489*38fd1498Szrj 	container->push_back(__value);
490*38fd1498Szrj 	return *this;
491*38fd1498Szrj       }
492*38fd1498Szrj 
493*38fd1498Szrj       back_insert_iterator&
494*38fd1498Szrj       operator=(typename _Container::value_type&& __value)
495*38fd1498Szrj       {
496*38fd1498Szrj 	container->push_back(std::move(__value));
497*38fd1498Szrj 	return *this;
498*38fd1498Szrj       }
499*38fd1498Szrj #endif
500*38fd1498Szrj 
501*38fd1498Szrj       /// Simply returns *this.
502*38fd1498Szrj       back_insert_iterator&
503*38fd1498Szrj       operator*()
504*38fd1498Szrj       { return *this; }
505*38fd1498Szrj 
506*38fd1498Szrj       /// Simply returns *this.  (This %iterator does not @a move.)
507*38fd1498Szrj       back_insert_iterator&
508*38fd1498Szrj       operator++()
509*38fd1498Szrj       { return *this; }
510*38fd1498Szrj 
511*38fd1498Szrj       /// Simply returns *this.  (This %iterator does not @a move.)
512*38fd1498Szrj       back_insert_iterator
513*38fd1498Szrj       operator++(int)
514*38fd1498Szrj       { return *this; }
515*38fd1498Szrj     };
516*38fd1498Szrj 
517*38fd1498Szrj   /**
518*38fd1498Szrj    *  @param  __x  A container of arbitrary type.
519*38fd1498Szrj    *  @return  An instance of back_insert_iterator working on @p __x.
520*38fd1498Szrj    *
521*38fd1498Szrj    *  This wrapper function helps in creating back_insert_iterator instances.
522*38fd1498Szrj    *  Typing the name of the %iterator requires knowing the precise full
523*38fd1498Szrj    *  type of the container, which can be tedious and impedes generic
524*38fd1498Szrj    *  programming.  Using this function lets you take advantage of automatic
525*38fd1498Szrj    *  template parameter deduction, making the compiler match the correct
526*38fd1498Szrj    *  types for you.
527*38fd1498Szrj   */
528*38fd1498Szrj   template<typename _Container>
529*38fd1498Szrj     inline back_insert_iterator<_Container>
530*38fd1498Szrj     back_inserter(_Container& __x)
531*38fd1498Szrj     { return back_insert_iterator<_Container>(__x); }
532*38fd1498Szrj 
533*38fd1498Szrj   /**
534*38fd1498Szrj    *  @brief  Turns assignment into insertion.
535*38fd1498Szrj    *
536*38fd1498Szrj    *  These are output iterators, constructed from a container-of-T.
537*38fd1498Szrj    *  Assigning a T to the iterator prepends it to the container using
538*38fd1498Szrj    *  push_front.
539*38fd1498Szrj    *
540*38fd1498Szrj    *  Tip:  Using the front_inserter function to create these iterators can
541*38fd1498Szrj    *  save typing.
542*38fd1498Szrj   */
543*38fd1498Szrj   template<typename _Container>
544*38fd1498Szrj     class front_insert_iterator
545*38fd1498Szrj     : public iterator<output_iterator_tag, void, void, void, void>
546*38fd1498Szrj     {
547*38fd1498Szrj     protected:
548*38fd1498Szrj       _Container* container;
549*38fd1498Szrj 
550*38fd1498Szrj     public:
551*38fd1498Szrj       /// A nested typedef for the type of whatever container you used.
552*38fd1498Szrj       typedef _Container          container_type;
553*38fd1498Szrj 
554*38fd1498Szrj       /// The only way to create this %iterator is with a container.
555*38fd1498Szrj       explicit front_insert_iterator(_Container& __x)
556*38fd1498Szrj       : container(std::__addressof(__x)) { }
557*38fd1498Szrj 
558*38fd1498Szrj       /**
559*38fd1498Szrj        *  @param  __value  An instance of whatever type
560*38fd1498Szrj        *                 container_type::const_reference is; presumably a
561*38fd1498Szrj        *                 reference-to-const T for container<T>.
562*38fd1498Szrj        *  @return  This %iterator, for chained operations.
563*38fd1498Szrj        *
564*38fd1498Szrj        *  This kind of %iterator doesn't really have a @a position in the
565*38fd1498Szrj        *  container (you can think of the position as being permanently at
566*38fd1498Szrj        *  the front, if you like).  Assigning a value to the %iterator will
567*38fd1498Szrj        *  always prepend the value to the front of the container.
568*38fd1498Szrj       */
569*38fd1498Szrj #if __cplusplus < 201103L
570*38fd1498Szrj       front_insert_iterator&
571*38fd1498Szrj       operator=(typename _Container::const_reference __value)
572*38fd1498Szrj       {
573*38fd1498Szrj 	container->push_front(__value);
574*38fd1498Szrj 	return *this;
575*38fd1498Szrj       }
576*38fd1498Szrj #else
577*38fd1498Szrj       front_insert_iterator&
578*38fd1498Szrj       operator=(const typename _Container::value_type& __value)
579*38fd1498Szrj       {
580*38fd1498Szrj 	container->push_front(__value);
581*38fd1498Szrj 	return *this;
582*38fd1498Szrj       }
583*38fd1498Szrj 
584*38fd1498Szrj       front_insert_iterator&
585*38fd1498Szrj       operator=(typename _Container::value_type&& __value)
586*38fd1498Szrj       {
587*38fd1498Szrj 	container->push_front(std::move(__value));
588*38fd1498Szrj 	return *this;
589*38fd1498Szrj       }
590*38fd1498Szrj #endif
591*38fd1498Szrj 
592*38fd1498Szrj       /// Simply returns *this.
593*38fd1498Szrj       front_insert_iterator&
594*38fd1498Szrj       operator*()
595*38fd1498Szrj       { return *this; }
596*38fd1498Szrj 
597*38fd1498Szrj       /// Simply returns *this.  (This %iterator does not @a move.)
598*38fd1498Szrj       front_insert_iterator&
599*38fd1498Szrj       operator++()
600*38fd1498Szrj       { return *this; }
601*38fd1498Szrj 
602*38fd1498Szrj       /// Simply returns *this.  (This %iterator does not @a move.)
603*38fd1498Szrj       front_insert_iterator
604*38fd1498Szrj       operator++(int)
605*38fd1498Szrj       { return *this; }
606*38fd1498Szrj     };
607*38fd1498Szrj 
608*38fd1498Szrj   /**
609*38fd1498Szrj    *  @param  __x  A container of arbitrary type.
610*38fd1498Szrj    *  @return  An instance of front_insert_iterator working on @p x.
611*38fd1498Szrj    *
612*38fd1498Szrj    *  This wrapper function helps in creating front_insert_iterator instances.
613*38fd1498Szrj    *  Typing the name of the %iterator requires knowing the precise full
614*38fd1498Szrj    *  type of the container, which can be tedious and impedes generic
615*38fd1498Szrj    *  programming.  Using this function lets you take advantage of automatic
616*38fd1498Szrj    *  template parameter deduction, making the compiler match the correct
617*38fd1498Szrj    *  types for you.
618*38fd1498Szrj   */
619*38fd1498Szrj   template<typename _Container>
620*38fd1498Szrj     inline front_insert_iterator<_Container>
621*38fd1498Szrj     front_inserter(_Container& __x)
622*38fd1498Szrj     { return front_insert_iterator<_Container>(__x); }
623*38fd1498Szrj 
624*38fd1498Szrj   /**
625*38fd1498Szrj    *  @brief  Turns assignment into insertion.
626*38fd1498Szrj    *
627*38fd1498Szrj    *  These are output iterators, constructed from a container-of-T.
628*38fd1498Szrj    *  Assigning a T to the iterator inserts it in the container at the
629*38fd1498Szrj    *  %iterator's position, rather than overwriting the value at that
630*38fd1498Szrj    *  position.
631*38fd1498Szrj    *
632*38fd1498Szrj    *  (Sequences will actually insert a @e copy of the value before the
633*38fd1498Szrj    *  %iterator's position.)
634*38fd1498Szrj    *
635*38fd1498Szrj    *  Tip:  Using the inserter function to create these iterators can
636*38fd1498Szrj    *  save typing.
637*38fd1498Szrj   */
638*38fd1498Szrj   template<typename _Container>
639*38fd1498Szrj     class insert_iterator
640*38fd1498Szrj     : public iterator<output_iterator_tag, void, void, void, void>
641*38fd1498Szrj     {
642*38fd1498Szrj     protected:
643*38fd1498Szrj       _Container* container;
644*38fd1498Szrj       typename _Container::iterator iter;
645*38fd1498Szrj 
646*38fd1498Szrj     public:
647*38fd1498Szrj       /// A nested typedef for the type of whatever container you used.
648*38fd1498Szrj       typedef _Container          container_type;
649*38fd1498Szrj 
650*38fd1498Szrj       /**
651*38fd1498Szrj        *  The only way to create this %iterator is with a container and an
652*38fd1498Szrj        *  initial position (a normal %iterator into the container).
653*38fd1498Szrj       */
654*38fd1498Szrj       insert_iterator(_Container& __x, typename _Container::iterator __i)
655*38fd1498Szrj       : container(std::__addressof(__x)), iter(__i) {}
656*38fd1498Szrj 
657*38fd1498Szrj       /**
658*38fd1498Szrj        *  @param  __value  An instance of whatever type
659*38fd1498Szrj        *                 container_type::const_reference is; presumably a
660*38fd1498Szrj        *                 reference-to-const T for container<T>.
661*38fd1498Szrj        *  @return  This %iterator, for chained operations.
662*38fd1498Szrj        *
663*38fd1498Szrj        *  This kind of %iterator maintains its own position in the
664*38fd1498Szrj        *  container.  Assigning a value to the %iterator will insert the
665*38fd1498Szrj        *  value into the container at the place before the %iterator.
666*38fd1498Szrj        *
667*38fd1498Szrj        *  The position is maintained such that subsequent assignments will
668*38fd1498Szrj        *  insert values immediately after one another.  For example,
669*38fd1498Szrj        *  @code
670*38fd1498Szrj        *     // vector v contains A and Z
671*38fd1498Szrj        *
672*38fd1498Szrj        *     insert_iterator i (v, ++v.begin());
673*38fd1498Szrj        *     i = 1;
674*38fd1498Szrj        *     i = 2;
675*38fd1498Szrj        *     i = 3;
676*38fd1498Szrj        *
677*38fd1498Szrj        *     // vector v contains A, 1, 2, 3, and Z
678*38fd1498Szrj        *  @endcode
679*38fd1498Szrj       */
680*38fd1498Szrj #if __cplusplus < 201103L
681*38fd1498Szrj       insert_iterator&
682*38fd1498Szrj       operator=(typename _Container::const_reference __value)
683*38fd1498Szrj       {
684*38fd1498Szrj 	iter = container->insert(iter, __value);
685*38fd1498Szrj 	++iter;
686*38fd1498Szrj 	return *this;
687*38fd1498Szrj       }
688*38fd1498Szrj #else
689*38fd1498Szrj       insert_iterator&
690*38fd1498Szrj       operator=(const typename _Container::value_type& __value)
691*38fd1498Szrj       {
692*38fd1498Szrj 	iter = container->insert(iter, __value);
693*38fd1498Szrj 	++iter;
694*38fd1498Szrj 	return *this;
695*38fd1498Szrj       }
696*38fd1498Szrj 
697*38fd1498Szrj       insert_iterator&
698*38fd1498Szrj       operator=(typename _Container::value_type&& __value)
699*38fd1498Szrj       {
700*38fd1498Szrj 	iter = container->insert(iter, std::move(__value));
701*38fd1498Szrj 	++iter;
702*38fd1498Szrj 	return *this;
703*38fd1498Szrj       }
704*38fd1498Szrj #endif
705*38fd1498Szrj 
706*38fd1498Szrj       /// Simply returns *this.
707*38fd1498Szrj       insert_iterator&
708*38fd1498Szrj       operator*()
709*38fd1498Szrj       { return *this; }
710*38fd1498Szrj 
711*38fd1498Szrj       /// Simply returns *this.  (This %iterator does not @a move.)
712*38fd1498Szrj       insert_iterator&
713*38fd1498Szrj       operator++()
714*38fd1498Szrj       { return *this; }
715*38fd1498Szrj 
716*38fd1498Szrj       /// Simply returns *this.  (This %iterator does not @a move.)
717*38fd1498Szrj       insert_iterator&
718*38fd1498Szrj       operator++(int)
719*38fd1498Szrj       { return *this; }
720*38fd1498Szrj     };
721*38fd1498Szrj 
722*38fd1498Szrj   /**
723*38fd1498Szrj    *  @param __x  A container of arbitrary type.
724*38fd1498Szrj    *  @param __i  An iterator into the container.
725*38fd1498Szrj    *  @return  An instance of insert_iterator working on @p __x.
726*38fd1498Szrj    *
727*38fd1498Szrj    *  This wrapper function helps in creating insert_iterator instances.
728*38fd1498Szrj    *  Typing the name of the %iterator requires knowing the precise full
729*38fd1498Szrj    *  type of the container, which can be tedious and impedes generic
730*38fd1498Szrj    *  programming.  Using this function lets you take advantage of automatic
731*38fd1498Szrj    *  template parameter deduction, making the compiler match the correct
732*38fd1498Szrj    *  types for you.
733*38fd1498Szrj   */
734*38fd1498Szrj   template<typename _Container, typename _Iterator>
735*38fd1498Szrj     inline insert_iterator<_Container>
736*38fd1498Szrj     inserter(_Container& __x, _Iterator __i)
737*38fd1498Szrj     {
738*38fd1498Szrj       return insert_iterator<_Container>(__x,
739*38fd1498Szrj 					 typename _Container::iterator(__i));
740*38fd1498Szrj     }
741*38fd1498Szrj 
742*38fd1498Szrj   // @} group iterators
743*38fd1498Szrj 
744*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
745*38fd1498Szrj } // namespace
746*38fd1498Szrj 
747*38fd1498Szrj namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
748*38fd1498Szrj {
749*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
750*38fd1498Szrj 
751*38fd1498Szrj   // This iterator adapter is @a normal in the sense that it does not
752*38fd1498Szrj   // change the semantics of any of the operators of its iterator
753*38fd1498Szrj   // parameter.  Its primary purpose is to convert an iterator that is
754*38fd1498Szrj   // not a class, e.g. a pointer, into an iterator that is a class.
755*38fd1498Szrj   // The _Container parameter exists solely so that different containers
756*38fd1498Szrj   // using this template can instantiate different types, even if the
757*38fd1498Szrj   // _Iterator parameter is the same.
758*38fd1498Szrj   using std::iterator_traits;
759*38fd1498Szrj   using std::iterator;
760*38fd1498Szrj   template<typename _Iterator, typename _Container>
761*38fd1498Szrj     class __normal_iterator
762*38fd1498Szrj     {
763*38fd1498Szrj     protected:
764*38fd1498Szrj       _Iterator _M_current;
765*38fd1498Szrj 
766*38fd1498Szrj       typedef iterator_traits<_Iterator>		__traits_type;
767*38fd1498Szrj 
768*38fd1498Szrj     public:
769*38fd1498Szrj       typedef _Iterator					iterator_type;
770*38fd1498Szrj       typedef typename __traits_type::iterator_category iterator_category;
771*38fd1498Szrj       typedef typename __traits_type::value_type  	value_type;
772*38fd1498Szrj       typedef typename __traits_type::difference_type 	difference_type;
773*38fd1498Szrj       typedef typename __traits_type::reference 	reference;
774*38fd1498Szrj       typedef typename __traits_type::pointer   	pointer;
775*38fd1498Szrj 
776*38fd1498Szrj       _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT
777*38fd1498Szrj       : _M_current(_Iterator()) { }
778*38fd1498Szrj 
779*38fd1498Szrj       explicit
780*38fd1498Szrj       __normal_iterator(const _Iterator& __i) _GLIBCXX_NOEXCEPT
781*38fd1498Szrj       : _M_current(__i) { }
782*38fd1498Szrj 
783*38fd1498Szrj       // Allow iterator to const_iterator conversion
784*38fd1498Szrj       template<typename _Iter>
785*38fd1498Szrj         __normal_iterator(const __normal_iterator<_Iter,
786*38fd1498Szrj 			  typename __enable_if<
787*38fd1498Szrj       	       (std::__are_same<_Iter, typename _Container::pointer>::__value),
788*38fd1498Szrj 		      _Container>::__type>& __i) _GLIBCXX_NOEXCEPT
789*38fd1498Szrj         : _M_current(__i.base()) { }
790*38fd1498Szrj 
791*38fd1498Szrj       // Forward iterator requirements
792*38fd1498Szrj       reference
793*38fd1498Szrj       operator*() const _GLIBCXX_NOEXCEPT
794*38fd1498Szrj       { return *_M_current; }
795*38fd1498Szrj 
796*38fd1498Szrj       pointer
797*38fd1498Szrj       operator->() const _GLIBCXX_NOEXCEPT
798*38fd1498Szrj       { return _M_current; }
799*38fd1498Szrj 
800*38fd1498Szrj       __normal_iterator&
801*38fd1498Szrj       operator++() _GLIBCXX_NOEXCEPT
802*38fd1498Szrj       {
803*38fd1498Szrj 	++_M_current;
804*38fd1498Szrj 	return *this;
805*38fd1498Szrj       }
806*38fd1498Szrj 
807*38fd1498Szrj       __normal_iterator
808*38fd1498Szrj       operator++(int) _GLIBCXX_NOEXCEPT
809*38fd1498Szrj       { return __normal_iterator(_M_current++); }
810*38fd1498Szrj 
811*38fd1498Szrj       // Bidirectional iterator requirements
812*38fd1498Szrj       __normal_iterator&
813*38fd1498Szrj       operator--() _GLIBCXX_NOEXCEPT
814*38fd1498Szrj       {
815*38fd1498Szrj 	--_M_current;
816*38fd1498Szrj 	return *this;
817*38fd1498Szrj       }
818*38fd1498Szrj 
819*38fd1498Szrj       __normal_iterator
820*38fd1498Szrj       operator--(int) _GLIBCXX_NOEXCEPT
821*38fd1498Szrj       { return __normal_iterator(_M_current--); }
822*38fd1498Szrj 
823*38fd1498Szrj       // Random access iterator requirements
824*38fd1498Szrj       reference
825*38fd1498Szrj       operator[](difference_type __n) const _GLIBCXX_NOEXCEPT
826*38fd1498Szrj       { return _M_current[__n]; }
827*38fd1498Szrj 
828*38fd1498Szrj       __normal_iterator&
829*38fd1498Szrj       operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
830*38fd1498Szrj       { _M_current += __n; return *this; }
831*38fd1498Szrj 
832*38fd1498Szrj       __normal_iterator
833*38fd1498Szrj       operator+(difference_type __n) const _GLIBCXX_NOEXCEPT
834*38fd1498Szrj       { return __normal_iterator(_M_current + __n); }
835*38fd1498Szrj 
836*38fd1498Szrj       __normal_iterator&
837*38fd1498Szrj       operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
838*38fd1498Szrj       { _M_current -= __n; return *this; }
839*38fd1498Szrj 
840*38fd1498Szrj       __normal_iterator
841*38fd1498Szrj       operator-(difference_type __n) const _GLIBCXX_NOEXCEPT
842*38fd1498Szrj       { return __normal_iterator(_M_current - __n); }
843*38fd1498Szrj 
844*38fd1498Szrj       const _Iterator&
845*38fd1498Szrj       base() const _GLIBCXX_NOEXCEPT
846*38fd1498Szrj       { return _M_current; }
847*38fd1498Szrj     };
848*38fd1498Szrj 
849*38fd1498Szrj   // Note: In what follows, the left- and right-hand-side iterators are
850*38fd1498Szrj   // allowed to vary in types (conceptually in cv-qualification) so that
851*38fd1498Szrj   // comparison between cv-qualified and non-cv-qualified iterators be
852*38fd1498Szrj   // valid.  However, the greedy and unfriendly operators in std::rel_ops
853*38fd1498Szrj   // will make overload resolution ambiguous (when in scope) if we don't
854*38fd1498Szrj   // provide overloads whose operands are of the same type.  Can someone
855*38fd1498Szrj   // remind me what generic programming is about? -- Gaby
856*38fd1498Szrj 
857*38fd1498Szrj   // Forward iterator requirements
858*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR, typename _Container>
859*38fd1498Szrj     inline bool
860*38fd1498Szrj     operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
861*38fd1498Szrj 	       const __normal_iterator<_IteratorR, _Container>& __rhs)
862*38fd1498Szrj     _GLIBCXX_NOEXCEPT
863*38fd1498Szrj     { return __lhs.base() == __rhs.base(); }
864*38fd1498Szrj 
865*38fd1498Szrj   template<typename _Iterator, typename _Container>
866*38fd1498Szrj     inline bool
867*38fd1498Szrj     operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
868*38fd1498Szrj 	       const __normal_iterator<_Iterator, _Container>& __rhs)
869*38fd1498Szrj     _GLIBCXX_NOEXCEPT
870*38fd1498Szrj     { return __lhs.base() == __rhs.base(); }
871*38fd1498Szrj 
872*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR, typename _Container>
873*38fd1498Szrj     inline bool
874*38fd1498Szrj     operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
875*38fd1498Szrj 	       const __normal_iterator<_IteratorR, _Container>& __rhs)
876*38fd1498Szrj     _GLIBCXX_NOEXCEPT
877*38fd1498Szrj     { return __lhs.base() != __rhs.base(); }
878*38fd1498Szrj 
879*38fd1498Szrj   template<typename _Iterator, typename _Container>
880*38fd1498Szrj     inline bool
881*38fd1498Szrj     operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
882*38fd1498Szrj 	       const __normal_iterator<_Iterator, _Container>& __rhs)
883*38fd1498Szrj     _GLIBCXX_NOEXCEPT
884*38fd1498Szrj     { return __lhs.base() != __rhs.base(); }
885*38fd1498Szrj 
886*38fd1498Szrj   // Random access iterator requirements
887*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR, typename _Container>
888*38fd1498Szrj     inline bool
889*38fd1498Szrj     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
890*38fd1498Szrj 	      const __normal_iterator<_IteratorR, _Container>& __rhs)
891*38fd1498Szrj     _GLIBCXX_NOEXCEPT
892*38fd1498Szrj     { return __lhs.base() < __rhs.base(); }
893*38fd1498Szrj 
894*38fd1498Szrj   template<typename _Iterator, typename _Container>
895*38fd1498Szrj     inline bool
896*38fd1498Szrj     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
897*38fd1498Szrj 	      const __normal_iterator<_Iterator, _Container>& __rhs)
898*38fd1498Szrj     _GLIBCXX_NOEXCEPT
899*38fd1498Szrj     { return __lhs.base() < __rhs.base(); }
900*38fd1498Szrj 
901*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR, typename _Container>
902*38fd1498Szrj     inline bool
903*38fd1498Szrj     operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
904*38fd1498Szrj 	      const __normal_iterator<_IteratorR, _Container>& __rhs)
905*38fd1498Szrj     _GLIBCXX_NOEXCEPT
906*38fd1498Szrj     { return __lhs.base() > __rhs.base(); }
907*38fd1498Szrj 
908*38fd1498Szrj   template<typename _Iterator, typename _Container>
909*38fd1498Szrj     inline bool
910*38fd1498Szrj     operator>(const __normal_iterator<_Iterator, _Container>& __lhs,
911*38fd1498Szrj 	      const __normal_iterator<_Iterator, _Container>& __rhs)
912*38fd1498Szrj     _GLIBCXX_NOEXCEPT
913*38fd1498Szrj     { return __lhs.base() > __rhs.base(); }
914*38fd1498Szrj 
915*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR, typename _Container>
916*38fd1498Szrj     inline bool
917*38fd1498Szrj     operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
918*38fd1498Szrj 	       const __normal_iterator<_IteratorR, _Container>& __rhs)
919*38fd1498Szrj     _GLIBCXX_NOEXCEPT
920*38fd1498Szrj     { return __lhs.base() <= __rhs.base(); }
921*38fd1498Szrj 
922*38fd1498Szrj   template<typename _Iterator, typename _Container>
923*38fd1498Szrj     inline bool
924*38fd1498Szrj     operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
925*38fd1498Szrj 	       const __normal_iterator<_Iterator, _Container>& __rhs)
926*38fd1498Szrj     _GLIBCXX_NOEXCEPT
927*38fd1498Szrj     { return __lhs.base() <= __rhs.base(); }
928*38fd1498Szrj 
929*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR, typename _Container>
930*38fd1498Szrj     inline bool
931*38fd1498Szrj     operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs,
932*38fd1498Szrj 	       const __normal_iterator<_IteratorR, _Container>& __rhs)
933*38fd1498Szrj     _GLIBCXX_NOEXCEPT
934*38fd1498Szrj     { return __lhs.base() >= __rhs.base(); }
935*38fd1498Szrj 
936*38fd1498Szrj   template<typename _Iterator, typename _Container>
937*38fd1498Szrj     inline bool
938*38fd1498Szrj     operator>=(const __normal_iterator<_Iterator, _Container>& __lhs,
939*38fd1498Szrj 	       const __normal_iterator<_Iterator, _Container>& __rhs)
940*38fd1498Szrj     _GLIBCXX_NOEXCEPT
941*38fd1498Szrj     { return __lhs.base() >= __rhs.base(); }
942*38fd1498Szrj 
943*38fd1498Szrj   // _GLIBCXX_RESOLVE_LIB_DEFECTS
944*38fd1498Szrj   // According to the resolution of DR179 not only the various comparison
945*38fd1498Szrj   // operators but also operator- must accept mixed iterator/const_iterator
946*38fd1498Szrj   // parameters.
947*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR, typename _Container>
948*38fd1498Szrj #if __cplusplus >= 201103L
949*38fd1498Szrj     // DR 685.
950*38fd1498Szrj     inline auto
951*38fd1498Szrj     operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
952*38fd1498Szrj 	      const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept
953*38fd1498Szrj     -> decltype(__lhs.base() - __rhs.base())
954*38fd1498Szrj #else
955*38fd1498Szrj     inline typename __normal_iterator<_IteratorL, _Container>::difference_type
956*38fd1498Szrj     operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
957*38fd1498Szrj 	      const __normal_iterator<_IteratorR, _Container>& __rhs)
958*38fd1498Szrj #endif
959*38fd1498Szrj     { return __lhs.base() - __rhs.base(); }
960*38fd1498Szrj 
961*38fd1498Szrj   template<typename _Iterator, typename _Container>
962*38fd1498Szrj     inline typename __normal_iterator<_Iterator, _Container>::difference_type
963*38fd1498Szrj     operator-(const __normal_iterator<_Iterator, _Container>& __lhs,
964*38fd1498Szrj 	      const __normal_iterator<_Iterator, _Container>& __rhs)
965*38fd1498Szrj     _GLIBCXX_NOEXCEPT
966*38fd1498Szrj     { return __lhs.base() - __rhs.base(); }
967*38fd1498Szrj 
968*38fd1498Szrj   template<typename _Iterator, typename _Container>
969*38fd1498Szrj     inline __normal_iterator<_Iterator, _Container>
970*38fd1498Szrj     operator+(typename __normal_iterator<_Iterator, _Container>::difference_type
971*38fd1498Szrj 	      __n, const __normal_iterator<_Iterator, _Container>& __i)
972*38fd1498Szrj     _GLIBCXX_NOEXCEPT
973*38fd1498Szrj     { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
974*38fd1498Szrj 
975*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
976*38fd1498Szrj } // namespace
977*38fd1498Szrj 
978*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
979*38fd1498Szrj {
980*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
981*38fd1498Szrj 
982*38fd1498Szrj   template<typename _Iterator, typename _Container>
983*38fd1498Szrj     _Iterator
984*38fd1498Szrj     __niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container> __it)
985*38fd1498Szrj     { return __it.base(); }
986*38fd1498Szrj 
987*38fd1498Szrj #if __cplusplus >= 201103L
988*38fd1498Szrj 
989*38fd1498Szrj   /**
990*38fd1498Szrj    * @addtogroup iterators
991*38fd1498Szrj    * @{
992*38fd1498Szrj    */
993*38fd1498Szrj 
994*38fd1498Szrj   // 24.4.3  Move iterators
995*38fd1498Szrj   /**
996*38fd1498Szrj    *  Class template move_iterator is an iterator adapter with the same
997*38fd1498Szrj    *  behavior as the underlying iterator except that its dereference
998*38fd1498Szrj    *  operator implicitly converts the value returned by the underlying
999*38fd1498Szrj    *  iterator's dereference operator to an rvalue reference.  Some
1000*38fd1498Szrj    *  generic algorithms can be called with move iterators to replace
1001*38fd1498Szrj    *  copying with moving.
1002*38fd1498Szrj    */
1003*38fd1498Szrj   template<typename _Iterator>
1004*38fd1498Szrj     class move_iterator
1005*38fd1498Szrj     {
1006*38fd1498Szrj     protected:
1007*38fd1498Szrj       _Iterator _M_current;
1008*38fd1498Szrj 
1009*38fd1498Szrj       typedef iterator_traits<_Iterator>		__traits_type;
1010*38fd1498Szrj       typedef typename __traits_type::reference		__base_ref;
1011*38fd1498Szrj 
1012*38fd1498Szrj     public:
1013*38fd1498Szrj       typedef _Iterator					iterator_type;
1014*38fd1498Szrj       typedef typename __traits_type::iterator_category iterator_category;
1015*38fd1498Szrj       typedef typename __traits_type::value_type  	value_type;
1016*38fd1498Szrj       typedef typename __traits_type::difference_type	difference_type;
1017*38fd1498Szrj       // NB: DR 680.
1018*38fd1498Szrj       typedef _Iterator					pointer;
1019*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
1020*38fd1498Szrj       // 2106. move_iterator wrapping iterators returning prvalues
1021*38fd1498Szrj       typedef typename conditional<is_reference<__base_ref>::value,
1022*38fd1498Szrj 			 typename remove_reference<__base_ref>::type&&,
1023*38fd1498Szrj 			 __base_ref>::type		reference;
1024*38fd1498Szrj 
1025*38fd1498Szrj       _GLIBCXX17_CONSTEXPR
1026*38fd1498Szrj       move_iterator()
1027*38fd1498Szrj       : _M_current() { }
1028*38fd1498Szrj 
1029*38fd1498Szrj       explicit _GLIBCXX17_CONSTEXPR
1030*38fd1498Szrj       move_iterator(iterator_type __i)
1031*38fd1498Szrj       : _M_current(__i) { }
1032*38fd1498Szrj 
1033*38fd1498Szrj       template<typename _Iter>
1034*38fd1498Szrj 	_GLIBCXX17_CONSTEXPR
1035*38fd1498Szrj 	move_iterator(const move_iterator<_Iter>& __i)
1036*38fd1498Szrj 	: _M_current(__i.base()) { }
1037*38fd1498Szrj 
1038*38fd1498Szrj       _GLIBCXX17_CONSTEXPR iterator_type
1039*38fd1498Szrj       base() const
1040*38fd1498Szrj       { return _M_current; }
1041*38fd1498Szrj 
1042*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reference
1043*38fd1498Szrj       operator*() const
1044*38fd1498Szrj       { return static_cast<reference>(*_M_current); }
1045*38fd1498Szrj 
1046*38fd1498Szrj       _GLIBCXX17_CONSTEXPR pointer
1047*38fd1498Szrj       operator->() const
1048*38fd1498Szrj       { return _M_current; }
1049*38fd1498Szrj 
1050*38fd1498Szrj       _GLIBCXX17_CONSTEXPR move_iterator&
1051*38fd1498Szrj       operator++()
1052*38fd1498Szrj       {
1053*38fd1498Szrj 	++_M_current;
1054*38fd1498Szrj 	return *this;
1055*38fd1498Szrj       }
1056*38fd1498Szrj 
1057*38fd1498Szrj       _GLIBCXX17_CONSTEXPR move_iterator
1058*38fd1498Szrj       operator++(int)
1059*38fd1498Szrj       {
1060*38fd1498Szrj 	move_iterator __tmp = *this;
1061*38fd1498Szrj 	++_M_current;
1062*38fd1498Szrj 	return __tmp;
1063*38fd1498Szrj       }
1064*38fd1498Szrj 
1065*38fd1498Szrj       _GLIBCXX17_CONSTEXPR move_iterator&
1066*38fd1498Szrj       operator--()
1067*38fd1498Szrj       {
1068*38fd1498Szrj 	--_M_current;
1069*38fd1498Szrj 	return *this;
1070*38fd1498Szrj       }
1071*38fd1498Szrj 
1072*38fd1498Szrj       _GLIBCXX17_CONSTEXPR move_iterator
1073*38fd1498Szrj       operator--(int)
1074*38fd1498Szrj       {
1075*38fd1498Szrj 	move_iterator __tmp = *this;
1076*38fd1498Szrj 	--_M_current;
1077*38fd1498Szrj 	return __tmp;
1078*38fd1498Szrj       }
1079*38fd1498Szrj 
1080*38fd1498Szrj       _GLIBCXX17_CONSTEXPR move_iterator
1081*38fd1498Szrj       operator+(difference_type __n) const
1082*38fd1498Szrj       { return move_iterator(_M_current + __n); }
1083*38fd1498Szrj 
1084*38fd1498Szrj       _GLIBCXX17_CONSTEXPR move_iterator&
1085*38fd1498Szrj       operator+=(difference_type __n)
1086*38fd1498Szrj       {
1087*38fd1498Szrj 	_M_current += __n;
1088*38fd1498Szrj 	return *this;
1089*38fd1498Szrj       }
1090*38fd1498Szrj 
1091*38fd1498Szrj       _GLIBCXX17_CONSTEXPR move_iterator
1092*38fd1498Szrj       operator-(difference_type __n) const
1093*38fd1498Szrj       { return move_iterator(_M_current - __n); }
1094*38fd1498Szrj 
1095*38fd1498Szrj       _GLIBCXX17_CONSTEXPR move_iterator&
1096*38fd1498Szrj       operator-=(difference_type __n)
1097*38fd1498Szrj       {
1098*38fd1498Szrj 	_M_current -= __n;
1099*38fd1498Szrj 	return *this;
1100*38fd1498Szrj       }
1101*38fd1498Szrj 
1102*38fd1498Szrj       _GLIBCXX17_CONSTEXPR reference
1103*38fd1498Szrj       operator[](difference_type __n) const
1104*38fd1498Szrj       { return std::move(_M_current[__n]); }
1105*38fd1498Szrj     };
1106*38fd1498Szrj 
1107*38fd1498Szrj   // Note: See __normal_iterator operators note from Gaby to understand
1108*38fd1498Szrj   // why there are always 2 versions for most of the move_iterator
1109*38fd1498Szrj   // operators.
1110*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
1111*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1112*38fd1498Szrj     operator==(const move_iterator<_IteratorL>& __x,
1113*38fd1498Szrj 	       const move_iterator<_IteratorR>& __y)
1114*38fd1498Szrj     { return __x.base() == __y.base(); }
1115*38fd1498Szrj 
1116*38fd1498Szrj   template<typename _Iterator>
1117*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1118*38fd1498Szrj     operator==(const move_iterator<_Iterator>& __x,
1119*38fd1498Szrj 	       const move_iterator<_Iterator>& __y)
1120*38fd1498Szrj     { return __x.base() == __y.base(); }
1121*38fd1498Szrj 
1122*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
1123*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1124*38fd1498Szrj     operator!=(const move_iterator<_IteratorL>& __x,
1125*38fd1498Szrj 	       const move_iterator<_IteratorR>& __y)
1126*38fd1498Szrj     { return !(__x == __y); }
1127*38fd1498Szrj 
1128*38fd1498Szrj   template<typename _Iterator>
1129*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1130*38fd1498Szrj     operator!=(const move_iterator<_Iterator>& __x,
1131*38fd1498Szrj 	       const move_iterator<_Iterator>& __y)
1132*38fd1498Szrj     { return !(__x == __y); }
1133*38fd1498Szrj 
1134*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
1135*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1136*38fd1498Szrj     operator<(const move_iterator<_IteratorL>& __x,
1137*38fd1498Szrj 	      const move_iterator<_IteratorR>& __y)
1138*38fd1498Szrj     { return __x.base() < __y.base(); }
1139*38fd1498Szrj 
1140*38fd1498Szrj   template<typename _Iterator>
1141*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1142*38fd1498Szrj     operator<(const move_iterator<_Iterator>& __x,
1143*38fd1498Szrj 	      const move_iterator<_Iterator>& __y)
1144*38fd1498Szrj     { return __x.base() < __y.base(); }
1145*38fd1498Szrj 
1146*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
1147*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1148*38fd1498Szrj     operator<=(const move_iterator<_IteratorL>& __x,
1149*38fd1498Szrj 	       const move_iterator<_IteratorR>& __y)
1150*38fd1498Szrj     { return !(__y < __x); }
1151*38fd1498Szrj 
1152*38fd1498Szrj   template<typename _Iterator>
1153*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1154*38fd1498Szrj     operator<=(const move_iterator<_Iterator>& __x,
1155*38fd1498Szrj 	       const move_iterator<_Iterator>& __y)
1156*38fd1498Szrj     { return !(__y < __x); }
1157*38fd1498Szrj 
1158*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
1159*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1160*38fd1498Szrj     operator>(const move_iterator<_IteratorL>& __x,
1161*38fd1498Szrj 	      const move_iterator<_IteratorR>& __y)
1162*38fd1498Szrj     { return __y < __x; }
1163*38fd1498Szrj 
1164*38fd1498Szrj   template<typename _Iterator>
1165*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1166*38fd1498Szrj     operator>(const move_iterator<_Iterator>& __x,
1167*38fd1498Szrj 	      const move_iterator<_Iterator>& __y)
1168*38fd1498Szrj     { return __y < __x; }
1169*38fd1498Szrj 
1170*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
1171*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1172*38fd1498Szrj     operator>=(const move_iterator<_IteratorL>& __x,
1173*38fd1498Szrj 	       const move_iterator<_IteratorR>& __y)
1174*38fd1498Szrj     { return !(__x < __y); }
1175*38fd1498Szrj 
1176*38fd1498Szrj   template<typename _Iterator>
1177*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR bool
1178*38fd1498Szrj     operator>=(const move_iterator<_Iterator>& __x,
1179*38fd1498Szrj 	       const move_iterator<_Iterator>& __y)
1180*38fd1498Szrj     { return !(__x < __y); }
1181*38fd1498Szrj 
1182*38fd1498Szrj   // DR 685.
1183*38fd1498Szrj   template<typename _IteratorL, typename _IteratorR>
1184*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR auto
1185*38fd1498Szrj     operator-(const move_iterator<_IteratorL>& __x,
1186*38fd1498Szrj 	      const move_iterator<_IteratorR>& __y)
1187*38fd1498Szrj     -> decltype(__x.base() - __y.base())
1188*38fd1498Szrj     { return __x.base() - __y.base(); }
1189*38fd1498Szrj 
1190*38fd1498Szrj   template<typename _Iterator>
1191*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
1192*38fd1498Szrj     operator+(typename move_iterator<_Iterator>::difference_type __n,
1193*38fd1498Szrj 	      const move_iterator<_Iterator>& __x)
1194*38fd1498Szrj     { return __x + __n; }
1195*38fd1498Szrj 
1196*38fd1498Szrj   template<typename _Iterator>
1197*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
1198*38fd1498Szrj     make_move_iterator(_Iterator __i)
1199*38fd1498Szrj     { return move_iterator<_Iterator>(__i); }
1200*38fd1498Szrj 
1201*38fd1498Szrj   template<typename _Iterator, typename _ReturnType
1202*38fd1498Szrj     = typename conditional<__move_if_noexcept_cond
1203*38fd1498Szrj       <typename iterator_traits<_Iterator>::value_type>::value,
1204*38fd1498Szrj                 _Iterator, move_iterator<_Iterator>>::type>
1205*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR _ReturnType
1206*38fd1498Szrj     __make_move_if_noexcept_iterator(_Iterator __i)
1207*38fd1498Szrj     { return _ReturnType(__i); }
1208*38fd1498Szrj 
1209*38fd1498Szrj   // Overload for pointers that matches std::move_if_noexcept more closely,
1210*38fd1498Szrj   // returning a constant iterator when we don't want to move.
1211*38fd1498Szrj   template<typename _Tp, typename _ReturnType
1212*38fd1498Szrj     = typename conditional<__move_if_noexcept_cond<_Tp>::value,
1213*38fd1498Szrj 			   const _Tp*, move_iterator<_Tp*>>::type>
1214*38fd1498Szrj     inline _GLIBCXX17_CONSTEXPR _ReturnType
1215*38fd1498Szrj     __make_move_if_noexcept_iterator(_Tp* __i)
1216*38fd1498Szrj     { return _ReturnType(__i); }
1217*38fd1498Szrj 
1218*38fd1498Szrj   // @} group iterators
1219*38fd1498Szrj 
1220*38fd1498Szrj   template<typename _Iterator>
1221*38fd1498Szrj     auto
1222*38fd1498Szrj     __niter_base(move_iterator<_Iterator> __it)
1223*38fd1498Szrj     -> decltype(make_move_iterator(__niter_base(__it.base())))
1224*38fd1498Szrj     { return make_move_iterator(__niter_base(__it.base())); }
1225*38fd1498Szrj 
1226*38fd1498Szrj   template<typename _Iterator>
1227*38fd1498Szrj     struct __is_move_iterator<move_iterator<_Iterator> >
1228*38fd1498Szrj     {
1229*38fd1498Szrj       enum { __value = 1 };
1230*38fd1498Szrj       typedef __true_type __type;
1231*38fd1498Szrj     };
1232*38fd1498Szrj 
1233*38fd1498Szrj   template<typename _Iterator>
1234*38fd1498Szrj     auto
1235*38fd1498Szrj     __miter_base(move_iterator<_Iterator> __it)
1236*38fd1498Szrj     -> decltype(__miter_base(__it.base()))
1237*38fd1498Szrj     { return __miter_base(__it.base()); }
1238*38fd1498Szrj 
1239*38fd1498Szrj #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
1240*38fd1498Szrj #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) \
1241*38fd1498Szrj   std::__make_move_if_noexcept_iterator(_Iter)
1242*38fd1498Szrj #else
1243*38fd1498Szrj #define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter)
1244*38fd1498Szrj #define _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(_Iter) (_Iter)
1245*38fd1498Szrj #endif // C++11
1246*38fd1498Szrj 
1247*38fd1498Szrj #if __cpp_deduction_guides >= 201606
1248*38fd1498Szrj   // These helper traits are used for deduction guides
1249*38fd1498Szrj   // of associative containers.
1250*38fd1498Szrj   template<typename _InputIterator>
1251*38fd1498Szrj     using __iter_key_t = remove_const_t<
1252*38fd1498Szrj     typename iterator_traits<_InputIterator>::value_type::first_type>;
1253*38fd1498Szrj 
1254*38fd1498Szrj   template<typename _InputIterator>
1255*38fd1498Szrj     using __iter_val_t =
1256*38fd1498Szrj     typename iterator_traits<_InputIterator>::value_type::second_type;
1257*38fd1498Szrj 
1258*38fd1498Szrj   template<typename _T1, typename _T2>
1259*38fd1498Szrj     struct pair;
1260*38fd1498Szrj 
1261*38fd1498Szrj   template<typename _InputIterator>
1262*38fd1498Szrj     using __iter_to_alloc_t =
1263*38fd1498Szrj     pair<add_const_t<__iter_key_t<_InputIterator>>,
1264*38fd1498Szrj 	 __iter_val_t<_InputIterator>>;
1265*38fd1498Szrj 
1266*38fd1498Szrj #endif
1267*38fd1498Szrj 
1268*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
1269*38fd1498Szrj } // namespace
1270*38fd1498Szrj 
1271*38fd1498Szrj #ifdef _GLIBCXX_DEBUG
1272*38fd1498Szrj # include <debug/stl_iterator.h>
1273*38fd1498Szrj #endif
1274*38fd1498Szrj 
1275*38fd1498Szrj #endif
1276