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