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