2 //===-------------------------- iterator ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_ITERATOR
12 #define _LIBCPP_ITERATOR
20 template<class Iterator>
21 struct iterator_traits
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;
31 struct iterator_traits<T*>
33 typedef ptrdiff_t difference_type;
37 typedef random_access_iterator_tag iterator_category;
41 struct iterator_traits<const T*>
43 typedef ptrdiff_t difference_type;
45 typedef const T* pointer;
46 typedef const T& reference;
47 typedef random_access_iterator_tag iterator_category;
50 template<class Category, class T, class Distance = ptrdiff_t,
51 class Pointer = T*, class Reference = T&>
55 typedef Distance difference_type;
56 typedef Pointer pointer;
57 typedef Reference reference;
58 typedef Category iterator_category;
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 {};
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);
72 template <class InputIterator>
73 typename iterator_traits<InputIterator>::difference_type
74 distance(InputIterator first, InputIterator last);
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>
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;
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;
109 template <class Iterator1, class Iterator2>
111 operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
113 template <class Iterator1, class Iterator2>
115 operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
117 template <class Iterator1, class Iterator2>
119 operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
121 template <class Iterator1, class Iterator2>
123 operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
125 template <class Iterator1, class Iterator2>
127 operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
129 template <class Iterator1, class Iterator2>
131 operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
133 template <class Iterator1, class Iterator2>
134 typename reverse_iterator<Iterator1>::difference_type
135 operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
137 template <class Iterator>
138 reverse_iterator<Iterator>
139 operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x);
141 template <class Iterator> reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14
143 template <class Container>
144 class back_insert_iterator
147 Container* container;
149 typedef Container container_type;
150 typedef void value_type;
151 typedef void difference_type;
152 typedef back_insert_iterator<Cont>& reference;
153 typedef void pointer;
155 explicit back_insert_iterator(Container& x);
156 back_insert_iterator& operator=(const typename Container::value_type& value);
157 back_insert_iterator& operator*();
158 back_insert_iterator& operator++();
159 back_insert_iterator operator++(int);
162 template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
164 template <class Container>
165 class front_insert_iterator
168 Container* container;
170 typedef Container container_type;
171 typedef void value_type;
172 typedef void difference_type;
173 typedef front_insert_iterator<Cont>& reference;
174 typedef void pointer;
176 explicit front_insert_iterator(Container& x);
177 front_insert_iterator& operator=(const typename Container::value_type& value);
178 front_insert_iterator& operator*();
179 front_insert_iterator& operator++();
180 front_insert_iterator operator++(int);
183 template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
185 template <class Container>
186 class insert_iterator
189 Container* container;
190 typename Container::iterator iter;
192 typedef Container container_type;
193 typedef void value_type;
194 typedef void difference_type;
195 typedef insert_iterator<Cont>& reference;
196 typedef void pointer;
198 insert_iterator(Container& x, typename Container::iterator i);
199 insert_iterator& operator=(const typename Container::value_type& value);
200 insert_iterator& operator*();
201 insert_iterator& operator++();
202 insert_iterator& operator++(int);
205 template <class Container, class Iterator>
206 insert_iterator<Container> inserter(Container& x, Iterator i);
208 template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
209 class istream_iterator
210 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
213 typedef charT char_type;
214 typedef traits traits_type;
215 typedef basic_istream<charT,traits> istream_type;
217 constexpr istream_iterator();
218 istream_iterator(istream_type& s);
219 istream_iterator(const istream_iterator& x);
222 const T& operator*() const;
223 const T* operator->() const;
224 istream_iterator& operator++();
225 istream_iterator operator++(int);
228 template <class T, class charT, class traits, class Distance>
229 bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
230 const istream_iterator<T,charT,traits,Distance>& y);
231 template <class T, class charT, class traits, class Distance>
232 bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
233 const istream_iterator<T,charT,traits,Distance>& y);
235 template <class T, class charT = char, class traits = char_traits<charT> >
236 class ostream_iterator
237 : public iterator<output_iterator_tag, void, void, void ,void>
240 typedef charT char_type;
241 typedef traits traits_type;
242 typedef basic_ostream<charT,traits> ostream_type;
244 ostream_iterator(ostream_type& s);
245 ostream_iterator(ostream_type& s, const charT* delimiter);
246 ostream_iterator(const ostream_iterator& x);
248 ostream_iterator& operator=(const T& value);
250 ostream_iterator& operator*();
251 ostream_iterator& operator++();
252 ostream_iterator& operator++(int);
255 template<class charT, class traits = char_traits<charT> >
256 class istreambuf_iterator
257 : public iterator<input_iterator_tag, charT,
258 typename traits::off_type, unspecified,
262 typedef charT char_type;
263 typedef traits traits_type;
264 typedef typename traits::int_type int_type;
265 typedef basic_streambuf<charT,traits> streambuf_type;
266 typedef basic_istream<charT,traits> istream_type;
268 istreambuf_iterator() noexcept;
269 istreambuf_iterator(istream_type& s) noexcept;
270 istreambuf_iterator(streambuf_type* s) noexcept;
271 istreambuf_iterator(a-private-type) noexcept;
273 charT operator*() const;
274 pointer operator->() const;
275 istreambuf_iterator& operator++();
276 a-private-type operator++(int);
278 bool equal(const istreambuf_iterator& b) const;
281 template <class charT, class traits>
282 bool operator==(const istreambuf_iterator<charT,traits>& a,
283 const istreambuf_iterator<charT,traits>& b);
284 template <class charT, class traits>
285 bool operator!=(const istreambuf_iterator<charT,traits>& a,
286 const istreambuf_iterator<charT,traits>& b);
288 template <class charT, class traits = char_traits<charT> >
289 class ostreambuf_iterator
290 : public iterator<output_iterator_tag, void, void, void, void>
293 typedef charT char_type;
294 typedef traits traits_type;
295 typedef basic_streambuf<charT,traits> streambuf_type;
296 typedef basic_ostream<charT,traits> ostream_type;
298 ostreambuf_iterator(ostream_type& s) noexcept;
299 ostreambuf_iterator(streambuf_type* s) noexcept;
300 ostreambuf_iterator& operator=(charT c);
301 ostreambuf_iterator& operator*();
302 ostreambuf_iterator& operator++();
303 ostreambuf_iterator& operator++(int);
304 bool failed() const noexcept;
307 template <class C> auto begin(C& c) -> decltype(c.begin());
308 template <class C> auto begin(const C& c) -> decltype(c.begin());
309 template <class C> auto end(C& c) -> decltype(c.end());
310 template <class C> auto end(const C& c) -> decltype(c.end());
311 template <class T, size_t N> T* begin(T (&array)[N]);
312 template <class T, size_t N> T* end(T (&array)[N]);
314 template <class C> auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14
315 template <class C> auto cend(const C& c) -> decltype(std::end(c)); // C++14
316 template <class C> auto rbegin(C& c) -> decltype(c.rbegin()); // C++14
317 template <class C> auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14
318 template <class C> auto rend(C& c) -> decltype(c.rend()); // C++14
319 template <class C> auto rend(const C& c) -> decltype(c.rend()); // C++14
320 template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14
321 template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); // C++14
322 template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]); // C++14
323 template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]); // C++14
324 template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
325 template <class C> auto crend(const C& c) -> decltype(std::rend(c)); // C++14
327 // 24.8, container access:
328 template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
329 template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
330 template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
331 template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
332 template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
333 template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
334 template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
335 template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
336 template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
343 #include <__functional_base>
344 #include <type_traits>
347 #include <initializer_list>
349 #include <Availability.h>
354 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
355 #pragma GCC system_header
358 _LIBCPP_BEGIN_NAMESPACE_STD
360 struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
361 struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
362 struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
363 struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
364 struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
367 struct __has_iterator_category
370 struct __two {char __lx; char __lxx;};
371 template <class _Up> static __two __test(...);
372 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
374 static const bool value = sizeof(__test<_Tp>(0)) == 1;
377 template <class _Iter, bool> struct __iterator_traits_impl {};
379 template <class _Iter>
380 struct __iterator_traits_impl<_Iter, true>
382 typedef typename _Iter::difference_type difference_type;
383 typedef typename _Iter::value_type value_type;
384 typedef typename _Iter::pointer pointer;
385 typedef typename _Iter::reference reference;
386 typedef typename _Iter::iterator_category iterator_category;
389 template <class _Iter, bool> struct __iterator_traits {};
391 template <class _Iter>
392 struct __iterator_traits<_Iter, true>
393 : __iterator_traits_impl
396 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
397 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
401 // iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
402 // exists. Else iterator_traits<Iterator> will be an empty class. This is a
403 // conforming extension which allows some programs to compile and behave as
404 // the client expects instead of failing at compile time.
406 template <class _Iter>
407 struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
408 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
411 struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
413 typedef ptrdiff_t difference_type;
414 typedef typename remove_const<_Tp>::type value_type;
415 typedef _Tp* pointer;
416 typedef _Tp& reference;
417 typedef random_access_iterator_tag iterator_category;
420 template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
421 struct __has_iterator_category_convertible_to
422 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
425 template <class _Tp, class _Up>
426 struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
429 struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
432 struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
435 struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
438 struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
441 struct __is_exactly_input_iterator
442 : public integral_constant<bool,
443 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
444 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
446 template<class _Category, class _Tp, class _Distance = ptrdiff_t,
447 class _Pointer = _Tp*, class _Reference = _Tp&>
448 struct _LIBCPP_TYPE_VIS_ONLY iterator
450 typedef _Tp value_type;
451 typedef _Distance difference_type;
452 typedef _Pointer pointer;
453 typedef _Reference reference;
454 typedef _Category iterator_category;
457 template <class _InputIter>
458 inline _LIBCPP_INLINE_VISIBILITY
459 void __advance(_InputIter& __i,
460 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
462 for (; __n > 0; --__n)
466 template <class _BiDirIter>
467 inline _LIBCPP_INLINE_VISIBILITY
468 void __advance(_BiDirIter& __i,
469 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
472 for (; __n > 0; --__n)
475 for (; __n < 0; ++__n)
479 template <class _RandIter>
480 inline _LIBCPP_INLINE_VISIBILITY
481 void __advance(_RandIter& __i,
482 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
487 template <class _InputIter>
488 inline _LIBCPP_INLINE_VISIBILITY
489 void advance(_InputIter& __i,
490 typename iterator_traits<_InputIter>::difference_type __n)
492 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
495 template <class _InputIter>
496 inline _LIBCPP_INLINE_VISIBILITY
497 typename iterator_traits<_InputIter>::difference_type
498 __distance(_InputIter __first, _InputIter __last, input_iterator_tag)
500 typename iterator_traits<_InputIter>::difference_type __r(0);
501 for (; __first != __last; ++__first)
506 template <class _RandIter>
507 inline _LIBCPP_INLINE_VISIBILITY
508 typename iterator_traits<_RandIter>::difference_type
509 __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
511 return __last - __first;
514 template <class _InputIter>
515 inline _LIBCPP_INLINE_VISIBILITY
516 typename iterator_traits<_InputIter>::difference_type
517 distance(_InputIter __first, _InputIter __last)
519 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
522 template <class _InputIter>
523 inline _LIBCPP_INLINE_VISIBILITY
526 typename iterator_traits<_InputIter>::difference_type __n = 1,
527 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
529 _VSTD::advance(__x, __n);
533 template <class _BidiretionalIter>
534 inline _LIBCPP_INLINE_VISIBILITY
536 prev(_BidiretionalIter __x,
537 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
538 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
540 _VSTD::advance(__x, -__n);
544 template <class _Iter>
545 class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
546 : public iterator<typename iterator_traits<_Iter>::iterator_category,
547 typename iterator_traits<_Iter>::value_type,
548 typename iterator_traits<_Iter>::difference_type,
549 typename iterator_traits<_Iter>::pointer,
550 typename iterator_traits<_Iter>::reference>
553 mutable _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
557 typedef _Iter iterator_type;
558 typedef typename iterator_traits<_Iter>::difference_type difference_type;
559 typedef typename iterator_traits<_Iter>::reference reference;
560 typedef typename iterator_traits<_Iter>::pointer pointer;
562 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
563 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
564 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
565 : __t(__u.base()), current(__u.base()) {}
566 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
567 _LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;}
568 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());}
569 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
570 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
571 {reverse_iterator __tmp(*this); --current; return __tmp;}
572 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
573 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
574 {reverse_iterator __tmp(*this); ++current; return __tmp;}
575 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
576 {return reverse_iterator(current - __n);}
577 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
578 {current -= __n; return *this;}
579 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
580 {return reverse_iterator(current + __n);}
581 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
582 {current += __n; return *this;}
583 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
584 {return *(*this + __n);}
587 template <class _Iter1, class _Iter2>
588 inline _LIBCPP_INLINE_VISIBILITY
590 operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
592 return __x.base() == __y.base();
595 template <class _Iter1, class _Iter2>
596 inline _LIBCPP_INLINE_VISIBILITY
598 operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
600 return __x.base() > __y.base();
603 template <class _Iter1, class _Iter2>
604 inline _LIBCPP_INLINE_VISIBILITY
606 operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
608 return __x.base() != __y.base();
611 template <class _Iter1, class _Iter2>
612 inline _LIBCPP_INLINE_VISIBILITY
614 operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
616 return __x.base() < __y.base();
619 template <class _Iter1, class _Iter2>
620 inline _LIBCPP_INLINE_VISIBILITY
622 operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
624 return __x.base() <= __y.base();
627 template <class _Iter1, class _Iter2>
628 inline _LIBCPP_INLINE_VISIBILITY
630 operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
632 return __x.base() >= __y.base();
635 template <class _Iter1, class _Iter2>
636 inline _LIBCPP_INLINE_VISIBILITY
637 typename reverse_iterator<_Iter1>::difference_type
638 operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
640 return __y.base() - __x.base();
643 template <class _Iter>
644 inline _LIBCPP_INLINE_VISIBILITY
645 reverse_iterator<_Iter>
646 operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
648 return reverse_iterator<_Iter>(__x.base() - __n);
651 #if _LIBCPP_STD_VER > 11
652 template <class _Iter>
653 inline _LIBCPP_INLINE_VISIBILITY
654 reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
656 return reverse_iterator<_Iter>(__i);
660 template <class _Container>
661 class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
662 : public iterator<output_iterator_tag,
666 back_insert_iterator<_Container>&>
669 _Container* container;
671 typedef _Container container_type;
673 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
674 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
675 {container->push_back(__value_); return *this;}
676 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
677 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
678 {container->push_back(_VSTD::move(__value_)); return *this;}
679 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
680 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
681 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
682 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
685 template <class _Container>
686 inline _LIBCPP_INLINE_VISIBILITY
687 back_insert_iterator<_Container>
688 back_inserter(_Container& __x)
690 return back_insert_iterator<_Container>(__x);
693 template <class _Container>
694 class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
695 : public iterator<output_iterator_tag,
699 front_insert_iterator<_Container>&>
702 _Container* container;
704 typedef _Container container_type;
706 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
707 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
708 {container->push_front(__value_); return *this;}
709 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
710 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
711 {container->push_front(_VSTD::move(__value_)); return *this;}
712 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
713 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
714 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
715 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
718 template <class _Container>
719 inline _LIBCPP_INLINE_VISIBILITY
720 front_insert_iterator<_Container>
721 front_inserter(_Container& __x)
723 return front_insert_iterator<_Container>(__x);
726 template <class _Container>
727 class _LIBCPP_TYPE_VIS_ONLY insert_iterator
728 : public iterator<output_iterator_tag,
732 insert_iterator<_Container>&>
735 _Container* container;
736 typename _Container::iterator iter;
738 typedef _Container container_type;
740 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
741 : container(_VSTD::addressof(__x)), iter(__i) {}
742 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
743 {iter = container->insert(iter, __value_); ++iter; return *this;}
744 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
745 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
746 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
747 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
748 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
749 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
750 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
753 template <class _Container>
754 inline _LIBCPP_INLINE_VISIBILITY
755 insert_iterator<_Container>
756 inserter(_Container& __x, typename _Container::iterator __i)
758 return insert_iterator<_Container>(__x, __i);
761 template <class _Tp, class _CharT = char,
762 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
763 class _LIBCPP_TYPE_VIS_ONLY istream_iterator
764 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
767 typedef _CharT char_type;
768 typedef _Traits traits_type;
769 typedef basic_istream<_CharT,_Traits> istream_type;
771 istream_type* __in_stream_;
774 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
775 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
777 if (!(*__in_stream_ >> __value_))
781 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
782 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
783 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
785 if (!(*__in_stream_ >> __value_))
789 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
790 {istream_iterator __t(*this); ++(*this); return __t;}
792 friend _LIBCPP_INLINE_VISIBILITY
793 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
794 {return __x.__in_stream_ == __y.__in_stream_;}
796 friend _LIBCPP_INLINE_VISIBILITY
797 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
798 {return !(__x == __y);}
801 template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
802 class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
803 : public iterator<output_iterator_tag, void, void, void, void>
806 typedef _CharT char_type;
807 typedef _Traits traits_type;
808 typedef basic_ostream<_CharT,_Traits> ostream_type;
810 ostream_type* __out_stream_;
811 const char_type* __delim_;
813 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
814 : __out_stream_(&__s), __delim_(0) {}
815 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
816 : __out_stream_(&__s), __delim_(__delimiter) {}
817 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
819 *__out_stream_ << __value_;
821 *__out_stream_ << __delim_;
825 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
826 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
827 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
830 template<class _CharT, class _Traits>
831 class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
832 : public iterator<input_iterator_tag, _CharT,
833 typename _Traits::off_type, _CharT*,
837 typedef _CharT char_type;
838 typedef _Traits traits_type;
839 typedef typename _Traits::int_type int_type;
840 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
841 typedef basic_istream<_CharT,_Traits> istream_type;
843 mutable streambuf_type* __sbuf_;
848 streambuf_type* __sbuf_;
849 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
850 : __keep_(__c), __sbuf_(__s) {}
851 friend class istreambuf_iterator;
853 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
856 _LIBCPP_INLINE_VISIBILITY
857 bool __test_for_eof() const
859 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
864 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
865 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
866 : __sbuf_(__s.rdbuf()) {}
867 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
869 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
870 : __sbuf_(__p.__sbuf_) {}
872 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
873 {return static_cast<char_type>(__sbuf_->sgetc());}
874 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
875 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
880 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
882 return __proxy(__sbuf_->sbumpc(), __sbuf_);
885 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
886 {return __test_for_eof() == __b.__test_for_eof();}
889 template <class _CharT, class _Traits>
890 inline _LIBCPP_INLINE_VISIBILITY
891 bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
892 const istreambuf_iterator<_CharT,_Traits>& __b)
893 {return __a.equal(__b);}
895 template <class _CharT, class _Traits>
896 inline _LIBCPP_INLINE_VISIBILITY
897 bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
898 const istreambuf_iterator<_CharT,_Traits>& __b)
899 {return !__a.equal(__b);}
901 template <class _CharT, class _Traits>
902 class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
903 : public iterator<output_iterator_tag, void, void, void, void>
906 typedef _CharT char_type;
907 typedef _Traits traits_type;
908 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
909 typedef basic_ostream<_CharT,_Traits> ostream_type;
911 streambuf_type* __sbuf_;
913 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
914 : __sbuf_(__s.rdbuf()) {}
915 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
917 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
919 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
923 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
924 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
925 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
926 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
928 #if !defined(__APPLE__) || \
929 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
930 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
932 template <class _Ch, class _Tr>
935 ostreambuf_iterator<_Ch, _Tr>
936 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
937 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
938 ios_base& __iob, _Ch __fl);
942 template <class _Iter>
943 class _LIBCPP_TYPE_VIS_ONLY move_iterator
948 typedef _Iter iterator_type;
949 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
950 typedef typename iterator_traits<iterator_type>::value_type value_type;
951 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
952 typedef typename iterator_traits<iterator_type>::pointer pointer;
953 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
954 typedef value_type&& reference;
956 typedef typename iterator_traits<iterator_type>::reference reference;
959 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
960 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
961 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
963 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
964 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
965 return static_cast<reference>(*__i);
967 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
968 typename iterator_traits<iterator_type>::reference __ref = *__i;
971 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
972 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
973 {move_iterator __tmp(*this); ++__i; return __tmp;}
974 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
975 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
976 {move_iterator __tmp(*this); --__i; return __tmp;}
977 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
978 {return move_iterator(__i + __n);}
979 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
980 {__i += __n; return *this;}
981 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
982 {return move_iterator(__i - __n);}
983 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
984 {__i -= __n; return *this;}
985 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
987 return static_cast<reference>(__i[__n]);
991 template <class _Iter1, class _Iter2>
992 inline _LIBCPP_INLINE_VISIBILITY
994 operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
996 return __x.base() == __y.base();
999 template <class _Iter1, class _Iter2>
1000 inline _LIBCPP_INLINE_VISIBILITY
1002 operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1004 return __x.base() < __y.base();
1007 template <class _Iter1, class _Iter2>
1008 inline _LIBCPP_INLINE_VISIBILITY
1010 operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1012 return __x.base() != __y.base();
1015 template <class _Iter1, class _Iter2>
1016 inline _LIBCPP_INLINE_VISIBILITY
1018 operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1020 return __x.base() > __y.base();
1023 template <class _Iter1, class _Iter2>
1024 inline _LIBCPP_INLINE_VISIBILITY
1026 operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1028 return __x.base() >= __y.base();
1031 template <class _Iter1, class _Iter2>
1032 inline _LIBCPP_INLINE_VISIBILITY
1034 operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1036 return __x.base() <= __y.base();
1039 template <class _Iter1, class _Iter2>
1040 inline _LIBCPP_INLINE_VISIBILITY
1041 typename move_iterator<_Iter1>::difference_type
1042 operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1044 return __x.base() - __y.base();
1047 template <class _Iter>
1048 inline _LIBCPP_INLINE_VISIBILITY
1049 move_iterator<_Iter>
1050 operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1052 return move_iterator<_Iter>(__x.base() + __n);
1055 template <class _Iter>
1056 inline _LIBCPP_INLINE_VISIBILITY
1057 move_iterator<_Iter>
1058 make_move_iterator(_Iter __i)
1060 return move_iterator<_Iter>(__i);
1065 template <class _Iter> class __wrap_iter;
1067 template <class _Iter1, class _Iter2>
1068 _LIBCPP_INLINE_VISIBILITY
1070 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1072 template <class _Iter1, class _Iter2>
1073 _LIBCPP_INLINE_VISIBILITY
1075 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1077 template <class _Iter1, class _Iter2>
1078 _LIBCPP_INLINE_VISIBILITY
1080 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1082 template <class _Iter1, class _Iter2>
1083 _LIBCPP_INLINE_VISIBILITY
1085 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1087 template <class _Iter1, class _Iter2>
1088 _LIBCPP_INLINE_VISIBILITY
1090 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1092 template <class _Iter1, class _Iter2>
1093 _LIBCPP_INLINE_VISIBILITY
1095 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1097 template <class _Iter1, class _Iter2>
1098 _LIBCPP_INLINE_VISIBILITY
1099 typename __wrap_iter<_Iter1>::difference_type
1100 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1102 template <class _Iter>
1103 _LIBCPP_INLINE_VISIBILITY
1105 operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
1107 template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1108 template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1109 template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1110 template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
1112 template <class _Tp>
1113 _LIBCPP_INLINE_VISIBILITY
1116 is_trivially_copy_assignable<_Tp>::value,
1119 __unwrap_iter(__wrap_iter<_Tp*>);
1121 template <class _Iter>
1125 typedef _Iter iterator_type;
1126 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1127 typedef typename iterator_traits<iterator_type>::value_type value_type;
1128 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1129 typedef typename iterator_traits<iterator_type>::pointer pointer;
1130 typedef typename iterator_traits<iterator_type>::reference reference;
1134 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
1135 #if _LIBCPP_STD_VER > 11
1139 #if _LIBCPP_DEBUG_LEVEL >= 2
1140 __get_db()->__insert_i(this);
1143 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
1144 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
1147 #if _LIBCPP_DEBUG_LEVEL >= 2
1148 __get_db()->__iterator_copy(this, &__u);
1151 #if _LIBCPP_DEBUG_LEVEL >= 2
1152 _LIBCPP_INLINE_VISIBILITY
1153 __wrap_iter(const __wrap_iter& __x)
1156 __get_db()->__iterator_copy(this, &__x);
1158 _LIBCPP_INLINE_VISIBILITY
1159 __wrap_iter& operator=(const __wrap_iter& __x)
1163 __get_db()->__iterator_copy(this, &__x);
1168 _LIBCPP_INLINE_VISIBILITY
1171 __get_db()->__erase_i(this);
1174 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1176 #if _LIBCPP_DEBUG_LEVEL >= 2
1177 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1178 "Attempted to dereference a non-dereferenceable iterator");
1182 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1184 #if _LIBCPP_DEBUG_LEVEL >= 2
1185 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1186 "Attempted to dereference a non-dereferenceable iterator");
1188 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
1190 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1192 #if _LIBCPP_DEBUG_LEVEL >= 2
1193 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1194 "Attempted to increment non-incrementable iterator");
1199 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
1200 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1201 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1203 #if _LIBCPP_DEBUG_LEVEL >= 2
1204 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1205 "Attempted to decrement non-decrementable iterator");
1210 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
1211 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
1212 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
1213 {__wrap_iter __w(*this); __w += __n; return __w;}
1214 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1216 #if _LIBCPP_DEBUG_LEVEL >= 2
1217 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1218 "Attempted to add/subtract iterator outside of valid range");
1223 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
1224 {return *this + (-__n);}
1225 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1226 {*this += -__n; return *this;}
1227 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
1229 #if _LIBCPP_DEBUG_LEVEL >= 2
1230 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1231 "Attempted to subscript iterator outside of valid range");
1236 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
1239 #if _LIBCPP_DEBUG_LEVEL >= 2
1240 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1242 __get_db()->__insert_ic(this, __p);
1245 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1248 template <class _Up> friend class __wrap_iter;
1249 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1250 template <class _Tp, class _Alloc> friend class _LIBCPP_TYPE_VIS_ONLY vector;
1252 template <class _Iter1, class _Iter2>
1255 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1257 template <class _Iter1, class _Iter2>
1260 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1262 template <class _Iter1, class _Iter2>
1265 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1267 template <class _Iter1, class _Iter2>
1270 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1272 template <class _Iter1, class _Iter2>
1275 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1277 template <class _Iter1, class _Iter2>
1280 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1282 template <class _Iter1, class _Iter2>
1284 typename __wrap_iter<_Iter1>::difference_type
1285 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1287 template <class _Iter1>
1290 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
1292 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
1293 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
1294 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
1295 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1297 template <class _Tp>
1301 is_trivially_copy_assignable<_Tp>::value,
1304 __unwrap_iter(__wrap_iter<_Tp*>);
1307 template <class _Iter1, class _Iter2>
1308 inline _LIBCPP_INLINE_VISIBILITY
1310 operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1312 return __x.base() == __y.base();
1315 template <class _Iter1, class _Iter2>
1316 inline _LIBCPP_INLINE_VISIBILITY
1318 operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1320 #if _LIBCPP_DEBUG_LEVEL >= 2
1321 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1322 "Attempted to compare incomparable iterators");
1324 return __x.base() < __y.base();
1327 template <class _Iter1, class _Iter2>
1328 inline _LIBCPP_INLINE_VISIBILITY
1330 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1332 return !(__x == __y);
1335 template <class _Iter1, class _Iter2>
1336 inline _LIBCPP_INLINE_VISIBILITY
1338 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1343 template <class _Iter1, class _Iter2>
1344 inline _LIBCPP_INLINE_VISIBILITY
1346 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1348 return !(__x < __y);
1351 template <class _Iter1, class _Iter2>
1352 inline _LIBCPP_INLINE_VISIBILITY
1354 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1356 return !(__y < __x);
1359 template <class _Iter1>
1360 inline _LIBCPP_INLINE_VISIBILITY
1362 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1364 return !(__x == __y);
1367 template <class _Iter1>
1368 inline _LIBCPP_INLINE_VISIBILITY
1370 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1375 template <class _Iter1>
1376 inline _LIBCPP_INLINE_VISIBILITY
1378 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1380 return !(__x < __y);
1383 template <class _Iter1>
1384 inline _LIBCPP_INLINE_VISIBILITY
1386 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1388 return !(__y < __x);
1391 template <class _Iter1, class _Iter2>
1392 inline _LIBCPP_INLINE_VISIBILITY
1393 typename __wrap_iter<_Iter1>::difference_type
1394 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1396 #if _LIBCPP_DEBUG_LEVEL >= 2
1397 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1398 "Attempted to subtract incompatible iterators");
1400 return __x.base() - __y.base();
1403 template <class _Iter>
1404 inline _LIBCPP_INLINE_VISIBILITY
1406 operator+(typename __wrap_iter<_Iter>::difference_type __n,
1407 __wrap_iter<_Iter> __x) _NOEXCEPT
1413 template <class _Iter>
1414 struct __libcpp_is_trivial_iterator
1415 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1417 template <class _Iter>
1418 struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
1419 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1421 template <class _Iter>
1422 struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
1423 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1425 template <class _Iter>
1426 struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
1427 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1430 template <class _Tp, size_t _Np>
1431 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1433 begin(_Tp (&__array)[_Np])
1438 template <class _Tp, size_t _Np>
1439 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1441 end(_Tp (&__array)[_Np])
1443 return __array + _Np;
1446 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1448 template <class _Cp>
1449 inline _LIBCPP_INLINE_VISIBILITY
1451 begin(_Cp& __c) -> decltype(__c.begin())
1456 template <class _Cp>
1457 inline _LIBCPP_INLINE_VISIBILITY
1459 begin(const _Cp& __c) -> decltype(__c.begin())
1464 template <class _Cp>
1465 inline _LIBCPP_INLINE_VISIBILITY
1467 end(_Cp& __c) -> decltype(__c.end())
1472 template <class _Cp>
1473 inline _LIBCPP_INLINE_VISIBILITY
1475 end(const _Cp& __c) -> decltype(__c.end())
1480 #if _LIBCPP_STD_VER > 11
1482 template <class _Tp, size_t _Np>
1483 inline _LIBCPP_INLINE_VISIBILITY
1484 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1486 return reverse_iterator<_Tp*>(__array + _Np);
1489 template <class _Tp, size_t _Np>
1490 inline _LIBCPP_INLINE_VISIBILITY
1491 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1493 return reverse_iterator<_Tp*>(__array);
1496 template <class _Ep>
1497 inline _LIBCPP_INLINE_VISIBILITY
1498 reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1500 return reverse_iterator<const _Ep*>(__il.end());
1503 template <class _Ep>
1504 inline _LIBCPP_INLINE_VISIBILITY
1505 reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1507 return reverse_iterator<const _Ep*>(__il.begin());
1510 template <class _Cp>
1511 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1512 auto cbegin(const _Cp& __c) -> decltype(begin(__c))
1517 template <class _Cp>
1518 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1519 auto cend(const _Cp& __c) -> decltype(end(__c))
1524 template <class _Cp>
1525 inline _LIBCPP_INLINE_VISIBILITY
1526 auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1528 return __c.rbegin();
1531 template <class _Cp>
1532 inline _LIBCPP_INLINE_VISIBILITY
1533 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1535 return __c.rbegin();
1538 template <class _Cp>
1539 inline _LIBCPP_INLINE_VISIBILITY
1540 auto rend(_Cp& __c) -> decltype(__c.rend())
1545 template <class _Cp>
1546 inline _LIBCPP_INLINE_VISIBILITY
1547 auto rend(const _Cp& __c) -> decltype(__c.rend())
1552 template <class _Cp>
1553 inline _LIBCPP_INLINE_VISIBILITY
1554 auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
1559 template <class _Cp>
1560 inline _LIBCPP_INLINE_VISIBILITY
1561 auto crend(const _Cp& __c) -> decltype(rend(__c))
1569 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1571 template <class _Cp>
1572 inline _LIBCPP_INLINE_VISIBILITY
1573 typename _Cp::iterator
1579 template <class _Cp>
1580 inline _LIBCPP_INLINE_VISIBILITY
1581 typename _Cp::const_iterator
1582 begin(const _Cp& __c)
1587 template <class _Cp>
1588 inline _LIBCPP_INLINE_VISIBILITY
1589 typename _Cp::iterator
1595 template <class _Cp>
1596 inline _LIBCPP_INLINE_VISIBILITY
1597 typename _Cp::const_iterator
1603 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1605 #if _LIBCPP_STD_VER > 14
1606 template <class _Cont>
1607 constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
1609 template <class _Tp, size_t _Sz>
1610 constexpr size_t size(const _Tp (&__array)[_Sz]) noexcept { return _Sz; }
1612 template <class _Cont>
1613 constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
1615 template <class _Tp, size_t _Sz>
1616 constexpr bool empty(const _Tp (&__array)[_Sz]) noexcept { return false; }
1618 template <class _Ep>
1619 constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1621 template <class _Cont> constexpr
1622 auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
1624 template <class _Cont> constexpr
1625 auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
1627 template <class _Tp, size_t _Sz>
1628 constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1630 template <class _Ep>
1631 constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1635 _LIBCPP_END_NAMESPACE_STD
1637 #endif // _LIBCPP_ITERATOR