xref: /freebsd/contrib/llvm-project/libcxx/include/iterator (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric// -*- C++ -*-
2*0b57cec5SDimitry Andric//===-------------------------- iterator ----------------------------------===//
3*0b57cec5SDimitry Andric//
4*0b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*0b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6*0b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*0b57cec5SDimitry Andric//
8*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
9*0b57cec5SDimitry Andric
10*0b57cec5SDimitry Andric#ifndef _LIBCPP_ITERATOR
11*0b57cec5SDimitry Andric#define _LIBCPP_ITERATOR
12*0b57cec5SDimitry Andric
13*0b57cec5SDimitry Andric/*
14*0b57cec5SDimitry Andric    iterator synopsis
15*0b57cec5SDimitry Andric
16*0b57cec5SDimitry Andricnamespace std
17*0b57cec5SDimitry Andric{
18*0b57cec5SDimitry Andric
19*0b57cec5SDimitry Andrictemplate<class Iterator>
20*0b57cec5SDimitry Andricstruct iterator_traits
21*0b57cec5SDimitry Andric{
22*0b57cec5SDimitry Andric    typedef typename Iterator::difference_type difference_type;
23*0b57cec5SDimitry Andric    typedef typename Iterator::value_type value_type;
24*0b57cec5SDimitry Andric    typedef typename Iterator::pointer pointer;
25*0b57cec5SDimitry Andric    typedef typename Iterator::reference reference;
26*0b57cec5SDimitry Andric    typedef typename Iterator::iterator_category iterator_category;
27*0b57cec5SDimitry Andric};
28*0b57cec5SDimitry Andric
29*0b57cec5SDimitry Andrictemplate<class T>
30*0b57cec5SDimitry Andricstruct iterator_traits<T*>
31*0b57cec5SDimitry Andric{
32*0b57cec5SDimitry Andric    typedef ptrdiff_t difference_type;
33*0b57cec5SDimitry Andric    typedef T value_type;
34*0b57cec5SDimitry Andric    typedef T* pointer;
35*0b57cec5SDimitry Andric    typedef T& reference;
36*0b57cec5SDimitry Andric    typedef random_access_iterator_tag iterator_category;
37*0b57cec5SDimitry Andric};
38*0b57cec5SDimitry Andric
39*0b57cec5SDimitry Andrictemplate<class Category, class T, class Distance = ptrdiff_t,
40*0b57cec5SDimitry Andric         class Pointer = T*, class Reference = T&>
41*0b57cec5SDimitry Andricstruct iterator
42*0b57cec5SDimitry Andric{
43*0b57cec5SDimitry Andric    typedef T         value_type;
44*0b57cec5SDimitry Andric    typedef Distance  difference_type;
45*0b57cec5SDimitry Andric    typedef Pointer   pointer;
46*0b57cec5SDimitry Andric    typedef Reference reference;
47*0b57cec5SDimitry Andric    typedef Category  iterator_category;
48*0b57cec5SDimitry Andric};
49*0b57cec5SDimitry Andric
50*0b57cec5SDimitry Andricstruct input_iterator_tag  {};
51*0b57cec5SDimitry Andricstruct output_iterator_tag {};
52*0b57cec5SDimitry Andricstruct forward_iterator_tag       : public input_iterator_tag         {};
53*0b57cec5SDimitry Andricstruct bidirectional_iterator_tag : public forward_iterator_tag       {};
54*0b57cec5SDimitry Andricstruct random_access_iterator_tag : public bidirectional_iterator_tag {};
55*0b57cec5SDimitry Andric
56*0b57cec5SDimitry Andric// 27.4.3, iterator operations
57*0b57cec5SDimitry Andric// extension: second argument not conforming to C++03
58*0b57cec5SDimitry Andrictemplate <class InputIterator>  // constexpr in C++17
59*0b57cec5SDimitry Andric  constexpr void advance(InputIterator& i,
60*0b57cec5SDimitry Andric             typename iterator_traits<InputIterator>::difference_type n);
61*0b57cec5SDimitry Andric
62*0b57cec5SDimitry Andrictemplate <class InputIterator>  // constexpr in C++17
63*0b57cec5SDimitry Andric  constexpr typename iterator_traits<InputIterator>::difference_type
64*0b57cec5SDimitry Andric    distance(InputIterator first, InputIterator last);
65*0b57cec5SDimitry Andric
66*0b57cec5SDimitry Andrictemplate <class InputIterator>  // constexpr in C++17
67*0b57cec5SDimitry Andric  constexpr InputIterator next(InputIterator x,
68*0b57cec5SDimitry Andrictypename iterator_traits<InputIterator>::difference_type n = 1);
69*0b57cec5SDimitry Andric
70*0b57cec5SDimitry Andrictemplate <class BidirectionalIterator>  // constexpr in C++17
71*0b57cec5SDimitry Andric  constexpr BidirectionalIterator prev(BidirectionalIterator x,
72*0b57cec5SDimitry Andric    typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
73*0b57cec5SDimitry Andric
74*0b57cec5SDimitry Andrictemplate <class Iterator>
75*0b57cec5SDimitry Andricclass reverse_iterator
76*0b57cec5SDimitry Andric    : public iterator<typename iterator_traits<Iterator>::iterator_category,
77*0b57cec5SDimitry Andric                      typename iterator_traits<Iterator>::value_type,
78*0b57cec5SDimitry Andric                      typename iterator_traits<Iterator>::difference_type,
79*0b57cec5SDimitry Andric                      typename iterator_traits<Iterator>::pointer,
80*0b57cec5SDimitry Andric                      typename iterator_traits<Iterator>::reference>
81*0b57cec5SDimitry Andric{
82*0b57cec5SDimitry Andricprotected:
83*0b57cec5SDimitry Andric    Iterator current;
84*0b57cec5SDimitry Andricpublic:
85*0b57cec5SDimitry Andric    typedef Iterator                                            iterator_type;
86*0b57cec5SDimitry Andric    typedef typename iterator_traits<Iterator>::difference_type difference_type;
87*0b57cec5SDimitry Andric    typedef typename iterator_traits<Iterator>::reference       reference;
88*0b57cec5SDimitry Andric    typedef typename iterator_traits<Iterator>::pointer         pointer;
89*0b57cec5SDimitry Andric
90*0b57cec5SDimitry Andric    constexpr reverse_iterator();
91*0b57cec5SDimitry Andric    constexpr explicit reverse_iterator(Iterator x);
92*0b57cec5SDimitry Andric    template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
93*0b57cec5SDimitry Andric    template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
94*0b57cec5SDimitry Andric    constexpr Iterator base() const;
95*0b57cec5SDimitry Andric    constexpr reference operator*() const;
96*0b57cec5SDimitry Andric    constexpr pointer   operator->() const;
97*0b57cec5SDimitry Andric    constexpr reverse_iterator& operator++();
98*0b57cec5SDimitry Andric    constexpr reverse_iterator  operator++(int);
99*0b57cec5SDimitry Andric    constexpr reverse_iterator& operator--();
100*0b57cec5SDimitry Andric    constexpr reverse_iterator  operator--(int);
101*0b57cec5SDimitry Andric    constexpr reverse_iterator  operator+ (difference_type n) const;
102*0b57cec5SDimitry Andric    constexpr reverse_iterator& operator+=(difference_type n);
103*0b57cec5SDimitry Andric    constexpr reverse_iterator  operator- (difference_type n) const;
104*0b57cec5SDimitry Andric    constexpr reverse_iterator& operator-=(difference_type n);
105*0b57cec5SDimitry Andric    constexpr reference         operator[](difference_type n) const;
106*0b57cec5SDimitry Andric};
107*0b57cec5SDimitry Andric
108*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
109*0b57cec5SDimitry Andricconstexpr bool                          // constexpr in C++17
110*0b57cec5SDimitry Andricoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
111*0b57cec5SDimitry Andric
112*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
113*0b57cec5SDimitry Andricconstexpr bool                          // constexpr in C++17
114*0b57cec5SDimitry Andricoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
115*0b57cec5SDimitry Andric
116*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
117*0b57cec5SDimitry Andricconstexpr bool                          // constexpr in C++17
118*0b57cec5SDimitry Andricoperator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
119*0b57cec5SDimitry Andric
120*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
121*0b57cec5SDimitry Andricconstexpr bool                          // constexpr in C++17
122*0b57cec5SDimitry Andricoperator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
123*0b57cec5SDimitry Andric
124*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
125*0b57cec5SDimitry Andricconstexpr bool                          // constexpr in C++17
126*0b57cec5SDimitry Andricoperator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
127*0b57cec5SDimitry Andric
128*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
129*0b57cec5SDimitry Andricconstexpr bool                          // constexpr in C++17
130*0b57cec5SDimitry Andricoperator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
131*0b57cec5SDimitry Andric
132*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
133*0b57cec5SDimitry Andricconstexpr auto
134*0b57cec5SDimitry Andricoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
135*0b57cec5SDimitry Andric-> decltype(__y.base() - __x.base());   // constexpr in C++17
136*0b57cec5SDimitry Andric
137*0b57cec5SDimitry Andrictemplate <class Iterator>
138*0b57cec5SDimitry Andricconstexpr reverse_iterator<Iterator>
139*0b57cec5SDimitry Andricoperator+(typename reverse_iterator<Iterator>::difference_type n,
140*0b57cec5SDimitry Andric          const reverse_iterator<Iterator>& x);   // constexpr in C++17
141*0b57cec5SDimitry Andric
142*0b57cec5SDimitry Andrictemplate <class Iterator>
143*0b57cec5SDimitry Andricconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
144*0b57cec5SDimitry Andric
145*0b57cec5SDimitry Andrictemplate <class Container>
146*0b57cec5SDimitry Andricclass back_insert_iterator
147*0b57cec5SDimitry Andric{
148*0b57cec5SDimitry Andricprotected:
149*0b57cec5SDimitry Andric    Container* container;
150*0b57cec5SDimitry Andricpublic:
151*0b57cec5SDimitry Andric    typedef Container                   container_type;
152*0b57cec5SDimitry Andric    typedef void                        value_type;
153*0b57cec5SDimitry Andric    typedef void                        difference_type;
154*0b57cec5SDimitry Andric    typedef void                        reference;
155*0b57cec5SDimitry Andric    typedef void                        pointer;
156*0b57cec5SDimitry Andric
157*0b57cec5SDimitry Andric    explicit back_insert_iterator(Container& x);
158*0b57cec5SDimitry Andric    back_insert_iterator& operator=(const typename Container::value_type& value);
159*0b57cec5SDimitry Andric    back_insert_iterator& operator*();
160*0b57cec5SDimitry Andric    back_insert_iterator& operator++();
161*0b57cec5SDimitry Andric    back_insert_iterator  operator++(int);
162*0b57cec5SDimitry Andric};
163*0b57cec5SDimitry Andric
164*0b57cec5SDimitry Andrictemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x);
165*0b57cec5SDimitry Andric
166*0b57cec5SDimitry Andrictemplate <class Container>
167*0b57cec5SDimitry Andricclass front_insert_iterator
168*0b57cec5SDimitry Andric{
169*0b57cec5SDimitry Andricprotected:
170*0b57cec5SDimitry Andric    Container* container;
171*0b57cec5SDimitry Andricpublic:
172*0b57cec5SDimitry Andric    typedef Container                    container_type;
173*0b57cec5SDimitry Andric    typedef void                         value_type;
174*0b57cec5SDimitry Andric    typedef void                         difference_type;
175*0b57cec5SDimitry Andric    typedef void                         reference;
176*0b57cec5SDimitry Andric    typedef void                         pointer;
177*0b57cec5SDimitry Andric
178*0b57cec5SDimitry Andric    explicit front_insert_iterator(Container& x);
179*0b57cec5SDimitry Andric    front_insert_iterator& operator=(const typename Container::value_type& value);
180*0b57cec5SDimitry Andric    front_insert_iterator& operator*();
181*0b57cec5SDimitry Andric    front_insert_iterator& operator++();
182*0b57cec5SDimitry Andric    front_insert_iterator  operator++(int);
183*0b57cec5SDimitry Andric};
184*0b57cec5SDimitry Andric
185*0b57cec5SDimitry Andrictemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x);
186*0b57cec5SDimitry Andric
187*0b57cec5SDimitry Andrictemplate <class Container>
188*0b57cec5SDimitry Andricclass insert_iterator
189*0b57cec5SDimitry Andric{
190*0b57cec5SDimitry Andricprotected:
191*0b57cec5SDimitry Andric    Container* container;
192*0b57cec5SDimitry Andric    typename Container::iterator iter;
193*0b57cec5SDimitry Andricpublic:
194*0b57cec5SDimitry Andric    typedef Container              container_type;
195*0b57cec5SDimitry Andric    typedef void                   value_type;
196*0b57cec5SDimitry Andric    typedef void                   difference_type;
197*0b57cec5SDimitry Andric    typedef void                   reference;
198*0b57cec5SDimitry Andric    typedef void                   pointer;
199*0b57cec5SDimitry Andric
200*0b57cec5SDimitry Andric    insert_iterator(Container& x, typename Container::iterator i);
201*0b57cec5SDimitry Andric    insert_iterator& operator=(const typename Container::value_type& value);
202*0b57cec5SDimitry Andric    insert_iterator& operator*();
203*0b57cec5SDimitry Andric    insert_iterator& operator++();
204*0b57cec5SDimitry Andric    insert_iterator& operator++(int);
205*0b57cec5SDimitry Andric};
206*0b57cec5SDimitry Andric
207*0b57cec5SDimitry Andrictemplate <class Container, class Iterator>
208*0b57cec5SDimitry Andricinsert_iterator<Container> inserter(Container& x, Iterator i);
209*0b57cec5SDimitry Andric
210*0b57cec5SDimitry Andrictemplate <class Iterator>
211*0b57cec5SDimitry Andricclass move_iterator {
212*0b57cec5SDimitry Andricpublic:
213*0b57cec5SDimitry Andric    typedef Iterator                                              iterator_type;
214*0b57cec5SDimitry Andric    typedef typename iterator_traits<Iterator>::difference_type   difference_type;
215*0b57cec5SDimitry Andric    typedef Iterator                                              pointer;
216*0b57cec5SDimitry Andric    typedef typename iterator_traits<Iterator>::value_type        value_type;
217*0b57cec5SDimitry Andric    typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
218*0b57cec5SDimitry Andric    typedef value_type&&                                          reference;
219*0b57cec5SDimitry Andric
220*0b57cec5SDimitry Andric    constexpr move_iterator();  // all the constexprs are in C++17
221*0b57cec5SDimitry Andric    constexpr explicit move_iterator(Iterator i);
222*0b57cec5SDimitry Andric    template <class U>
223*0b57cec5SDimitry Andric      constexpr move_iterator(const move_iterator<U>& u);
224*0b57cec5SDimitry Andric    template <class U>
225*0b57cec5SDimitry Andric      constexpr move_iterator& operator=(const move_iterator<U>& u);
226*0b57cec5SDimitry Andric    constexpr iterator_type base() const;
227*0b57cec5SDimitry Andric    constexpr reference operator*() const;
228*0b57cec5SDimitry Andric    constexpr pointer operator->() const;
229*0b57cec5SDimitry Andric    constexpr move_iterator& operator++();
230*0b57cec5SDimitry Andric    constexpr move_iterator operator++(int);
231*0b57cec5SDimitry Andric    constexpr move_iterator& operator--();
232*0b57cec5SDimitry Andric    constexpr move_iterator operator--(int);
233*0b57cec5SDimitry Andric    constexpr move_iterator operator+(difference_type n) const;
234*0b57cec5SDimitry Andric    constexpr move_iterator& operator+=(difference_type n);
235*0b57cec5SDimitry Andric    constexpr move_iterator operator-(difference_type n) const;
236*0b57cec5SDimitry Andric    constexpr move_iterator& operator-=(difference_type n);
237*0b57cec5SDimitry Andric    constexpr unspecified operator[](difference_type n) const;
238*0b57cec5SDimitry Andricprivate:
239*0b57cec5SDimitry Andric    Iterator current; // exposition only
240*0b57cec5SDimitry Andric};
241*0b57cec5SDimitry Andric
242*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
243*0b57cec5SDimitry Andricconstexpr bool   // constexpr in C++17
244*0b57cec5SDimitry Andricoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
245*0b57cec5SDimitry Andric
246*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
247*0b57cec5SDimitry Andricconstexpr bool   // constexpr in C++17
248*0b57cec5SDimitry Andricoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
249*0b57cec5SDimitry Andric
250*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
251*0b57cec5SDimitry Andricconstexpr bool   // constexpr in C++17
252*0b57cec5SDimitry Andricoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
253*0b57cec5SDimitry Andric
254*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
255*0b57cec5SDimitry Andricconstexpr bool   // constexpr in C++17
256*0b57cec5SDimitry Andricoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
257*0b57cec5SDimitry Andric
258*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
259*0b57cec5SDimitry Andricconstexpr bool   // constexpr in C++17
260*0b57cec5SDimitry Andricoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
261*0b57cec5SDimitry Andric
262*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
263*0b57cec5SDimitry Andricconstexpr bool   // constexpr in C++17
264*0b57cec5SDimitry Andricoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
265*0b57cec5SDimitry Andric
266*0b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2>
267*0b57cec5SDimitry Andricconstexpr auto   // constexpr in C++17
268*0b57cec5SDimitry Andricoperator-(const move_iterator<Iterator1>& x,
269*0b57cec5SDimitry Andric          const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
270*0b57cec5SDimitry Andric
271*0b57cec5SDimitry Andrictemplate <class Iterator>
272*0b57cec5SDimitry Andricconstexpr move_iterator<Iterator> operator+(   // constexpr in C++17
273*0b57cec5SDimitry Andric            typename move_iterator<Iterator>::difference_type n,
274*0b57cec5SDimitry Andric            const move_iterator<Iterator>& x);
275*0b57cec5SDimitry Andric
276*0b57cec5SDimitry Andrictemplate <class Iterator>   // constexpr in C++17
277*0b57cec5SDimitry Andricconstexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
278*0b57cec5SDimitry Andric
279*0b57cec5SDimitry Andric
280*0b57cec5SDimitry Andrictemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
281*0b57cec5SDimitry Andricclass istream_iterator
282*0b57cec5SDimitry Andric    : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
283*0b57cec5SDimitry Andric{
284*0b57cec5SDimitry Andricpublic:
285*0b57cec5SDimitry Andric    typedef charT char_type;
286*0b57cec5SDimitry Andric    typedef traits traits_type;
287*0b57cec5SDimitry Andric    typedef basic_istream<charT,traits> istream_type;
288*0b57cec5SDimitry Andric
289*0b57cec5SDimitry Andric    constexpr istream_iterator();
290*0b57cec5SDimitry Andric    istream_iterator(istream_type& s);
291*0b57cec5SDimitry Andric    istream_iterator(const istream_iterator& x);
292*0b57cec5SDimitry Andric    ~istream_iterator();
293*0b57cec5SDimitry Andric
294*0b57cec5SDimitry Andric    const T& operator*() const;
295*0b57cec5SDimitry Andric    const T* operator->() const;
296*0b57cec5SDimitry Andric    istream_iterator& operator++();
297*0b57cec5SDimitry Andric    istream_iterator  operator++(int);
298*0b57cec5SDimitry Andric};
299*0b57cec5SDimitry Andric
300*0b57cec5SDimitry Andrictemplate <class T, class charT, class traits, class Distance>
301*0b57cec5SDimitry Andricbool operator==(const istream_iterator<T,charT,traits,Distance>& x,
302*0b57cec5SDimitry Andric                const istream_iterator<T,charT,traits,Distance>& y);
303*0b57cec5SDimitry Andrictemplate <class T, class charT, class traits, class Distance>
304*0b57cec5SDimitry Andricbool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
305*0b57cec5SDimitry Andric                const istream_iterator<T,charT,traits,Distance>& y);
306*0b57cec5SDimitry Andric
307*0b57cec5SDimitry Andrictemplate <class T, class charT = char, class traits = char_traits<charT> >
308*0b57cec5SDimitry Andricclass ostream_iterator
309*0b57cec5SDimitry Andric    : public iterator<output_iterator_tag, void, void, void ,void>
310*0b57cec5SDimitry Andric{
311*0b57cec5SDimitry Andricpublic:
312*0b57cec5SDimitry Andric    typedef charT char_type;
313*0b57cec5SDimitry Andric    typedef traits traits_type;
314*0b57cec5SDimitry Andric    typedef basic_ostream<charT,traits> ostream_type;
315*0b57cec5SDimitry Andric
316*0b57cec5SDimitry Andric    ostream_iterator(ostream_type& s);
317*0b57cec5SDimitry Andric    ostream_iterator(ostream_type& s, const charT* delimiter);
318*0b57cec5SDimitry Andric    ostream_iterator(const ostream_iterator& x);
319*0b57cec5SDimitry Andric    ~ostream_iterator();
320*0b57cec5SDimitry Andric    ostream_iterator& operator=(const T& value);
321*0b57cec5SDimitry Andric
322*0b57cec5SDimitry Andric    ostream_iterator& operator*();
323*0b57cec5SDimitry Andric    ostream_iterator& operator++();
324*0b57cec5SDimitry Andric    ostream_iterator& operator++(int);
325*0b57cec5SDimitry Andric};
326*0b57cec5SDimitry Andric
327*0b57cec5SDimitry Andrictemplate<class charT, class traits = char_traits<charT> >
328*0b57cec5SDimitry Andricclass istreambuf_iterator
329*0b57cec5SDimitry Andric    : public iterator<input_iterator_tag, charT,
330*0b57cec5SDimitry Andric                      typename traits::off_type, unspecified,
331*0b57cec5SDimitry Andric                      charT>
332*0b57cec5SDimitry Andric{
333*0b57cec5SDimitry Andricpublic:
334*0b57cec5SDimitry Andric    typedef charT                         char_type;
335*0b57cec5SDimitry Andric    typedef traits                        traits_type;
336*0b57cec5SDimitry Andric    typedef typename traits::int_type     int_type;
337*0b57cec5SDimitry Andric    typedef basic_streambuf<charT,traits> streambuf_type;
338*0b57cec5SDimitry Andric    typedef basic_istream<charT,traits>   istream_type;
339*0b57cec5SDimitry Andric
340*0b57cec5SDimitry Andric    istreambuf_iterator() noexcept;
341*0b57cec5SDimitry Andric    istreambuf_iterator(istream_type& s) noexcept;
342*0b57cec5SDimitry Andric    istreambuf_iterator(streambuf_type* s) noexcept;
343*0b57cec5SDimitry Andric    istreambuf_iterator(a-private-type) noexcept;
344*0b57cec5SDimitry Andric
345*0b57cec5SDimitry Andric    charT                operator*() const;
346*0b57cec5SDimitry Andric    pointer operator->() const;
347*0b57cec5SDimitry Andric    istreambuf_iterator& operator++();
348*0b57cec5SDimitry Andric    a-private-type       operator++(int);
349*0b57cec5SDimitry Andric
350*0b57cec5SDimitry Andric    bool equal(const istreambuf_iterator& b) const;
351*0b57cec5SDimitry Andric};
352*0b57cec5SDimitry Andric
353*0b57cec5SDimitry Andrictemplate <class charT, class traits>
354*0b57cec5SDimitry Andricbool operator==(const istreambuf_iterator<charT,traits>& a,
355*0b57cec5SDimitry Andric                const istreambuf_iterator<charT,traits>& b);
356*0b57cec5SDimitry Andrictemplate <class charT, class traits>
357*0b57cec5SDimitry Andricbool operator!=(const istreambuf_iterator<charT,traits>& a,
358*0b57cec5SDimitry Andric                const istreambuf_iterator<charT,traits>& b);
359*0b57cec5SDimitry Andric
360*0b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT> >
361*0b57cec5SDimitry Andricclass ostreambuf_iterator
362*0b57cec5SDimitry Andric    : public iterator<output_iterator_tag, void, void, void, void>
363*0b57cec5SDimitry Andric{
364*0b57cec5SDimitry Andricpublic:
365*0b57cec5SDimitry Andric    typedef charT                         char_type;
366*0b57cec5SDimitry Andric    typedef traits                        traits_type;
367*0b57cec5SDimitry Andric    typedef basic_streambuf<charT,traits> streambuf_type;
368*0b57cec5SDimitry Andric    typedef basic_ostream<charT,traits>   ostream_type;
369*0b57cec5SDimitry Andric
370*0b57cec5SDimitry Andric    ostreambuf_iterator(ostream_type& s) noexcept;
371*0b57cec5SDimitry Andric    ostreambuf_iterator(streambuf_type* s) noexcept;
372*0b57cec5SDimitry Andric    ostreambuf_iterator& operator=(charT c);
373*0b57cec5SDimitry Andric    ostreambuf_iterator& operator*();
374*0b57cec5SDimitry Andric    ostreambuf_iterator& operator++();
375*0b57cec5SDimitry Andric    ostreambuf_iterator& operator++(int);
376*0b57cec5SDimitry Andric    bool failed() const noexcept;
377*0b57cec5SDimitry Andric};
378*0b57cec5SDimitry Andric
379*0b57cec5SDimitry Andrictemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin());
380*0b57cec5SDimitry Andrictemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
381*0b57cec5SDimitry Andrictemplate <class C> constexpr auto end(C& c) -> decltype(c.end());
382*0b57cec5SDimitry Andrictemplate <class C> constexpr auto end(const C& c) -> decltype(c.end());
383*0b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr T* begin(T (&array)[N]);
384*0b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr T* end(T (&array)[N]);
385*0b57cec5SDimitry Andric
386*0b57cec5SDimitry Andrictemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c));        // C++14
387*0b57cec5SDimitry Andrictemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c));            // C++14
388*0b57cec5SDimitry Andrictemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin());                 // C++14
389*0b57cec5SDimitry Andrictemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin());           // C++14
390*0b57cec5SDimitry Andrictemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend());                     // C++14
391*0b57cec5SDimitry Andrictemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend());               // C++14
392*0b57cec5SDimitry Andrictemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
393*0b57cec5SDimitry Andrictemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il);   // C++14
394*0b57cec5SDimitry Andrictemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]);      // C++14
395*0b57cec5SDimitry Andrictemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]);        // C++14
396*0b57cec5SDimitry Andrictemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));      // C++14
397*0b57cec5SDimitry Andrictemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));          // C++14
398*0b57cec5SDimitry Andric
399*0b57cec5SDimitry Andric// 24.8, container access:
400*0b57cec5SDimitry Andrictemplate <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
401*0b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
402*0b57cec5SDimitry Andric
403*0b57cec5SDimitry Andrictemplate <class C> constexpr auto ssize(const C& c)
404*0b57cec5SDimitry Andric    -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;				       // C++20
405*0b57cec5SDimitry Andrictemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
406*0b57cec5SDimitry Andric
407*0b57cec5SDimitry Andrictemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
408*0b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
409*0b57cec5SDimitry Andrictemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
410*0b57cec5SDimitry Andrictemplate <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
411*0b57cec5SDimitry Andrictemplate <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
412*0b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
413*0b57cec5SDimitry Andrictemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
414*0b57cec5SDimitry Andric
415*0b57cec5SDimitry Andric}  // std
416*0b57cec5SDimitry Andric
417*0b57cec5SDimitry Andric*/
418*0b57cec5SDimitry Andric
419*0b57cec5SDimitry Andric#include <__config>
420*0b57cec5SDimitry Andric#include <iosfwd> // for forward declarations of vector and string.
421*0b57cec5SDimitry Andric#include <__functional_base>
422*0b57cec5SDimitry Andric#include <type_traits>
423*0b57cec5SDimitry Andric#include <cstddef>
424*0b57cec5SDimitry Andric#include <initializer_list>
425*0b57cec5SDimitry Andric#include <version>
426*0b57cec5SDimitry Andric#ifdef __APPLE__
427*0b57cec5SDimitry Andric#include <Availability.h>
428*0b57cec5SDimitry Andric#endif
429*0b57cec5SDimitry Andric
430*0b57cec5SDimitry Andric#include <__debug>
431*0b57cec5SDimitry Andric
432*0b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
433*0b57cec5SDimitry Andric#pragma GCC system_header
434*0b57cec5SDimitry Andric#endif
435*0b57cec5SDimitry Andric
436*0b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
437*0b57cec5SDimitry Andric
438*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
439*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
440*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS forward_iterator_tag       : public input_iterator_tag {};
441*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
442*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
443*0b57cec5SDimitry Andric
444*0b57cec5SDimitry Andrictemplate <class _Tp>
445*0b57cec5SDimitry Andricstruct __has_iterator_typedefs
446*0b57cec5SDimitry Andric{
447*0b57cec5SDimitry Andricprivate:
448*0b57cec5SDimitry Andric    struct __two {char __lx; char __lxx;};
449*0b57cec5SDimitry Andric    template <class _Up> static __two __test(...);
450*0b57cec5SDimitry Andric    template <class _Up> static char __test(typename std::__void_t<typename _Up::iterator_category>::type* = 0,
451*0b57cec5SDimitry Andric    										typename std::__void_t<typename _Up::difference_type>::type* = 0,
452*0b57cec5SDimitry Andric    										typename std::__void_t<typename _Up::value_type>::type* = 0,
453*0b57cec5SDimitry Andric    										typename std::__void_t<typename _Up::reference>::type* = 0,
454*0b57cec5SDimitry Andric    										typename std::__void_t<typename _Up::pointer>::type* = 0
455*0b57cec5SDimitry Andric    										);
456*0b57cec5SDimitry Andricpublic:
457*0b57cec5SDimitry Andric    static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1;
458*0b57cec5SDimitry Andric};
459*0b57cec5SDimitry Andric
460*0b57cec5SDimitry Andric
461*0b57cec5SDimitry Andrictemplate <class _Tp>
462*0b57cec5SDimitry Andricstruct __has_iterator_category
463*0b57cec5SDimitry Andric{
464*0b57cec5SDimitry Andricprivate:
465*0b57cec5SDimitry Andric    struct __two {char __lx; char __lxx;};
466*0b57cec5SDimitry Andric    template <class _Up> static __two __test(...);
467*0b57cec5SDimitry Andric    template <class _Up> static char __test(typename _Up::iterator_category* = 0);
468*0b57cec5SDimitry Andricpublic:
469*0b57cec5SDimitry Andric    static const bool value = sizeof(__test<_Tp>(0)) == 1;
470*0b57cec5SDimitry Andric};
471*0b57cec5SDimitry Andric
472*0b57cec5SDimitry Andrictemplate <class _Iter, bool> struct __iterator_traits_impl {};
473*0b57cec5SDimitry Andric
474*0b57cec5SDimitry Andrictemplate <class _Iter>
475*0b57cec5SDimitry Andricstruct __iterator_traits_impl<_Iter, true>
476*0b57cec5SDimitry Andric{
477*0b57cec5SDimitry Andric    typedef typename _Iter::difference_type   difference_type;
478*0b57cec5SDimitry Andric    typedef typename _Iter::value_type        value_type;
479*0b57cec5SDimitry Andric    typedef typename _Iter::pointer           pointer;
480*0b57cec5SDimitry Andric    typedef typename _Iter::reference         reference;
481*0b57cec5SDimitry Andric    typedef typename _Iter::iterator_category iterator_category;
482*0b57cec5SDimitry Andric};
483*0b57cec5SDimitry Andric
484*0b57cec5SDimitry Andrictemplate <class _Iter, bool> struct __iterator_traits {};
485*0b57cec5SDimitry Andric
486*0b57cec5SDimitry Andrictemplate <class _Iter>
487*0b57cec5SDimitry Andricstruct __iterator_traits<_Iter, true>
488*0b57cec5SDimitry Andric    :  __iterator_traits_impl
489*0b57cec5SDimitry Andric      <
490*0b57cec5SDimitry Andric        _Iter,
491*0b57cec5SDimitry Andric        is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
492*0b57cec5SDimitry Andric        is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
493*0b57cec5SDimitry Andric      >
494*0b57cec5SDimitry Andric{};
495*0b57cec5SDimitry Andric
496*0b57cec5SDimitry Andric// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
497*0b57cec5SDimitry Andric//    exists.  Else iterator_traits<Iterator> will be an empty class.  This is a
498*0b57cec5SDimitry Andric//    conforming extension which allows some programs to compile and behave as
499*0b57cec5SDimitry Andric//    the client expects instead of failing at compile time.
500*0b57cec5SDimitry Andric
501*0b57cec5SDimitry Andrictemplate <class _Iter>
502*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS iterator_traits
503*0b57cec5SDimitry Andric    : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {};
504*0b57cec5SDimitry Andric
505*0b57cec5SDimitry Andrictemplate<class _Tp>
506*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
507*0b57cec5SDimitry Andric{
508*0b57cec5SDimitry Andric    typedef ptrdiff_t difference_type;
509*0b57cec5SDimitry Andric    typedef typename remove_cv<_Tp>::type value_type;
510*0b57cec5SDimitry Andric    typedef _Tp* pointer;
511*0b57cec5SDimitry Andric    typedef _Tp& reference;
512*0b57cec5SDimitry Andric    typedef random_access_iterator_tag iterator_category;
513*0b57cec5SDimitry Andric};
514*0b57cec5SDimitry Andric
515*0b57cec5SDimitry Andrictemplate <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
516*0b57cec5SDimitry Andricstruct __has_iterator_category_convertible_to
517*0b57cec5SDimitry Andric    : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
518*0b57cec5SDimitry Andric{};
519*0b57cec5SDimitry Andric
520*0b57cec5SDimitry Andrictemplate <class _Tp, class _Up>
521*0b57cec5SDimitry Andricstruct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
522*0b57cec5SDimitry Andric
523*0b57cec5SDimitry Andrictemplate <class _Tp>
524*0b57cec5SDimitry Andricstruct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
525*0b57cec5SDimitry Andric
526*0b57cec5SDimitry Andrictemplate <class _Tp>
527*0b57cec5SDimitry Andricstruct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
528*0b57cec5SDimitry Andric
529*0b57cec5SDimitry Andrictemplate <class _Tp>
530*0b57cec5SDimitry Andricstruct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
531*0b57cec5SDimitry Andric
532*0b57cec5SDimitry Andrictemplate <class _Tp>
533*0b57cec5SDimitry Andricstruct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
534*0b57cec5SDimitry Andric
535*0b57cec5SDimitry Andrictemplate <class _Tp>
536*0b57cec5SDimitry Andricstruct __is_exactly_input_iterator
537*0b57cec5SDimitry Andric    : public integral_constant<bool,
538*0b57cec5SDimitry Andric         __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
539*0b57cec5SDimitry Andric        !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
540*0b57cec5SDimitry Andric
541*0b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
542*0b57cec5SDimitry Andrictemplate<class _InputIterator>
543*0b57cec5SDimitry Andricusing __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
544*0b57cec5SDimitry Andric
545*0b57cec5SDimitry Andrictemplate<class _InputIterator>
546*0b57cec5SDimitry Andricusing __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
547*0b57cec5SDimitry Andric
548*0b57cec5SDimitry Andrictemplate<class _InputIterator>
549*0b57cec5SDimitry Andricusing __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
550*0b57cec5SDimitry Andric
551*0b57cec5SDimitry Andrictemplate<class _InputIterator>
552*0b57cec5SDimitry Andricusing __iter_to_alloc_type = pair<
553*0b57cec5SDimitry Andric    add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
554*0b57cec5SDimitry Andric    typename iterator_traits<_InputIterator>::value_type::second_type>;
555*0b57cec5SDimitry Andric#endif
556*0b57cec5SDimitry Andric
557*0b57cec5SDimitry Andrictemplate<class _Category, class _Tp, class _Distance = ptrdiff_t,
558*0b57cec5SDimitry Andric         class _Pointer = _Tp*, class _Reference = _Tp&>
559*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS iterator
560*0b57cec5SDimitry Andric{
561*0b57cec5SDimitry Andric    typedef _Tp        value_type;
562*0b57cec5SDimitry Andric    typedef _Distance  difference_type;
563*0b57cec5SDimitry Andric    typedef _Pointer   pointer;
564*0b57cec5SDimitry Andric    typedef _Reference reference;
565*0b57cec5SDimitry Andric    typedef _Category  iterator_category;
566*0b57cec5SDimitry Andric};
567*0b57cec5SDimitry Andric
568*0b57cec5SDimitry Andrictemplate <class _InputIter>
569*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
570*0b57cec5SDimitry Andricvoid __advance(_InputIter& __i,
571*0b57cec5SDimitry Andric             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
572*0b57cec5SDimitry Andric{
573*0b57cec5SDimitry Andric    for (; __n > 0; --__n)
574*0b57cec5SDimitry Andric        ++__i;
575*0b57cec5SDimitry Andric}
576*0b57cec5SDimitry Andric
577*0b57cec5SDimitry Andrictemplate <class _BiDirIter>
578*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
579*0b57cec5SDimitry Andricvoid __advance(_BiDirIter& __i,
580*0b57cec5SDimitry Andric             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
581*0b57cec5SDimitry Andric{
582*0b57cec5SDimitry Andric    if (__n >= 0)
583*0b57cec5SDimitry Andric        for (; __n > 0; --__n)
584*0b57cec5SDimitry Andric            ++__i;
585*0b57cec5SDimitry Andric    else
586*0b57cec5SDimitry Andric        for (; __n < 0; ++__n)
587*0b57cec5SDimitry Andric            --__i;
588*0b57cec5SDimitry Andric}
589*0b57cec5SDimitry Andric
590*0b57cec5SDimitry Andrictemplate <class _RandIter>
591*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
592*0b57cec5SDimitry Andricvoid __advance(_RandIter& __i,
593*0b57cec5SDimitry Andric             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
594*0b57cec5SDimitry Andric{
595*0b57cec5SDimitry Andric   __i += __n;
596*0b57cec5SDimitry Andric}
597*0b57cec5SDimitry Andric
598*0b57cec5SDimitry Andrictemplate <class _InputIter>
599*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
600*0b57cec5SDimitry Andricvoid advance(_InputIter& __i,
601*0b57cec5SDimitry Andric             typename iterator_traits<_InputIter>::difference_type __n)
602*0b57cec5SDimitry Andric{
603*0b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value,
604*0b57cec5SDimitry Andric                       "Attempt to advance(it, -n) on a non-bidi iterator");
605*0b57cec5SDimitry Andric    __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
606*0b57cec5SDimitry Andric}
607*0b57cec5SDimitry Andric
608*0b57cec5SDimitry Andrictemplate <class _InputIter>
609*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
610*0b57cec5SDimitry Andrictypename iterator_traits<_InputIter>::difference_type
611*0b57cec5SDimitry Andric__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
612*0b57cec5SDimitry Andric{
613*0b57cec5SDimitry Andric    typename iterator_traits<_InputIter>::difference_type __r(0);
614*0b57cec5SDimitry Andric    for (; __first != __last; ++__first)
615*0b57cec5SDimitry Andric        ++__r;
616*0b57cec5SDimitry Andric    return __r;
617*0b57cec5SDimitry Andric}
618*0b57cec5SDimitry Andric
619*0b57cec5SDimitry Andrictemplate <class _RandIter>
620*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
621*0b57cec5SDimitry Andrictypename iterator_traits<_RandIter>::difference_type
622*0b57cec5SDimitry Andric__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
623*0b57cec5SDimitry Andric{
624*0b57cec5SDimitry Andric    return __last - __first;
625*0b57cec5SDimitry Andric}
626*0b57cec5SDimitry Andric
627*0b57cec5SDimitry Andrictemplate <class _InputIter>
628*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
629*0b57cec5SDimitry Andrictypename iterator_traits<_InputIter>::difference_type
630*0b57cec5SDimitry Andricdistance(_InputIter __first, _InputIter __last)
631*0b57cec5SDimitry Andric{
632*0b57cec5SDimitry Andric    return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
633*0b57cec5SDimitry Andric}
634*0b57cec5SDimitry Andric
635*0b57cec5SDimitry Andrictemplate <class _InputIter>
636*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
637*0b57cec5SDimitry Andrictypename enable_if
638*0b57cec5SDimitry Andric<
639*0b57cec5SDimitry Andric    __is_input_iterator<_InputIter>::value,
640*0b57cec5SDimitry Andric    _InputIter
641*0b57cec5SDimitry Andric>::type
642*0b57cec5SDimitry Andricnext(_InputIter __x,
643*0b57cec5SDimitry Andric     typename iterator_traits<_InputIter>::difference_type __n = 1)
644*0b57cec5SDimitry Andric{
645*0b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value,
646*0b57cec5SDimitry Andric                       "Attempt to next(it, -n) on a non-bidi iterator");
647*0b57cec5SDimitry Andric
648*0b57cec5SDimitry Andric    _VSTD::advance(__x, __n);
649*0b57cec5SDimitry Andric    return __x;
650*0b57cec5SDimitry Andric}
651*0b57cec5SDimitry Andric
652*0b57cec5SDimitry Andrictemplate <class _InputIter>
653*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
654*0b57cec5SDimitry Andrictypename enable_if
655*0b57cec5SDimitry Andric<
656*0b57cec5SDimitry Andric    __is_input_iterator<_InputIter>::value,
657*0b57cec5SDimitry Andric    _InputIter
658*0b57cec5SDimitry Andric>::type
659*0b57cec5SDimitry Andricprev(_InputIter __x,
660*0b57cec5SDimitry Andric     typename iterator_traits<_InputIter>::difference_type __n = 1)
661*0b57cec5SDimitry Andric{
662*0b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n <= 0 || __is_bidirectional_iterator<_InputIter>::value,
663*0b57cec5SDimitry Andric                       "Attempt to prev(it, +n) on a non-bidi iterator");
664*0b57cec5SDimitry Andric    _VSTD::advance(__x, -__n);
665*0b57cec5SDimitry Andric    return __x;
666*0b57cec5SDimitry Andric}
667*0b57cec5SDimitry Andric
668*0b57cec5SDimitry Andric
669*0b57cec5SDimitry Andrictemplate <class _Tp, class = void>
670*0b57cec5SDimitry Andricstruct __is_stashing_iterator : false_type {};
671*0b57cec5SDimitry Andric
672*0b57cec5SDimitry Andrictemplate <class _Tp>
673*0b57cec5SDimitry Andricstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
674*0b57cec5SDimitry Andric  : true_type {};
675*0b57cec5SDimitry Andric
676*0b57cec5SDimitry Andrictemplate <class _Iter>
677*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS reverse_iterator
678*0b57cec5SDimitry Andric    : public iterator<typename iterator_traits<_Iter>::iterator_category,
679*0b57cec5SDimitry Andric                      typename iterator_traits<_Iter>::value_type,
680*0b57cec5SDimitry Andric                      typename iterator_traits<_Iter>::difference_type,
681*0b57cec5SDimitry Andric                      typename iterator_traits<_Iter>::pointer,
682*0b57cec5SDimitry Andric                      typename iterator_traits<_Iter>::reference>
683*0b57cec5SDimitry Andric{
684*0b57cec5SDimitry Andricprivate:
685*0b57cec5SDimitry Andric    /*mutable*/ _Iter __t;  // no longer used as of LWG #2360, not removed due to ABI break
686*0b57cec5SDimitry Andric
687*0b57cec5SDimitry Andric    static_assert(!__is_stashing_iterator<_Iter>::value,
688*0b57cec5SDimitry Andric      "The specified iterator type cannot be used with reverse_iterator; "
689*0b57cec5SDimitry Andric      "Using stashing iterators with reverse_iterator causes undefined behavior");
690*0b57cec5SDimitry Andric
691*0b57cec5SDimitry Andricprotected:
692*0b57cec5SDimitry Andric    _Iter current;
693*0b57cec5SDimitry Andricpublic:
694*0b57cec5SDimitry Andric    typedef _Iter                                            iterator_type;
695*0b57cec5SDimitry Andric    typedef typename iterator_traits<_Iter>::difference_type difference_type;
696*0b57cec5SDimitry Andric    typedef typename iterator_traits<_Iter>::reference       reference;
697*0b57cec5SDimitry Andric    typedef typename iterator_traits<_Iter>::pointer         pointer;
698*0b57cec5SDimitry Andric
699*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
700*0b57cec5SDimitry Andric    reverse_iterator() : __t(), current() {}
701*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
702*0b57cec5SDimitry Andric    explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
703*0b57cec5SDimitry Andric    template <class _Up>
704*0b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
705*0b57cec5SDimitry Andric        reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
706*0b57cec5SDimitry Andric    template <class _Up>
707*0b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
708*0b57cec5SDimitry Andric        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
709*0b57cec5SDimitry Andric            { __t = current = __u.base(); return *this; }
710*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
711*0b57cec5SDimitry Andric    _Iter base() const {return current;}
712*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
713*0b57cec5SDimitry Andric    reference operator*() const {_Iter __tmp = current; return *--__tmp;}
714*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
715*0b57cec5SDimitry Andric    pointer  operator->() const {return _VSTD::addressof(operator*());}
716*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
717*0b57cec5SDimitry Andric    reverse_iterator& operator++() {--current; return *this;}
718*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
719*0b57cec5SDimitry Andric    reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
720*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
721*0b57cec5SDimitry Andric    reverse_iterator& operator--() {++current; return *this;}
722*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
723*0b57cec5SDimitry Andric    reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
724*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
725*0b57cec5SDimitry Andric    reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
726*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
727*0b57cec5SDimitry Andric    reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
728*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
729*0b57cec5SDimitry Andric    reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
730*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
731*0b57cec5SDimitry Andric    reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
732*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
733*0b57cec5SDimitry Andric    reference         operator[](difference_type __n) const {return *(*this + __n);}
734*0b57cec5SDimitry Andric};
735*0b57cec5SDimitry Andric
736*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
737*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
738*0b57cec5SDimitry Andricbool
739*0b57cec5SDimitry Andricoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
740*0b57cec5SDimitry Andric{
741*0b57cec5SDimitry Andric    return __x.base() == __y.base();
742*0b57cec5SDimitry Andric}
743*0b57cec5SDimitry Andric
744*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
745*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
746*0b57cec5SDimitry Andricbool
747*0b57cec5SDimitry Andricoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
748*0b57cec5SDimitry Andric{
749*0b57cec5SDimitry Andric    return __x.base() > __y.base();
750*0b57cec5SDimitry Andric}
751*0b57cec5SDimitry Andric
752*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
753*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
754*0b57cec5SDimitry Andricbool
755*0b57cec5SDimitry Andricoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
756*0b57cec5SDimitry Andric{
757*0b57cec5SDimitry Andric    return __x.base() != __y.base();
758*0b57cec5SDimitry Andric}
759*0b57cec5SDimitry Andric
760*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
761*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
762*0b57cec5SDimitry Andricbool
763*0b57cec5SDimitry Andricoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
764*0b57cec5SDimitry Andric{
765*0b57cec5SDimitry Andric    return __x.base() < __y.base();
766*0b57cec5SDimitry Andric}
767*0b57cec5SDimitry Andric
768*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
769*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
770*0b57cec5SDimitry Andricbool
771*0b57cec5SDimitry Andricoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
772*0b57cec5SDimitry Andric{
773*0b57cec5SDimitry Andric    return __x.base() <= __y.base();
774*0b57cec5SDimitry Andric}
775*0b57cec5SDimitry Andric
776*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
777*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
778*0b57cec5SDimitry Andricbool
779*0b57cec5SDimitry Andricoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
780*0b57cec5SDimitry Andric{
781*0b57cec5SDimitry Andric    return __x.base() >= __y.base();
782*0b57cec5SDimitry Andric}
783*0b57cec5SDimitry Andric
784*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
785*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
786*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
787*0b57cec5SDimitry Andricauto
788*0b57cec5SDimitry Andricoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
789*0b57cec5SDimitry Andric-> decltype(__y.base() - __x.base())
790*0b57cec5SDimitry Andric{
791*0b57cec5SDimitry Andric    return __y.base() - __x.base();
792*0b57cec5SDimitry Andric}
793*0b57cec5SDimitry Andric#else
794*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
795*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
796*0b57cec5SDimitry Andrictypename reverse_iterator<_Iter1>::difference_type
797*0b57cec5SDimitry Andricoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
798*0b57cec5SDimitry Andric{
799*0b57cec5SDimitry Andric    return __y.base() - __x.base();
800*0b57cec5SDimitry Andric}
801*0b57cec5SDimitry Andric#endif
802*0b57cec5SDimitry Andric
803*0b57cec5SDimitry Andrictemplate <class _Iter>
804*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
805*0b57cec5SDimitry Andricreverse_iterator<_Iter>
806*0b57cec5SDimitry Andricoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
807*0b57cec5SDimitry Andric{
808*0b57cec5SDimitry Andric    return reverse_iterator<_Iter>(__x.base() - __n);
809*0b57cec5SDimitry Andric}
810*0b57cec5SDimitry Andric
811*0b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
812*0b57cec5SDimitry Andrictemplate <class _Iter>
813*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
814*0b57cec5SDimitry Andricreverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
815*0b57cec5SDimitry Andric{
816*0b57cec5SDimitry Andric    return reverse_iterator<_Iter>(__i);
817*0b57cec5SDimitry Andric}
818*0b57cec5SDimitry Andric#endif
819*0b57cec5SDimitry Andric
820*0b57cec5SDimitry Andrictemplate <class _Container>
821*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS back_insert_iterator
822*0b57cec5SDimitry Andric    : public iterator<output_iterator_tag,
823*0b57cec5SDimitry Andric                      void,
824*0b57cec5SDimitry Andric                      void,
825*0b57cec5SDimitry Andric                      void,
826*0b57cec5SDimitry Andric                      void>
827*0b57cec5SDimitry Andric{
828*0b57cec5SDimitry Andricprotected:
829*0b57cec5SDimitry Andric    _Container* container;
830*0b57cec5SDimitry Andricpublic:
831*0b57cec5SDimitry Andric    typedef _Container container_type;
832*0b57cec5SDimitry Andric
833*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
834*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
835*0b57cec5SDimitry Andric        {container->push_back(__value_); return *this;}
836*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
837*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
838*0b57cec5SDimitry Andric        {container->push_back(_VSTD::move(__value_)); return *this;}
839*0b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
840*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*()     {return *this;}
841*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++()    {return *this;}
842*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY back_insert_iterator  operator++(int) {return *this;}
843*0b57cec5SDimitry Andric};
844*0b57cec5SDimitry Andric
845*0b57cec5SDimitry Andrictemplate <class _Container>
846*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
847*0b57cec5SDimitry Andricback_insert_iterator<_Container>
848*0b57cec5SDimitry Andricback_inserter(_Container& __x)
849*0b57cec5SDimitry Andric{
850*0b57cec5SDimitry Andric    return back_insert_iterator<_Container>(__x);
851*0b57cec5SDimitry Andric}
852*0b57cec5SDimitry Andric
853*0b57cec5SDimitry Andrictemplate <class _Container>
854*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS front_insert_iterator
855*0b57cec5SDimitry Andric    : public iterator<output_iterator_tag,
856*0b57cec5SDimitry Andric                      void,
857*0b57cec5SDimitry Andric                      void,
858*0b57cec5SDimitry Andric                      void,
859*0b57cec5SDimitry Andric                      void>
860*0b57cec5SDimitry Andric{
861*0b57cec5SDimitry Andricprotected:
862*0b57cec5SDimitry Andric    _Container* container;
863*0b57cec5SDimitry Andricpublic:
864*0b57cec5SDimitry Andric    typedef _Container container_type;
865*0b57cec5SDimitry Andric
866*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
867*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
868*0b57cec5SDimitry Andric        {container->push_front(__value_); return *this;}
869*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
870*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
871*0b57cec5SDimitry Andric        {container->push_front(_VSTD::move(__value_)); return *this;}
872*0b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
873*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*()     {return *this;}
874*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++()    {return *this;}
875*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY front_insert_iterator  operator++(int) {return *this;}
876*0b57cec5SDimitry Andric};
877*0b57cec5SDimitry Andric
878*0b57cec5SDimitry Andrictemplate <class _Container>
879*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
880*0b57cec5SDimitry Andricfront_insert_iterator<_Container>
881*0b57cec5SDimitry Andricfront_inserter(_Container& __x)
882*0b57cec5SDimitry Andric{
883*0b57cec5SDimitry Andric    return front_insert_iterator<_Container>(__x);
884*0b57cec5SDimitry Andric}
885*0b57cec5SDimitry Andric
886*0b57cec5SDimitry Andrictemplate <class _Container>
887*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS insert_iterator
888*0b57cec5SDimitry Andric    : public iterator<output_iterator_tag,
889*0b57cec5SDimitry Andric                      void,
890*0b57cec5SDimitry Andric                      void,
891*0b57cec5SDimitry Andric                      void,
892*0b57cec5SDimitry Andric                      void>
893*0b57cec5SDimitry Andric{
894*0b57cec5SDimitry Andricprotected:
895*0b57cec5SDimitry Andric    _Container* container;
896*0b57cec5SDimitry Andric    typename _Container::iterator iter;
897*0b57cec5SDimitry Andricpublic:
898*0b57cec5SDimitry Andric    typedef _Container container_type;
899*0b57cec5SDimitry Andric
900*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
901*0b57cec5SDimitry Andric        : container(_VSTD::addressof(__x)), iter(__i) {}
902*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
903*0b57cec5SDimitry Andric        {iter = container->insert(iter, __value_); ++iter; return *this;}
904*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
905*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
906*0b57cec5SDimitry Andric        {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
907*0b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
908*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*()        {return *this;}
909*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++()       {return *this;}
910*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int)    {return *this;}
911*0b57cec5SDimitry Andric};
912*0b57cec5SDimitry Andric
913*0b57cec5SDimitry Andrictemplate <class _Container>
914*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
915*0b57cec5SDimitry Andricinsert_iterator<_Container>
916*0b57cec5SDimitry Andricinserter(_Container& __x, typename _Container::iterator __i)
917*0b57cec5SDimitry Andric{
918*0b57cec5SDimitry Andric    return insert_iterator<_Container>(__x, __i);
919*0b57cec5SDimitry Andric}
920*0b57cec5SDimitry Andric
921*0b57cec5SDimitry Andrictemplate <class _Tp, class _CharT = char,
922*0b57cec5SDimitry Andric          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
923*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS istream_iterator
924*0b57cec5SDimitry Andric    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
925*0b57cec5SDimitry Andric{
926*0b57cec5SDimitry Andricpublic:
927*0b57cec5SDimitry Andric    typedef _CharT char_type;
928*0b57cec5SDimitry Andric    typedef _Traits traits_type;
929*0b57cec5SDimitry Andric    typedef basic_istream<_CharT,_Traits> istream_type;
930*0b57cec5SDimitry Andricprivate:
931*0b57cec5SDimitry Andric    istream_type* __in_stream_;
932*0b57cec5SDimitry Andric    _Tp __value_;
933*0b57cec5SDimitry Andricpublic:
934*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
935*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
936*0b57cec5SDimitry Andric        {
937*0b57cec5SDimitry Andric            if (!(*__in_stream_ >> __value_))
938*0b57cec5SDimitry Andric                __in_stream_ = 0;
939*0b57cec5SDimitry Andric        }
940*0b57cec5SDimitry Andric
941*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
942*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
943*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
944*0b57cec5SDimitry Andric        {
945*0b57cec5SDimitry Andric            if (!(*__in_stream_ >> __value_))
946*0b57cec5SDimitry Andric                __in_stream_ = 0;
947*0b57cec5SDimitry Andric            return *this;
948*0b57cec5SDimitry Andric        }
949*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
950*0b57cec5SDimitry Andric        {istream_iterator __t(*this); ++(*this); return __t;}
951*0b57cec5SDimitry Andric
952*0b57cec5SDimitry Andric    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
953*0b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY
954*0b57cec5SDimitry Andric    bool
955*0b57cec5SDimitry Andric    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
956*0b57cec5SDimitry Andric               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
957*0b57cec5SDimitry Andric
958*0b57cec5SDimitry Andric    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
959*0b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY
960*0b57cec5SDimitry Andric    bool
961*0b57cec5SDimitry Andric    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
962*0b57cec5SDimitry Andric               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
963*0b57cec5SDimitry Andric};
964*0b57cec5SDimitry Andric
965*0b57cec5SDimitry Andrictemplate <class _Tp, class _CharT, class _Traits, class _Distance>
966*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
967*0b57cec5SDimitry Andricbool
968*0b57cec5SDimitry Andricoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
969*0b57cec5SDimitry Andric           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
970*0b57cec5SDimitry Andric{
971*0b57cec5SDimitry Andric    return __x.__in_stream_ == __y.__in_stream_;
972*0b57cec5SDimitry Andric}
973*0b57cec5SDimitry Andric
974*0b57cec5SDimitry Andrictemplate <class _Tp, class _CharT, class _Traits, class _Distance>
975*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
976*0b57cec5SDimitry Andricbool
977*0b57cec5SDimitry Andricoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
978*0b57cec5SDimitry Andric           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
979*0b57cec5SDimitry Andric{
980*0b57cec5SDimitry Andric    return !(__x == __y);
981*0b57cec5SDimitry Andric}
982*0b57cec5SDimitry Andric
983*0b57cec5SDimitry Andrictemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
984*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS ostream_iterator
985*0b57cec5SDimitry Andric    : public iterator<output_iterator_tag, void, void, void, void>
986*0b57cec5SDimitry Andric{
987*0b57cec5SDimitry Andricpublic:
988*0b57cec5SDimitry Andric    typedef _CharT char_type;
989*0b57cec5SDimitry Andric    typedef _Traits traits_type;
990*0b57cec5SDimitry Andric    typedef basic_ostream<_CharT,_Traits> ostream_type;
991*0b57cec5SDimitry Andricprivate:
992*0b57cec5SDimitry Andric    ostream_type* __out_stream_;
993*0b57cec5SDimitry Andric    const char_type* __delim_;
994*0b57cec5SDimitry Andricpublic:
995*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
996*0b57cec5SDimitry Andric        : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
997*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
998*0b57cec5SDimitry Andric        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
999*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
1000*0b57cec5SDimitry Andric        {
1001*0b57cec5SDimitry Andric            *__out_stream_ << __value_;
1002*0b57cec5SDimitry Andric            if (__delim_)
1003*0b57cec5SDimitry Andric                *__out_stream_ << __delim_;
1004*0b57cec5SDimitry Andric            return *this;
1005*0b57cec5SDimitry Andric        }
1006*0b57cec5SDimitry Andric
1007*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
1008*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
1009*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
1010*0b57cec5SDimitry Andric};
1011*0b57cec5SDimitry Andric
1012*0b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
1013*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator
1014*0b57cec5SDimitry Andric    : public iterator<input_iterator_tag, _CharT,
1015*0b57cec5SDimitry Andric                      typename _Traits::off_type, _CharT*,
1016*0b57cec5SDimitry Andric                      _CharT>
1017*0b57cec5SDimitry Andric{
1018*0b57cec5SDimitry Andricpublic:
1019*0b57cec5SDimitry Andric    typedef _CharT                          char_type;
1020*0b57cec5SDimitry Andric    typedef _Traits                         traits_type;
1021*0b57cec5SDimitry Andric    typedef typename _Traits::int_type      int_type;
1022*0b57cec5SDimitry Andric    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1023*0b57cec5SDimitry Andric    typedef basic_istream<_CharT,_Traits>   istream_type;
1024*0b57cec5SDimitry Andricprivate:
1025*0b57cec5SDimitry Andric    mutable streambuf_type* __sbuf_;
1026*0b57cec5SDimitry Andric
1027*0b57cec5SDimitry Andric    class __proxy
1028*0b57cec5SDimitry Andric    {
1029*0b57cec5SDimitry Andric        char_type __keep_;
1030*0b57cec5SDimitry Andric        streambuf_type* __sbuf_;
1031*0b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
1032*0b57cec5SDimitry Andric            : __keep_(__c), __sbuf_(__s) {}
1033*0b57cec5SDimitry Andric        friend class istreambuf_iterator;
1034*0b57cec5SDimitry Andric    public:
1035*0b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
1036*0b57cec5SDimitry Andric    };
1037*0b57cec5SDimitry Andric
1038*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1039*0b57cec5SDimitry Andric    bool __test_for_eof() const
1040*0b57cec5SDimitry Andric    {
1041*0b57cec5SDimitry Andric        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
1042*0b57cec5SDimitry Andric            __sbuf_ = 0;
1043*0b57cec5SDimitry Andric        return __sbuf_ == 0;
1044*0b57cec5SDimitry Andric    }
1045*0b57cec5SDimitry Andricpublic:
1046*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
1047*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
1048*0b57cec5SDimitry Andric        : __sbuf_(__s.rdbuf()) {}
1049*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1050*0b57cec5SDimitry Andric        : __sbuf_(__s) {}
1051*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
1052*0b57cec5SDimitry Andric        : __sbuf_(__p.__sbuf_) {}
1053*0b57cec5SDimitry Andric
1054*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
1055*0b57cec5SDimitry Andric        {return static_cast<char_type>(__sbuf_->sgetc());}
1056*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1057*0b57cec5SDimitry Andric        {
1058*0b57cec5SDimitry Andric            __sbuf_->sbumpc();
1059*0b57cec5SDimitry Andric            return *this;
1060*0b57cec5SDimitry Andric        }
1061*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
1062*0b57cec5SDimitry Andric        {
1063*0b57cec5SDimitry Andric            return __proxy(__sbuf_->sbumpc(), __sbuf_);
1064*0b57cec5SDimitry Andric        }
1065*0b57cec5SDimitry Andric
1066*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1067*0b57cec5SDimitry Andric        {return __test_for_eof() == __b.__test_for_eof();}
1068*0b57cec5SDimitry Andric};
1069*0b57cec5SDimitry Andric
1070*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1071*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1072*0b57cec5SDimitry Andricbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1073*0b57cec5SDimitry Andric                const istreambuf_iterator<_CharT,_Traits>& __b)
1074*0b57cec5SDimitry Andric                {return __a.equal(__b);}
1075*0b57cec5SDimitry Andric
1076*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1077*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1078*0b57cec5SDimitry Andricbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1079*0b57cec5SDimitry Andric                const istreambuf_iterator<_CharT,_Traits>& __b)
1080*0b57cec5SDimitry Andric                {return !__a.equal(__b);}
1081*0b57cec5SDimitry Andric
1082*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1083*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
1084*0b57cec5SDimitry Andric    : public iterator<output_iterator_tag, void, void, void, void>
1085*0b57cec5SDimitry Andric{
1086*0b57cec5SDimitry Andricpublic:
1087*0b57cec5SDimitry Andric    typedef _CharT                          char_type;
1088*0b57cec5SDimitry Andric    typedef _Traits                         traits_type;
1089*0b57cec5SDimitry Andric    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1090*0b57cec5SDimitry Andric    typedef basic_ostream<_CharT,_Traits>   ostream_type;
1091*0b57cec5SDimitry Andricprivate:
1092*0b57cec5SDimitry Andric    streambuf_type* __sbuf_;
1093*0b57cec5SDimitry Andricpublic:
1094*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
1095*0b57cec5SDimitry Andric        : __sbuf_(__s.rdbuf()) {}
1096*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1097*0b57cec5SDimitry Andric        : __sbuf_(__s) {}
1098*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1099*0b57cec5SDimitry Andric        {
1100*0b57cec5SDimitry Andric            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1101*0b57cec5SDimitry Andric                __sbuf_ = 0;
1102*0b57cec5SDimitry Andric            return *this;
1103*0b57cec5SDimitry Andric        }
1104*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
1105*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
1106*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1107*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
1108*0b57cec5SDimitry Andric
1109*0b57cec5SDimitry Andric    template <class _Ch, class _Tr>
1110*0b57cec5SDimitry Andric    friend
1111*0b57cec5SDimitry Andric    _LIBCPP_HIDDEN
1112*0b57cec5SDimitry Andric    ostreambuf_iterator<_Ch, _Tr>
1113*0b57cec5SDimitry Andric    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1114*0b57cec5SDimitry Andric                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1115*0b57cec5SDimitry Andric                     ios_base& __iob, _Ch __fl);
1116*0b57cec5SDimitry Andric};
1117*0b57cec5SDimitry Andric
1118*0b57cec5SDimitry Andrictemplate <class _Iter>
1119*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS move_iterator
1120*0b57cec5SDimitry Andric{
1121*0b57cec5SDimitry Andricprivate:
1122*0b57cec5SDimitry Andric    _Iter __i;
1123*0b57cec5SDimitry Andricpublic:
1124*0b57cec5SDimitry Andric    typedef _Iter                                            iterator_type;
1125*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1126*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::value_type value_type;
1127*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1128*0b57cec5SDimitry Andric    typedef iterator_type pointer;
1129*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1130*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::reference __reference;
1131*0b57cec5SDimitry Andric    typedef typename conditional<
1132*0b57cec5SDimitry Andric            is_reference<__reference>::value,
1133*0b57cec5SDimitry Andric            typename remove_reference<__reference>::type&&,
1134*0b57cec5SDimitry Andric            __reference
1135*0b57cec5SDimitry Andric        >::type reference;
1136*0b57cec5SDimitry Andric#else
1137*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::reference reference;
1138*0b57cec5SDimitry Andric#endif
1139*0b57cec5SDimitry Andric
1140*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1141*0b57cec5SDimitry Andric    move_iterator() : __i() {}
1142*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1143*0b57cec5SDimitry Andric    explicit move_iterator(_Iter __x) : __i(__x) {}
1144*0b57cec5SDimitry Andric    template <class _Up>
1145*0b57cec5SDimitry Andric      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1146*0b57cec5SDimitry Andric      move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1147*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1148*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1149*0b57cec5SDimitry Andric    reference operator*() const { return static_cast<reference>(*__i); }
1150*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1151*0b57cec5SDimitry Andric    pointer  operator->() const { return __i;}
1152*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1153*0b57cec5SDimitry Andric    move_iterator& operator++() {++__i; return *this;}
1154*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1155*0b57cec5SDimitry Andric    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1156*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1157*0b57cec5SDimitry Andric    move_iterator& operator--() {--__i; return *this;}
1158*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1159*0b57cec5SDimitry Andric    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1160*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1161*0b57cec5SDimitry Andric    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1162*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1163*0b57cec5SDimitry Andric    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1164*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1165*0b57cec5SDimitry Andric    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
1166*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1167*0b57cec5SDimitry Andric    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1168*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1169*0b57cec5SDimitry Andric    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
1170*0b57cec5SDimitry Andric};
1171*0b57cec5SDimitry Andric
1172*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1173*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1174*0b57cec5SDimitry Andricbool
1175*0b57cec5SDimitry Andricoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1176*0b57cec5SDimitry Andric{
1177*0b57cec5SDimitry Andric    return __x.base() == __y.base();
1178*0b57cec5SDimitry Andric}
1179*0b57cec5SDimitry Andric
1180*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1181*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1182*0b57cec5SDimitry Andricbool
1183*0b57cec5SDimitry Andricoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1184*0b57cec5SDimitry Andric{
1185*0b57cec5SDimitry Andric    return __x.base() < __y.base();
1186*0b57cec5SDimitry Andric}
1187*0b57cec5SDimitry Andric
1188*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1189*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1190*0b57cec5SDimitry Andricbool
1191*0b57cec5SDimitry Andricoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1192*0b57cec5SDimitry Andric{
1193*0b57cec5SDimitry Andric    return __x.base() != __y.base();
1194*0b57cec5SDimitry Andric}
1195*0b57cec5SDimitry Andric
1196*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1197*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1198*0b57cec5SDimitry Andricbool
1199*0b57cec5SDimitry Andricoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1200*0b57cec5SDimitry Andric{
1201*0b57cec5SDimitry Andric    return __x.base() > __y.base();
1202*0b57cec5SDimitry Andric}
1203*0b57cec5SDimitry Andric
1204*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1205*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1206*0b57cec5SDimitry Andricbool
1207*0b57cec5SDimitry Andricoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1208*0b57cec5SDimitry Andric{
1209*0b57cec5SDimitry Andric    return __x.base() >= __y.base();
1210*0b57cec5SDimitry Andric}
1211*0b57cec5SDimitry Andric
1212*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1213*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1214*0b57cec5SDimitry Andricbool
1215*0b57cec5SDimitry Andricoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1216*0b57cec5SDimitry Andric{
1217*0b57cec5SDimitry Andric    return __x.base() <= __y.base();
1218*0b57cec5SDimitry Andric}
1219*0b57cec5SDimitry Andric
1220*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1221*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1222*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1223*0b57cec5SDimitry Andricauto
1224*0b57cec5SDimitry Andricoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1225*0b57cec5SDimitry Andric-> decltype(__x.base() - __y.base())
1226*0b57cec5SDimitry Andric{
1227*0b57cec5SDimitry Andric    return __x.base() - __y.base();
1228*0b57cec5SDimitry Andric}
1229*0b57cec5SDimitry Andric#else
1230*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1231*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1232*0b57cec5SDimitry Andrictypename move_iterator<_Iter1>::difference_type
1233*0b57cec5SDimitry Andricoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1234*0b57cec5SDimitry Andric{
1235*0b57cec5SDimitry Andric    return __x.base() - __y.base();
1236*0b57cec5SDimitry Andric}
1237*0b57cec5SDimitry Andric#endif
1238*0b57cec5SDimitry Andric
1239*0b57cec5SDimitry Andrictemplate <class _Iter>
1240*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1241*0b57cec5SDimitry Andricmove_iterator<_Iter>
1242*0b57cec5SDimitry Andricoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1243*0b57cec5SDimitry Andric{
1244*0b57cec5SDimitry Andric    return move_iterator<_Iter>(__x.base() + __n);
1245*0b57cec5SDimitry Andric}
1246*0b57cec5SDimitry Andric
1247*0b57cec5SDimitry Andrictemplate <class _Iter>
1248*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1249*0b57cec5SDimitry Andricmove_iterator<_Iter>
1250*0b57cec5SDimitry Andricmake_move_iterator(_Iter __i)
1251*0b57cec5SDimitry Andric{
1252*0b57cec5SDimitry Andric    return move_iterator<_Iter>(__i);
1253*0b57cec5SDimitry Andric}
1254*0b57cec5SDimitry Andric
1255*0b57cec5SDimitry Andric// __wrap_iter
1256*0b57cec5SDimitry Andric
1257*0b57cec5SDimitry Andrictemplate <class _Iter> class __wrap_iter;
1258*0b57cec5SDimitry Andric
1259*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1260*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1261*0b57cec5SDimitry Andricbool
1262*0b57cec5SDimitry Andricoperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1263*0b57cec5SDimitry Andric
1264*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1265*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1266*0b57cec5SDimitry Andricbool
1267*0b57cec5SDimitry Andricoperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1268*0b57cec5SDimitry Andric
1269*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1270*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1271*0b57cec5SDimitry Andricbool
1272*0b57cec5SDimitry Andricoperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1273*0b57cec5SDimitry Andric
1274*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1275*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1276*0b57cec5SDimitry Andricbool
1277*0b57cec5SDimitry Andricoperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1278*0b57cec5SDimitry Andric
1279*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1280*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1281*0b57cec5SDimitry Andricbool
1282*0b57cec5SDimitry Andricoperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1283*0b57cec5SDimitry Andric
1284*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1285*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1286*0b57cec5SDimitry Andricbool
1287*0b57cec5SDimitry Andricoperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1288*0b57cec5SDimitry Andric
1289*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1290*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1291*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1292*0b57cec5SDimitry Andricauto
1293*0b57cec5SDimitry Andricoperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1294*0b57cec5SDimitry Andric-> decltype(__x.base() - __y.base());
1295*0b57cec5SDimitry Andric#else
1296*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1297*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1298*0b57cec5SDimitry Andrictypename __wrap_iter<_Iter1>::difference_type
1299*0b57cec5SDimitry Andricoperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1300*0b57cec5SDimitry Andric#endif
1301*0b57cec5SDimitry Andric
1302*0b57cec5SDimitry Andrictemplate <class _Iter>
1303*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1304*0b57cec5SDimitry Andric__wrap_iter<_Iter>
1305*0b57cec5SDimitry Andricoperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
1306*0b57cec5SDimitry Andric
1307*0b57cec5SDimitry Andrictemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1308*0b57cec5SDimitry Andrictemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1309*0b57cec5SDimitry Andrictemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1310*0b57cec5SDimitry Andrictemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
1311*0b57cec5SDimitry Andric
1312*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL < 2
1313*0b57cec5SDimitry Andric
1314*0b57cec5SDimitry Andrictemplate <class _Tp>
1315*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1316*0b57cec5SDimitry Andrictypename enable_if
1317*0b57cec5SDimitry Andric<
1318*0b57cec5SDimitry Andric    is_trivially_copy_assignable<_Tp>::value,
1319*0b57cec5SDimitry Andric    _Tp*
1320*0b57cec5SDimitry Andric>::type
1321*0b57cec5SDimitry Andric__unwrap_iter(__wrap_iter<_Tp*>);
1322*0b57cec5SDimitry Andric
1323*0b57cec5SDimitry Andric#else
1324*0b57cec5SDimitry Andric
1325*0b57cec5SDimitry Andrictemplate <class _Tp>
1326*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1327*0b57cec5SDimitry Andrictypename enable_if
1328*0b57cec5SDimitry Andric<
1329*0b57cec5SDimitry Andric    is_trivially_copy_assignable<_Tp>::value,
1330*0b57cec5SDimitry Andric    __wrap_iter<_Tp*>
1331*0b57cec5SDimitry Andric>::type
1332*0b57cec5SDimitry Andric__unwrap_iter(__wrap_iter<_Tp*> __i);
1333*0b57cec5SDimitry Andric
1334*0b57cec5SDimitry Andric#endif
1335*0b57cec5SDimitry Andric
1336*0b57cec5SDimitry Andrictemplate <class _Iter>
1337*0b57cec5SDimitry Andricclass __wrap_iter
1338*0b57cec5SDimitry Andric{
1339*0b57cec5SDimitry Andricpublic:
1340*0b57cec5SDimitry Andric    typedef _Iter                                                      iterator_type;
1341*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1342*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::value_type        value_type;
1343*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
1344*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::pointer           pointer;
1345*0b57cec5SDimitry Andric    typedef typename iterator_traits<iterator_type>::reference         reference;
1346*0b57cec5SDimitry Andricprivate:
1347*0b57cec5SDimitry Andric    iterator_type __i;
1348*0b57cec5SDimitry Andricpublic:
1349*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
1350*0b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
1351*0b57cec5SDimitry Andric                : __i{}
1352*0b57cec5SDimitry Andric#endif
1353*0b57cec5SDimitry Andric    {
1354*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1355*0b57cec5SDimitry Andric        __get_db()->__insert_i(this);
1356*0b57cec5SDimitry Andric#endif
1357*0b57cec5SDimitry Andric    }
1358*0b57cec5SDimitry Andric    template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1359*0b57cec5SDimitry Andric        __wrap_iter(const __wrap_iter<_Up>& __u,
1360*0b57cec5SDimitry Andric            typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
1361*0b57cec5SDimitry Andric            : __i(__u.base())
1362*0b57cec5SDimitry Andric    {
1363*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1364*0b57cec5SDimitry Andric        __get_db()->__iterator_copy(this, &__u);
1365*0b57cec5SDimitry Andric#endif
1366*0b57cec5SDimitry Andric    }
1367*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1368*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1369*0b57cec5SDimitry Andric    __wrap_iter(const __wrap_iter& __x)
1370*0b57cec5SDimitry Andric        : __i(__x.base())
1371*0b57cec5SDimitry Andric    {
1372*0b57cec5SDimitry Andric        __get_db()->__iterator_copy(this, &__x);
1373*0b57cec5SDimitry Andric    }
1374*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1375*0b57cec5SDimitry Andric    __wrap_iter& operator=(const __wrap_iter& __x)
1376*0b57cec5SDimitry Andric    {
1377*0b57cec5SDimitry Andric        if (this != &__x)
1378*0b57cec5SDimitry Andric        {
1379*0b57cec5SDimitry Andric            __get_db()->__iterator_copy(this, &__x);
1380*0b57cec5SDimitry Andric            __i = __x.__i;
1381*0b57cec5SDimitry Andric        }
1382*0b57cec5SDimitry Andric        return *this;
1383*0b57cec5SDimitry Andric    }
1384*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1385*0b57cec5SDimitry Andric    ~__wrap_iter()
1386*0b57cec5SDimitry Andric    {
1387*0b57cec5SDimitry Andric        __get_db()->__erase_i(this);
1388*0b57cec5SDimitry Andric    }
1389*0b57cec5SDimitry Andric#endif
1390*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
1391*0b57cec5SDimitry Andric    {
1392*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1393*0b57cec5SDimitry Andric        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1394*0b57cec5SDimitry Andric                       "Attempted to dereference a non-dereferenceable iterator");
1395*0b57cec5SDimitry Andric#endif
1396*0b57cec5SDimitry Andric        return *__i;
1397*0b57cec5SDimitry Andric    }
1398*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
1399*0b57cec5SDimitry Andric    {
1400*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1401*0b57cec5SDimitry Andric        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1402*0b57cec5SDimitry Andric                       "Attempted to dereference a non-dereferenceable iterator");
1403*0b57cec5SDimitry Andric#endif
1404*0b57cec5SDimitry Andric        return (pointer)_VSTD::addressof(*__i);
1405*0b57cec5SDimitry Andric    }
1406*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
1407*0b57cec5SDimitry Andric    {
1408*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1409*0b57cec5SDimitry Andric        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1410*0b57cec5SDimitry Andric                       "Attempted to increment non-incrementable iterator");
1411*0b57cec5SDimitry Andric#endif
1412*0b57cec5SDimitry Andric        ++__i;
1413*0b57cec5SDimitry Andric        return *this;
1414*0b57cec5SDimitry Andric    }
1415*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
1416*0b57cec5SDimitry Andric        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1417*0b57cec5SDimitry Andric
1418*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
1419*0b57cec5SDimitry Andric    {
1420*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1421*0b57cec5SDimitry Andric        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1422*0b57cec5SDimitry Andric                       "Attempted to decrement non-decrementable iterator");
1423*0b57cec5SDimitry Andric#endif
1424*0b57cec5SDimitry Andric        --__i;
1425*0b57cec5SDimitry Andric        return *this;
1426*0b57cec5SDimitry Andric    }
1427*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
1428*0b57cec5SDimitry Andric        {__wrap_iter __tmp(*this); --(*this); return __tmp;}
1429*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
1430*0b57cec5SDimitry Andric        {__wrap_iter __w(*this); __w += __n; return __w;}
1431*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1432*0b57cec5SDimitry Andric    {
1433*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1434*0b57cec5SDimitry Andric        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1435*0b57cec5SDimitry Andric                   "Attempted to add/subtract iterator outside of valid range");
1436*0b57cec5SDimitry Andric#endif
1437*0b57cec5SDimitry Andric        __i += __n;
1438*0b57cec5SDimitry Andric        return *this;
1439*0b57cec5SDimitry Andric    }
1440*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
1441*0b57cec5SDimitry Andric        {return *this + (-__n);}
1442*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1443*0b57cec5SDimitry Andric        {*this += -__n; return *this;}
1444*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
1445*0b57cec5SDimitry Andric    {
1446*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1447*0b57cec5SDimitry Andric        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1448*0b57cec5SDimitry Andric                   "Attempted to subscript iterator outside of valid range");
1449*0b57cec5SDimitry Andric#endif
1450*0b57cec5SDimitry Andric        return __i[__n];
1451*0b57cec5SDimitry Andric    }
1452*0b57cec5SDimitry Andric
1453*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
1454*0b57cec5SDimitry Andric
1455*0b57cec5SDimitry Andricprivate:
1456*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1457*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1458*0b57cec5SDimitry Andric    {
1459*0b57cec5SDimitry Andric        __get_db()->__insert_ic(this, __p);
1460*0b57cec5SDimitry Andric    }
1461*0b57cec5SDimitry Andric#else
1462*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1463*0b57cec5SDimitry Andric#endif
1464*0b57cec5SDimitry Andric
1465*0b57cec5SDimitry Andric    template <class _Up> friend class __wrap_iter;
1466*0b57cec5SDimitry Andric    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1467*0b57cec5SDimitry Andric    template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
1468*0b57cec5SDimitry Andric    template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
1469*0b57cec5SDimitry Andric
1470*0b57cec5SDimitry Andric    template <class _Iter1, class _Iter2>
1471*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1472*0b57cec5SDimitry Andric    bool
1473*0b57cec5SDimitry Andric    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1474*0b57cec5SDimitry Andric
1475*0b57cec5SDimitry Andric    template <class _Iter1, class _Iter2>
1476*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1477*0b57cec5SDimitry Andric    bool
1478*0b57cec5SDimitry Andric    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1479*0b57cec5SDimitry Andric
1480*0b57cec5SDimitry Andric    template <class _Iter1, class _Iter2>
1481*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1482*0b57cec5SDimitry Andric    bool
1483*0b57cec5SDimitry Andric    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1484*0b57cec5SDimitry Andric
1485*0b57cec5SDimitry Andric    template <class _Iter1, class _Iter2>
1486*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1487*0b57cec5SDimitry Andric    bool
1488*0b57cec5SDimitry Andric    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1489*0b57cec5SDimitry Andric
1490*0b57cec5SDimitry Andric    template <class _Iter1, class _Iter2>
1491*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1492*0b57cec5SDimitry Andric    bool
1493*0b57cec5SDimitry Andric    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1494*0b57cec5SDimitry Andric
1495*0b57cec5SDimitry Andric    template <class _Iter1, class _Iter2>
1496*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1497*0b57cec5SDimitry Andric    bool
1498*0b57cec5SDimitry Andric    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1499*0b57cec5SDimitry Andric
1500*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1501*0b57cec5SDimitry Andric    template <class _Iter1, class _Iter2>
1502*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1503*0b57cec5SDimitry Andric    auto
1504*0b57cec5SDimitry Andric    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1505*0b57cec5SDimitry Andric    -> decltype(__x.base() - __y.base());
1506*0b57cec5SDimitry Andric#else
1507*0b57cec5SDimitry Andric    template <class _Iter1, class _Iter2>
1508*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1509*0b57cec5SDimitry Andric    typename __wrap_iter<_Iter1>::difference_type
1510*0b57cec5SDimitry Andric    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1511*0b57cec5SDimitry Andric#endif
1512*0b57cec5SDimitry Andric
1513*0b57cec5SDimitry Andric    template <class _Iter1>
1514*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1515*0b57cec5SDimitry Andric    __wrap_iter<_Iter1>
1516*0b57cec5SDimitry Andric    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
1517*0b57cec5SDimitry Andric
1518*0b57cec5SDimitry Andric    template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
1519*0b57cec5SDimitry Andric    template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
1520*0b57cec5SDimitry Andric    template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
1521*0b57cec5SDimitry Andric    template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1522*0b57cec5SDimitry Andric
1523*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL < 2
1524*0b57cec5SDimitry Andric    template <class _Tp>
1525*0b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1526*0b57cec5SDimitry Andric    typename enable_if
1527*0b57cec5SDimitry Andric    <
1528*0b57cec5SDimitry Andric        is_trivially_copy_assignable<_Tp>::value,
1529*0b57cec5SDimitry Andric        _Tp*
1530*0b57cec5SDimitry Andric    >::type
1531*0b57cec5SDimitry Andric    __unwrap_iter(__wrap_iter<_Tp*>);
1532*0b57cec5SDimitry Andric#else
1533*0b57cec5SDimitry Andric  template <class _Tp>
1534*0b57cec5SDimitry Andric  inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1535*0b57cec5SDimitry Andric  typename enable_if
1536*0b57cec5SDimitry Andric  <
1537*0b57cec5SDimitry Andric      is_trivially_copy_assignable<_Tp>::value,
1538*0b57cec5SDimitry Andric      __wrap_iter<_Tp*>
1539*0b57cec5SDimitry Andric  >::type
1540*0b57cec5SDimitry Andric  __unwrap_iter(__wrap_iter<_Tp*> __i);
1541*0b57cec5SDimitry Andric#endif
1542*0b57cec5SDimitry Andric};
1543*0b57cec5SDimitry Andric
1544*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1545*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1546*0b57cec5SDimitry Andricbool
1547*0b57cec5SDimitry Andricoperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1548*0b57cec5SDimitry Andric{
1549*0b57cec5SDimitry Andric    return __x.base() == __y.base();
1550*0b57cec5SDimitry Andric}
1551*0b57cec5SDimitry Andric
1552*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1553*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1554*0b57cec5SDimitry Andricbool
1555*0b57cec5SDimitry Andricoperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1556*0b57cec5SDimitry Andric{
1557*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1558*0b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1559*0b57cec5SDimitry Andric                   "Attempted to compare incomparable iterators");
1560*0b57cec5SDimitry Andric#endif
1561*0b57cec5SDimitry Andric    return __x.base() < __y.base();
1562*0b57cec5SDimitry Andric}
1563*0b57cec5SDimitry Andric
1564*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1565*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1566*0b57cec5SDimitry Andricbool
1567*0b57cec5SDimitry Andricoperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1568*0b57cec5SDimitry Andric{
1569*0b57cec5SDimitry Andric    return !(__x == __y);
1570*0b57cec5SDimitry Andric}
1571*0b57cec5SDimitry Andric
1572*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1573*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1574*0b57cec5SDimitry Andricbool
1575*0b57cec5SDimitry Andricoperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1576*0b57cec5SDimitry Andric{
1577*0b57cec5SDimitry Andric    return __y < __x;
1578*0b57cec5SDimitry Andric}
1579*0b57cec5SDimitry Andric
1580*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1581*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1582*0b57cec5SDimitry Andricbool
1583*0b57cec5SDimitry Andricoperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1584*0b57cec5SDimitry Andric{
1585*0b57cec5SDimitry Andric    return !(__x < __y);
1586*0b57cec5SDimitry Andric}
1587*0b57cec5SDimitry Andric
1588*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1589*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1590*0b57cec5SDimitry Andricbool
1591*0b57cec5SDimitry Andricoperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1592*0b57cec5SDimitry Andric{
1593*0b57cec5SDimitry Andric    return !(__y < __x);
1594*0b57cec5SDimitry Andric}
1595*0b57cec5SDimitry Andric
1596*0b57cec5SDimitry Andrictemplate <class _Iter1>
1597*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1598*0b57cec5SDimitry Andricbool
1599*0b57cec5SDimitry Andricoperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1600*0b57cec5SDimitry Andric{
1601*0b57cec5SDimitry Andric    return !(__x == __y);
1602*0b57cec5SDimitry Andric}
1603*0b57cec5SDimitry Andric
1604*0b57cec5SDimitry Andrictemplate <class _Iter1>
1605*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1606*0b57cec5SDimitry Andricbool
1607*0b57cec5SDimitry Andricoperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1608*0b57cec5SDimitry Andric{
1609*0b57cec5SDimitry Andric    return __y < __x;
1610*0b57cec5SDimitry Andric}
1611*0b57cec5SDimitry Andric
1612*0b57cec5SDimitry Andrictemplate <class _Iter1>
1613*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1614*0b57cec5SDimitry Andricbool
1615*0b57cec5SDimitry Andricoperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1616*0b57cec5SDimitry Andric{
1617*0b57cec5SDimitry Andric    return !(__x < __y);
1618*0b57cec5SDimitry Andric}
1619*0b57cec5SDimitry Andric
1620*0b57cec5SDimitry Andrictemplate <class _Iter1>
1621*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1622*0b57cec5SDimitry Andricbool
1623*0b57cec5SDimitry Andricoperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1624*0b57cec5SDimitry Andric{
1625*0b57cec5SDimitry Andric    return !(__y < __x);
1626*0b57cec5SDimitry Andric}
1627*0b57cec5SDimitry Andric
1628*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1629*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1630*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1631*0b57cec5SDimitry Andricauto
1632*0b57cec5SDimitry Andricoperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1633*0b57cec5SDimitry Andric-> decltype(__x.base() - __y.base())
1634*0b57cec5SDimitry Andric{
1635*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1636*0b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1637*0b57cec5SDimitry Andric                   "Attempted to subtract incompatible iterators");
1638*0b57cec5SDimitry Andric#endif
1639*0b57cec5SDimitry Andric    return __x.base() - __y.base();
1640*0b57cec5SDimitry Andric}
1641*0b57cec5SDimitry Andric#else
1642*0b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2>
1643*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1644*0b57cec5SDimitry Andrictypename __wrap_iter<_Iter1>::difference_type
1645*0b57cec5SDimitry Andricoperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1646*0b57cec5SDimitry Andric{
1647*0b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1648*0b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1649*0b57cec5SDimitry Andric                   "Attempted to subtract incompatible iterators");
1650*0b57cec5SDimitry Andric#endif
1651*0b57cec5SDimitry Andric    return __x.base() - __y.base();
1652*0b57cec5SDimitry Andric}
1653*0b57cec5SDimitry Andric#endif
1654*0b57cec5SDimitry Andric
1655*0b57cec5SDimitry Andrictemplate <class _Iter>
1656*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1657*0b57cec5SDimitry Andric__wrap_iter<_Iter>
1658*0b57cec5SDimitry Andricoperator+(typename __wrap_iter<_Iter>::difference_type __n,
1659*0b57cec5SDimitry Andric          __wrap_iter<_Iter> __x) _NOEXCEPT
1660*0b57cec5SDimitry Andric{
1661*0b57cec5SDimitry Andric    __x += __n;
1662*0b57cec5SDimitry Andric    return __x;
1663*0b57cec5SDimitry Andric}
1664*0b57cec5SDimitry Andric
1665*0b57cec5SDimitry Andrictemplate <class _Iter>
1666*0b57cec5SDimitry Andricstruct __libcpp_is_trivial_iterator
1667*0b57cec5SDimitry Andric    : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1668*0b57cec5SDimitry Andric
1669*0b57cec5SDimitry Andrictemplate <class _Iter>
1670*0b57cec5SDimitry Andricstruct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
1671*0b57cec5SDimitry Andric    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1672*0b57cec5SDimitry Andric
1673*0b57cec5SDimitry Andrictemplate <class _Iter>
1674*0b57cec5SDimitry Andricstruct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
1675*0b57cec5SDimitry Andric    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1676*0b57cec5SDimitry Andric
1677*0b57cec5SDimitry Andrictemplate <class _Iter>
1678*0b57cec5SDimitry Andricstruct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
1679*0b57cec5SDimitry Andric    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1680*0b57cec5SDimitry Andric
1681*0b57cec5SDimitry Andric
1682*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Np>
1683*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1684*0b57cec5SDimitry Andric_Tp*
1685*0b57cec5SDimitry Andricbegin(_Tp (&__array)[_Np])
1686*0b57cec5SDimitry Andric{
1687*0b57cec5SDimitry Andric    return __array;
1688*0b57cec5SDimitry Andric}
1689*0b57cec5SDimitry Andric
1690*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Np>
1691*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1692*0b57cec5SDimitry Andric_Tp*
1693*0b57cec5SDimitry Andricend(_Tp (&__array)[_Np])
1694*0b57cec5SDimitry Andric{
1695*0b57cec5SDimitry Andric    return __array + _Np;
1696*0b57cec5SDimitry Andric}
1697*0b57cec5SDimitry Andric
1698*0b57cec5SDimitry Andric#if !defined(_LIBCPP_CXX03_LANG)
1699*0b57cec5SDimitry Andric
1700*0b57cec5SDimitry Andrictemplate <class _Cp>
1701*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1702*0b57cec5SDimitry Andricauto
1703*0b57cec5SDimitry Andricbegin(_Cp& __c) -> decltype(__c.begin())
1704*0b57cec5SDimitry Andric{
1705*0b57cec5SDimitry Andric    return __c.begin();
1706*0b57cec5SDimitry Andric}
1707*0b57cec5SDimitry Andric
1708*0b57cec5SDimitry Andrictemplate <class _Cp>
1709*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1710*0b57cec5SDimitry Andricauto
1711*0b57cec5SDimitry Andricbegin(const _Cp& __c) -> decltype(__c.begin())
1712*0b57cec5SDimitry Andric{
1713*0b57cec5SDimitry Andric    return __c.begin();
1714*0b57cec5SDimitry Andric}
1715*0b57cec5SDimitry Andric
1716*0b57cec5SDimitry Andrictemplate <class _Cp>
1717*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1718*0b57cec5SDimitry Andricauto
1719*0b57cec5SDimitry Andricend(_Cp& __c) -> decltype(__c.end())
1720*0b57cec5SDimitry Andric{
1721*0b57cec5SDimitry Andric    return __c.end();
1722*0b57cec5SDimitry Andric}
1723*0b57cec5SDimitry Andric
1724*0b57cec5SDimitry Andrictemplate <class _Cp>
1725*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1726*0b57cec5SDimitry Andricauto
1727*0b57cec5SDimitry Andricend(const _Cp& __c) -> decltype(__c.end())
1728*0b57cec5SDimitry Andric{
1729*0b57cec5SDimitry Andric    return __c.end();
1730*0b57cec5SDimitry Andric}
1731*0b57cec5SDimitry Andric
1732*0b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
1733*0b57cec5SDimitry Andric
1734*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Np>
1735*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1736*0b57cec5SDimitry Andricreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1737*0b57cec5SDimitry Andric{
1738*0b57cec5SDimitry Andric    return reverse_iterator<_Tp*>(__array + _Np);
1739*0b57cec5SDimitry Andric}
1740*0b57cec5SDimitry Andric
1741*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Np>
1742*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1743*0b57cec5SDimitry Andricreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1744*0b57cec5SDimitry Andric{
1745*0b57cec5SDimitry Andric    return reverse_iterator<_Tp*>(__array);
1746*0b57cec5SDimitry Andric}
1747*0b57cec5SDimitry Andric
1748*0b57cec5SDimitry Andrictemplate <class _Ep>
1749*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1750*0b57cec5SDimitry Andricreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1751*0b57cec5SDimitry Andric{
1752*0b57cec5SDimitry Andric    return reverse_iterator<const _Ep*>(__il.end());
1753*0b57cec5SDimitry Andric}
1754*0b57cec5SDimitry Andric
1755*0b57cec5SDimitry Andrictemplate <class _Ep>
1756*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1757*0b57cec5SDimitry Andricreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1758*0b57cec5SDimitry Andric{
1759*0b57cec5SDimitry Andric    return reverse_iterator<const _Ep*>(__il.begin());
1760*0b57cec5SDimitry Andric}
1761*0b57cec5SDimitry Andric
1762*0b57cec5SDimitry Andrictemplate <class _Cp>
1763*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1764*0b57cec5SDimitry Andricauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
1765*0b57cec5SDimitry Andric{
1766*0b57cec5SDimitry Andric    return _VSTD::begin(__c);
1767*0b57cec5SDimitry Andric}
1768*0b57cec5SDimitry Andric
1769*0b57cec5SDimitry Andrictemplate <class _Cp>
1770*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1771*0b57cec5SDimitry Andricauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
1772*0b57cec5SDimitry Andric{
1773*0b57cec5SDimitry Andric    return _VSTD::end(__c);
1774*0b57cec5SDimitry Andric}
1775*0b57cec5SDimitry Andric
1776*0b57cec5SDimitry Andrictemplate <class _Cp>
1777*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1778*0b57cec5SDimitry Andricauto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1779*0b57cec5SDimitry Andric{
1780*0b57cec5SDimitry Andric    return __c.rbegin();
1781*0b57cec5SDimitry Andric}
1782*0b57cec5SDimitry Andric
1783*0b57cec5SDimitry Andrictemplate <class _Cp>
1784*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1785*0b57cec5SDimitry Andricauto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1786*0b57cec5SDimitry Andric{
1787*0b57cec5SDimitry Andric    return __c.rbegin();
1788*0b57cec5SDimitry Andric}
1789*0b57cec5SDimitry Andric
1790*0b57cec5SDimitry Andrictemplate <class _Cp>
1791*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1792*0b57cec5SDimitry Andricauto rend(_Cp& __c) -> decltype(__c.rend())
1793*0b57cec5SDimitry Andric{
1794*0b57cec5SDimitry Andric    return __c.rend();
1795*0b57cec5SDimitry Andric}
1796*0b57cec5SDimitry Andric
1797*0b57cec5SDimitry Andrictemplate <class _Cp>
1798*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1799*0b57cec5SDimitry Andricauto rend(const _Cp& __c) -> decltype(__c.rend())
1800*0b57cec5SDimitry Andric{
1801*0b57cec5SDimitry Andric    return __c.rend();
1802*0b57cec5SDimitry Andric}
1803*0b57cec5SDimitry Andric
1804*0b57cec5SDimitry Andrictemplate <class _Cp>
1805*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1806*0b57cec5SDimitry Andricauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
1807*0b57cec5SDimitry Andric{
1808*0b57cec5SDimitry Andric    return _VSTD::rbegin(__c);
1809*0b57cec5SDimitry Andric}
1810*0b57cec5SDimitry Andric
1811*0b57cec5SDimitry Andrictemplate <class _Cp>
1812*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1813*0b57cec5SDimitry Andricauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
1814*0b57cec5SDimitry Andric{
1815*0b57cec5SDimitry Andric    return _VSTD::rend(__c);
1816*0b57cec5SDimitry Andric}
1817*0b57cec5SDimitry Andric
1818*0b57cec5SDimitry Andric#endif
1819*0b57cec5SDimitry Andric
1820*0b57cec5SDimitry Andric
1821*0b57cec5SDimitry Andric#else  // defined(_LIBCPP_CXX03_LANG)
1822*0b57cec5SDimitry Andric
1823*0b57cec5SDimitry Andrictemplate <class _Cp>
1824*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1825*0b57cec5SDimitry Andrictypename _Cp::iterator
1826*0b57cec5SDimitry Andricbegin(_Cp& __c)
1827*0b57cec5SDimitry Andric{
1828*0b57cec5SDimitry Andric    return __c.begin();
1829*0b57cec5SDimitry Andric}
1830*0b57cec5SDimitry Andric
1831*0b57cec5SDimitry Andrictemplate <class _Cp>
1832*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1833*0b57cec5SDimitry Andrictypename _Cp::const_iterator
1834*0b57cec5SDimitry Andricbegin(const _Cp& __c)
1835*0b57cec5SDimitry Andric{
1836*0b57cec5SDimitry Andric    return __c.begin();
1837*0b57cec5SDimitry Andric}
1838*0b57cec5SDimitry Andric
1839*0b57cec5SDimitry Andrictemplate <class _Cp>
1840*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1841*0b57cec5SDimitry Andrictypename _Cp::iterator
1842*0b57cec5SDimitry Andricend(_Cp& __c)
1843*0b57cec5SDimitry Andric{
1844*0b57cec5SDimitry Andric    return __c.end();
1845*0b57cec5SDimitry Andric}
1846*0b57cec5SDimitry Andric
1847*0b57cec5SDimitry Andrictemplate <class _Cp>
1848*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1849*0b57cec5SDimitry Andrictypename _Cp::const_iterator
1850*0b57cec5SDimitry Andricend(const _Cp& __c)
1851*0b57cec5SDimitry Andric{
1852*0b57cec5SDimitry Andric    return __c.end();
1853*0b57cec5SDimitry Andric}
1854*0b57cec5SDimitry Andric
1855*0b57cec5SDimitry Andric#endif  // !defined(_LIBCPP_CXX03_LANG)
1856*0b57cec5SDimitry Andric
1857*0b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
1858*0b57cec5SDimitry Andric
1859*0b57cec5SDimitry Andric// #if _LIBCPP_STD_VER > 11
1860*0b57cec5SDimitry Andric// template <>
1861*0b57cec5SDimitry Andric// struct _LIBCPP_TEMPLATE_VIS plus<void>
1862*0b57cec5SDimitry Andric// {
1863*0b57cec5SDimitry Andric//     template <class _T1, class _T2>
1864*0b57cec5SDimitry Andric//     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1865*0b57cec5SDimitry Andric//     auto operator()(_T1&& __t, _T2&& __u) const
1866*0b57cec5SDimitry Andric//     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1867*0b57cec5SDimitry Andric//     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1868*0b57cec5SDimitry Andric//         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1869*0b57cec5SDimitry Andric//     typedef void is_transparent;
1870*0b57cec5SDimitry Andric// };
1871*0b57cec5SDimitry Andric// #endif
1872*0b57cec5SDimitry Andric
1873*0b57cec5SDimitry Andrictemplate <class _Cont>
1874*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1875*0b57cec5SDimitry Andricconstexpr auto size(const _Cont& __c)
1876*0b57cec5SDimitry Andric_NOEXCEPT_(noexcept(__c.size()))
1877*0b57cec5SDimitry Andric-> decltype        (__c.size())
1878*0b57cec5SDimitry Andric{ return            __c.size(); }
1879*0b57cec5SDimitry Andric
1880*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Sz>
1881*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1882*0b57cec5SDimitry Andricconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1883*0b57cec5SDimitry Andric
1884*0b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
1885*0b57cec5SDimitry Andrictemplate <class _Cont>
1886*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1887*0b57cec5SDimitry Andricconstexpr auto ssize(const _Cont& __c)
1888*0b57cec5SDimitry Andric_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1889*0b57cec5SDimitry Andric->                              common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1890*0b57cec5SDimitry Andric{ return            static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1891*0b57cec5SDimitry Andric
1892*0b57cec5SDimitry Andrictemplate <class _Tp, ptrdiff_t _Sz>
1893*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1894*0b57cec5SDimitry Andricconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1895*0b57cec5SDimitry Andric#endif
1896*0b57cec5SDimitry Andric
1897*0b57cec5SDimitry Andrictemplate <class _Cont>
1898*0b57cec5SDimitry Andric_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1899*0b57cec5SDimitry Andricconstexpr auto empty(const _Cont& __c)
1900*0b57cec5SDimitry Andric_NOEXCEPT_(noexcept(__c.empty()))
1901*0b57cec5SDimitry Andric-> decltype        (__c.empty())
1902*0b57cec5SDimitry Andric{ return            __c.empty(); }
1903*0b57cec5SDimitry Andric
1904*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Sz>
1905*0b57cec5SDimitry Andric_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1906*0b57cec5SDimitry Andricconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1907*0b57cec5SDimitry Andric
1908*0b57cec5SDimitry Andrictemplate <class _Ep>
1909*0b57cec5SDimitry Andric_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1910*0b57cec5SDimitry Andricconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1911*0b57cec5SDimitry Andric
1912*0b57cec5SDimitry Andrictemplate <class _Cont> constexpr
1913*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1914*0b57cec5SDimitry Andricauto data(_Cont& __c)
1915*0b57cec5SDimitry Andric_NOEXCEPT_(noexcept(__c.data()))
1916*0b57cec5SDimitry Andric-> decltype        (__c.data())
1917*0b57cec5SDimitry Andric{ return            __c.data(); }
1918*0b57cec5SDimitry Andric
1919*0b57cec5SDimitry Andrictemplate <class _Cont> constexpr
1920*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1921*0b57cec5SDimitry Andricauto data(const _Cont& __c)
1922*0b57cec5SDimitry Andric_NOEXCEPT_(noexcept(__c.data()))
1923*0b57cec5SDimitry Andric-> decltype        (__c.data())
1924*0b57cec5SDimitry Andric{ return            __c.data(); }
1925*0b57cec5SDimitry Andric
1926*0b57cec5SDimitry Andrictemplate <class _Tp, size_t _Sz>
1927*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1928*0b57cec5SDimitry Andricconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1929*0b57cec5SDimitry Andric
1930*0b57cec5SDimitry Andrictemplate <class _Ep>
1931*0b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1932*0b57cec5SDimitry Andricconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1933*0b57cec5SDimitry Andric#endif
1934*0b57cec5SDimitry Andric
1935*0b57cec5SDimitry Andric
1936*0b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
1937*0b57cec5SDimitry Andric
1938*0b57cec5SDimitry Andric#endif  // _LIBCPP_ITERATOR
1939