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;
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
332 #include <__functional_base>
333 #include <type_traits>
336 #include <initializer_list>
338 #include <Availability.h>
343 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
344 #pragma GCC system_header
347 _LIBCPP_BEGIN_NAMESPACE_STD
349 struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
350 struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
351 struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
352 struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
353 struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
356 struct __has_iterator_category
359 struct __two {char __lx; char __lxx;};
360 template <class _Up> static __two __test(...);
361 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
363 static const bool value = sizeof(__test<_Tp>(0)) == 1;
366 template <class _Iter, bool> struct __iterator_traits_impl {};
368 template <class _Iter>
369 struct __iterator_traits_impl<_Iter, true>
371 typedef typename _Iter::difference_type difference_type;
372 typedef typename _Iter::value_type value_type;
373 typedef typename _Iter::pointer pointer;
374 typedef typename _Iter::reference reference;
375 typedef typename _Iter::iterator_category iterator_category;
378 template <class _Iter, bool> struct __iterator_traits {};
380 template <class _Iter>
381 struct __iterator_traits<_Iter, true>
382 : __iterator_traits_impl
385 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
386 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
390 // iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
391 // exists. Else iterator_traits<Iterator> will be an empty class. This is a
392 // conforming extension which allows some programs to compile and behave as
393 // the client expects instead of failing at compile time.
395 template <class _Iter>
396 struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
397 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
400 struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
402 typedef ptrdiff_t difference_type;
403 typedef typename remove_const<_Tp>::type value_type;
404 typedef _Tp* pointer;
405 typedef _Tp& reference;
406 typedef random_access_iterator_tag iterator_category;
409 template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
410 struct __has_iterator_category_convertible_to
411 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
414 template <class _Tp, class _Up>
415 struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
418 struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
421 struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
424 struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
427 struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
429 template<class _Category, class _Tp, class _Distance = ptrdiff_t,
430 class _Pointer = _Tp*, class _Reference = _Tp&>
431 struct _LIBCPP_TYPE_VIS_ONLY iterator
433 typedef _Tp value_type;
434 typedef _Distance difference_type;
435 typedef _Pointer pointer;
436 typedef _Reference reference;
437 typedef _Category iterator_category;
440 template <class _InputIter>
441 inline _LIBCPP_INLINE_VISIBILITY
442 void __advance(_InputIter& __i,
443 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
445 for (; __n > 0; --__n)
449 template <class _BiDirIter>
450 inline _LIBCPP_INLINE_VISIBILITY
451 void __advance(_BiDirIter& __i,
452 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
455 for (; __n > 0; --__n)
458 for (; __n < 0; ++__n)
462 template <class _RandIter>
463 inline _LIBCPP_INLINE_VISIBILITY
464 void __advance(_RandIter& __i,
465 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
470 template <class _InputIter>
471 inline _LIBCPP_INLINE_VISIBILITY
472 void advance(_InputIter& __i,
473 typename iterator_traits<_InputIter>::difference_type __n)
475 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
478 template <class _InputIter>
479 inline _LIBCPP_INLINE_VISIBILITY
480 typename iterator_traits<_InputIter>::difference_type
481 __distance(_InputIter __first, _InputIter __last, input_iterator_tag)
483 typename iterator_traits<_InputIter>::difference_type __r(0);
484 for (; __first != __last; ++__first)
489 template <class _RandIter>
490 inline _LIBCPP_INLINE_VISIBILITY
491 typename iterator_traits<_RandIter>::difference_type
492 __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
494 return __last - __first;
497 template <class _InputIter>
498 inline _LIBCPP_INLINE_VISIBILITY
499 typename iterator_traits<_InputIter>::difference_type
500 distance(_InputIter __first, _InputIter __last)
502 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
505 template <class _ForwardIter>
506 inline _LIBCPP_INLINE_VISIBILITY
508 next(_ForwardIter __x,
509 typename iterator_traits<_ForwardIter>::difference_type __n = 1,
510 typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
512 _VSTD::advance(__x, __n);
516 template <class _BidiretionalIter>
517 inline _LIBCPP_INLINE_VISIBILITY
519 prev(_BidiretionalIter __x,
520 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
521 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
523 _VSTD::advance(__x, -__n);
527 template <class _Iter>
528 class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
529 : public iterator<typename iterator_traits<_Iter>::iterator_category,
530 typename iterator_traits<_Iter>::value_type,
531 typename iterator_traits<_Iter>::difference_type,
532 typename iterator_traits<_Iter>::pointer,
533 typename iterator_traits<_Iter>::reference>
536 mutable _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
540 typedef _Iter iterator_type;
541 typedef typename iterator_traits<_Iter>::difference_type difference_type;
542 typedef typename iterator_traits<_Iter>::reference reference;
543 typedef typename iterator_traits<_Iter>::pointer pointer;
545 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
546 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
547 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
548 : __t(__u.base()), current(__u.base()) {}
549 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
550 _LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;}
551 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());}
552 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
553 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
554 {reverse_iterator __tmp(*this); --current; return __tmp;}
555 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
556 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
557 {reverse_iterator __tmp(*this); ++current; return __tmp;}
558 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
559 {return reverse_iterator(current - __n);}
560 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
561 {current -= __n; return *this;}
562 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
563 {return reverse_iterator(current + __n);}
564 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
565 {current += __n; return *this;}
566 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
567 {return current[-__n-1];}
570 template <class _Iter1, class _Iter2>
571 inline _LIBCPP_INLINE_VISIBILITY
573 operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
575 return __x.base() == __y.base();
578 template <class _Iter1, class _Iter2>
579 inline _LIBCPP_INLINE_VISIBILITY
581 operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
583 return __x.base() > __y.base();
586 template <class _Iter1, class _Iter2>
587 inline _LIBCPP_INLINE_VISIBILITY
589 operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
591 return __x.base() != __y.base();
594 template <class _Iter1, class _Iter2>
595 inline _LIBCPP_INLINE_VISIBILITY
597 operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
599 return __x.base() < __y.base();
602 template <class _Iter1, class _Iter2>
603 inline _LIBCPP_INLINE_VISIBILITY
605 operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
607 return __x.base() <= __y.base();
610 template <class _Iter1, class _Iter2>
611 inline _LIBCPP_INLINE_VISIBILITY
613 operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
615 return __x.base() >= __y.base();
618 template <class _Iter1, class _Iter2>
619 inline _LIBCPP_INLINE_VISIBILITY
620 typename reverse_iterator<_Iter1>::difference_type
621 operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
623 return __y.base() - __x.base();
626 template <class _Iter>
627 inline _LIBCPP_INLINE_VISIBILITY
628 reverse_iterator<_Iter>
629 operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
631 return reverse_iterator<_Iter>(__x.base() - __n);
634 #if _LIBCPP_STD_VER > 11
635 template <class _Iter>
636 inline _LIBCPP_INLINE_VISIBILITY
637 reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
639 return reverse_iterator<_Iter>(__i);
643 template <class _Container>
644 class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
645 : public iterator<output_iterator_tag,
649 back_insert_iterator<_Container>&>
652 _Container* container;
654 typedef _Container container_type;
656 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
657 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
658 {container->push_back(__value_); return *this;}
659 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
660 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
661 {container->push_back(_VSTD::move(__value_)); return *this;}
662 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
663 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
664 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
665 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
668 template <class _Container>
669 inline _LIBCPP_INLINE_VISIBILITY
670 back_insert_iterator<_Container>
671 back_inserter(_Container& __x)
673 return back_insert_iterator<_Container>(__x);
676 template <class _Container>
677 class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
678 : public iterator<output_iterator_tag,
682 front_insert_iterator<_Container>&>
685 _Container* container;
687 typedef _Container container_type;
689 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
690 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
691 {container->push_front(__value_); return *this;}
692 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
693 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
694 {container->push_front(_VSTD::move(__value_)); return *this;}
695 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
696 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
697 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
698 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
701 template <class _Container>
702 inline _LIBCPP_INLINE_VISIBILITY
703 front_insert_iterator<_Container>
704 front_inserter(_Container& __x)
706 return front_insert_iterator<_Container>(__x);
709 template <class _Container>
710 class _LIBCPP_TYPE_VIS_ONLY insert_iterator
711 : public iterator<output_iterator_tag,
715 insert_iterator<_Container>&>
718 _Container* container;
719 typename _Container::iterator iter;
721 typedef _Container container_type;
723 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
724 : container(_VSTD::addressof(__x)), iter(__i) {}
725 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
726 {iter = container->insert(iter, __value_); ++iter; return *this;}
727 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
728 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
729 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
730 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
731 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
732 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
733 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
736 template <class _Container>
737 inline _LIBCPP_INLINE_VISIBILITY
738 insert_iterator<_Container>
739 inserter(_Container& __x, typename _Container::iterator __i)
741 return insert_iterator<_Container>(__x, __i);
744 template <class _Tp, class _CharT = char,
745 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
746 class _LIBCPP_TYPE_VIS_ONLY istream_iterator
747 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
750 typedef _CharT char_type;
751 typedef _Traits traits_type;
752 typedef basic_istream<_CharT,_Traits> istream_type;
754 istream_type* __in_stream_;
757 _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {}
758 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
760 if (!(*__in_stream_ >> __value_))
764 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
765 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
766 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
768 if (!(*__in_stream_ >> __value_))
772 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
773 {istream_iterator __t(*this); ++(*this); return __t;}
775 friend _LIBCPP_INLINE_VISIBILITY
776 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
777 {return __x.__in_stream_ == __y.__in_stream_;}
779 friend _LIBCPP_INLINE_VISIBILITY
780 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
781 {return !(__x == __y);}
784 template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
785 class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
786 : public iterator<output_iterator_tag, void, void, void, void>
789 typedef _CharT char_type;
790 typedef _Traits traits_type;
791 typedef basic_ostream<_CharT,_Traits> ostream_type;
793 ostream_type* __out_stream_;
794 const char_type* __delim_;
796 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
797 : __out_stream_(&__s), __delim_(0) {}
798 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
799 : __out_stream_(&__s), __delim_(__delimiter) {}
800 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
802 *__out_stream_ << __value_;
804 *__out_stream_ << __delim_;
808 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
809 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
810 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
813 template<class _CharT, class _Traits>
814 class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
815 : public iterator<input_iterator_tag, _CharT,
816 typename _Traits::off_type, _CharT*,
820 typedef _CharT char_type;
821 typedef _Traits traits_type;
822 typedef typename _Traits::int_type int_type;
823 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
824 typedef basic_istream<_CharT,_Traits> istream_type;
826 mutable streambuf_type* __sbuf_;
831 streambuf_type* __sbuf_;
832 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
833 : __keep_(__c), __sbuf_(__s) {}
834 friend class istreambuf_iterator;
836 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
839 _LIBCPP_INLINE_VISIBILITY
840 bool __test_for_eof() const
842 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
847 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
848 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
849 : __sbuf_(__s.rdbuf()) {}
850 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
852 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
853 : __sbuf_(__p.__sbuf_) {}
855 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
856 {return static_cast<char_type>(__sbuf_->sgetc());}
857 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
858 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
863 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
865 return __proxy(__sbuf_->sbumpc(), __sbuf_);
868 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
869 {return __test_for_eof() == __b.__test_for_eof();}
872 template <class _CharT, class _Traits>
873 inline _LIBCPP_INLINE_VISIBILITY
874 bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
875 const istreambuf_iterator<_CharT,_Traits>& __b)
876 {return __a.equal(__b);}
878 template <class _CharT, class _Traits>
879 inline _LIBCPP_INLINE_VISIBILITY
880 bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
881 const istreambuf_iterator<_CharT,_Traits>& __b)
882 {return !__a.equal(__b);}
884 template <class _CharT, class _Traits>
885 class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
886 : public iterator<output_iterator_tag, void, void, void, void>
889 typedef _CharT char_type;
890 typedef _Traits traits_type;
891 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
892 typedef basic_ostream<_CharT,_Traits> ostream_type;
894 streambuf_type* __sbuf_;
896 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
897 : __sbuf_(__s.rdbuf()) {}
898 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
900 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
902 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
906 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
907 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
908 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
909 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
911 #if !defined(__APPLE__) || \
912 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
913 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
915 template <class _Ch, class _Tr>
918 ostreambuf_iterator<_Ch, _Tr>
919 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
920 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
921 ios_base& __iob, _Ch __fl);
925 template <class _Iter>
926 class _LIBCPP_TYPE_VIS_ONLY move_iterator
931 typedef _Iter iterator_type;
932 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
933 typedef typename iterator_traits<iterator_type>::value_type value_type;
934 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
935 typedef typename iterator_traits<iterator_type>::pointer pointer;
936 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
937 typedef value_type&& reference;
939 typedef typename iterator_traits<iterator_type>::reference reference;
942 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
943 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
944 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
946 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
947 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
948 return static_cast<reference>(*__i);
950 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
951 typename iterator_traits<iterator_type>::reference __ref = *__i;
954 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
955 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
956 {move_iterator __tmp(*this); ++__i; return __tmp;}
957 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
958 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
959 {move_iterator __tmp(*this); --__i; return __tmp;}
960 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
961 {return move_iterator(__i + __n);}
962 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
963 {__i += __n; return *this;}
964 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
965 {return move_iterator(__i - __n);}
966 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
967 {__i -= __n; return *this;}
968 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
970 return static_cast<reference>(__i[__n]);
974 template <class _Iter1, class _Iter2>
975 inline _LIBCPP_INLINE_VISIBILITY
977 operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
979 return __x.base() == __y.base();
982 template <class _Iter1, class _Iter2>
983 inline _LIBCPP_INLINE_VISIBILITY
985 operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
987 return __x.base() < __y.base();
990 template <class _Iter1, class _Iter2>
991 inline _LIBCPP_INLINE_VISIBILITY
993 operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
995 return __x.base() != __y.base();
998 template <class _Iter1, class _Iter2>
999 inline _LIBCPP_INLINE_VISIBILITY
1001 operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1003 return __x.base() > __y.base();
1006 template <class _Iter1, class _Iter2>
1007 inline _LIBCPP_INLINE_VISIBILITY
1009 operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1011 return __x.base() >= __y.base();
1014 template <class _Iter1, class _Iter2>
1015 inline _LIBCPP_INLINE_VISIBILITY
1017 operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1019 return __x.base() <= __y.base();
1022 template <class _Iter1, class _Iter2>
1023 inline _LIBCPP_INLINE_VISIBILITY
1024 typename move_iterator<_Iter1>::difference_type
1025 operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1027 return __x.base() - __y.base();
1030 template <class _Iter>
1031 inline _LIBCPP_INLINE_VISIBILITY
1032 move_iterator<_Iter>
1033 operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1035 return move_iterator<_Iter>(__x.base() + __n);
1038 template <class _Iter>
1039 inline _LIBCPP_INLINE_VISIBILITY
1040 move_iterator<_Iter>
1041 make_move_iterator(_Iter __i)
1043 return move_iterator<_Iter>(__i);
1048 template <class _Iter> class __wrap_iter;
1050 template <class _Iter1, class _Iter2>
1051 _LIBCPP_INLINE_VISIBILITY
1053 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1055 template <class _Iter1, class _Iter2>
1056 _LIBCPP_INLINE_VISIBILITY
1058 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1060 template <class _Iter1, class _Iter2>
1061 _LIBCPP_INLINE_VISIBILITY
1063 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1065 template <class _Iter1, class _Iter2>
1066 _LIBCPP_INLINE_VISIBILITY
1068 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1070 template <class _Iter1, class _Iter2>
1071 _LIBCPP_INLINE_VISIBILITY
1073 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1075 template <class _Iter1, class _Iter2>
1076 _LIBCPP_INLINE_VISIBILITY
1078 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1080 template <class _Iter1, class _Iter2>
1081 _LIBCPP_INLINE_VISIBILITY
1082 typename __wrap_iter<_Iter1>::difference_type
1083 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1085 template <class _Iter>
1086 _LIBCPP_INLINE_VISIBILITY
1088 operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
1090 template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1091 template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1092 template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1093 template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
1095 template <class _Tp>
1096 _LIBCPP_INLINE_VISIBILITY
1099 is_trivially_copy_assignable<_Tp>::value,
1102 __unwrap_iter(__wrap_iter<_Tp*>);
1104 template <class _Iter>
1108 typedef _Iter iterator_type;
1109 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1110 typedef typename iterator_traits<iterator_type>::value_type value_type;
1111 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1112 typedef typename iterator_traits<iterator_type>::pointer pointer;
1113 typedef typename iterator_traits<iterator_type>::reference reference;
1117 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
1118 #if _LIBCPP_STD_VER > 11
1122 #if _LIBCPP_DEBUG_LEVEL >= 2
1123 __get_db()->__insert_i(this);
1126 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
1127 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
1130 #if _LIBCPP_DEBUG_LEVEL >= 2
1131 __get_db()->__iterator_copy(this, &__u);
1134 #if _LIBCPP_DEBUG_LEVEL >= 2
1135 _LIBCPP_INLINE_VISIBILITY
1136 __wrap_iter(const __wrap_iter& __x)
1139 __get_db()->__iterator_copy(this, &__x);
1141 _LIBCPP_INLINE_VISIBILITY
1142 __wrap_iter& operator=(const __wrap_iter& __x)
1146 __get_db()->__iterator_copy(this, &__x);
1151 _LIBCPP_INLINE_VISIBILITY
1154 __get_db()->__erase_i(this);
1157 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1159 #if _LIBCPP_DEBUG_LEVEL >= 2
1160 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1161 "Attempted to dereference a non-dereferenceable iterator");
1165 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1167 #if _LIBCPP_DEBUG_LEVEL >= 2
1168 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1169 "Attempted to dereference a non-dereferenceable iterator");
1171 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
1173 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1175 #if _LIBCPP_DEBUG_LEVEL >= 2
1176 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1177 "Attempted to increment non-incrementable iterator");
1182 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
1183 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1184 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1186 #if _LIBCPP_DEBUG_LEVEL >= 2
1187 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1188 "Attempted to decrement non-decrementable iterator");
1193 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
1194 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
1195 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
1196 {__wrap_iter __w(*this); __w += __n; return __w;}
1197 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1199 #if _LIBCPP_DEBUG_LEVEL >= 2
1200 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1201 "Attempted to add/subtract iterator outside of valid range");
1206 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
1207 {return *this + (-__n);}
1208 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1209 {*this += -__n; return *this;}
1210 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
1212 #if _LIBCPP_DEBUG_LEVEL >= 2
1213 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1214 "Attempted to subscript iterator outside of valid range");
1219 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
1222 #if _LIBCPP_DEBUG_LEVEL >= 2
1223 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1225 __get_db()->__insert_ic(this, __p);
1228 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1231 template <class _Up> friend class __wrap_iter;
1232 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1233 template <class _Tp, class _Alloc> friend class vector;
1235 template <class _Iter1, class _Iter2>
1238 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1240 template <class _Iter1, class _Iter2>
1243 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1245 template <class _Iter1, class _Iter2>
1248 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1250 template <class _Iter1, class _Iter2>
1253 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1255 template <class _Iter1, class _Iter2>
1258 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1260 template <class _Iter1, class _Iter2>
1263 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1265 template <class _Iter1, class _Iter2>
1267 typename __wrap_iter<_Iter1>::difference_type
1268 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1270 template <class _Iter1>
1273 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
1275 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
1276 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
1277 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
1278 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1280 template <class _Tp>
1284 is_trivially_copy_assignable<_Tp>::value,
1287 __unwrap_iter(__wrap_iter<_Tp*>);
1290 template <class _Iter1, class _Iter2>
1291 inline _LIBCPP_INLINE_VISIBILITY
1293 operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1295 return __x.base() == __y.base();
1298 template <class _Iter1, class _Iter2>
1299 inline _LIBCPP_INLINE_VISIBILITY
1301 operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1303 #if _LIBCPP_DEBUG_LEVEL >= 2
1304 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1305 "Attempted to compare incomparable iterators");
1307 return __x.base() < __y.base();
1310 template <class _Iter1, class _Iter2>
1311 inline _LIBCPP_INLINE_VISIBILITY
1313 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1315 return !(__x == __y);
1318 template <class _Iter1, class _Iter2>
1319 inline _LIBCPP_INLINE_VISIBILITY
1321 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1326 template <class _Iter1, class _Iter2>
1327 inline _LIBCPP_INLINE_VISIBILITY
1329 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1331 return !(__x < __y);
1334 template <class _Iter1, class _Iter2>
1335 inline _LIBCPP_INLINE_VISIBILITY
1337 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1339 return !(__y < __x);
1342 template <class _Iter1>
1343 inline _LIBCPP_INLINE_VISIBILITY
1345 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1347 return !(__x == __y);
1350 template <class _Iter1>
1351 inline _LIBCPP_INLINE_VISIBILITY
1353 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1358 template <class _Iter1>
1359 inline _LIBCPP_INLINE_VISIBILITY
1361 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1363 return !(__x < __y);
1366 template <class _Iter1>
1367 inline _LIBCPP_INLINE_VISIBILITY
1369 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1371 return !(__y < __x);
1374 template <class _Iter1, class _Iter2>
1375 inline _LIBCPP_INLINE_VISIBILITY
1376 typename __wrap_iter<_Iter1>::difference_type
1377 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1379 #if _LIBCPP_DEBUG_LEVEL >= 2
1380 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1381 "Attempted to subtract incompatible iterators");
1383 return __x.base() - __y.base();
1386 template <class _Iter>
1387 inline _LIBCPP_INLINE_VISIBILITY
1389 operator+(typename __wrap_iter<_Iter>::difference_type __n,
1390 __wrap_iter<_Iter> __x) _NOEXCEPT
1396 template <class _Tp, size_t _Np>
1397 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1399 begin(_Tp (&__array)[_Np])
1404 template <class _Tp, size_t _Np>
1405 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1407 end(_Tp (&__array)[_Np])
1409 return __array + _Np;
1412 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1414 template <class _Cp>
1415 inline _LIBCPP_INLINE_VISIBILITY
1417 begin(_Cp& __c) -> decltype(__c.begin())
1422 template <class _Cp>
1423 inline _LIBCPP_INLINE_VISIBILITY
1425 begin(const _Cp& __c) -> decltype(__c.begin())
1430 template <class _Cp>
1431 inline _LIBCPP_INLINE_VISIBILITY
1433 end(_Cp& __c) -> decltype(__c.end())
1438 template <class _Cp>
1439 inline _LIBCPP_INLINE_VISIBILITY
1441 end(const _Cp& __c) -> decltype(__c.end())
1446 #if _LIBCPP_STD_VER > 11
1448 template <class _Tp, size_t _Np>
1449 inline _LIBCPP_INLINE_VISIBILITY
1450 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1452 return reverse_iterator<_Tp*>(__array + _Np);
1455 template <class _Tp, size_t _Np>
1456 inline _LIBCPP_INLINE_VISIBILITY
1457 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1459 return reverse_iterator<_Tp*>(__array);
1462 template <class _Ep>
1463 inline _LIBCPP_INLINE_VISIBILITY
1464 reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1466 return reverse_iterator<const _Ep*>(__il.end());
1469 template <class _Ep>
1470 inline _LIBCPP_INLINE_VISIBILITY
1471 reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1473 return reverse_iterator<const _Ep*>(__il.begin());
1476 template <class _Cp>
1477 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1478 auto cbegin(const _Cp& __c) -> decltype(begin(__c))
1483 template <class _Cp>
1484 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1485 auto cend(const _Cp& __c) -> decltype(end(__c))
1490 template <class _Cp>
1491 inline _LIBCPP_INLINE_VISIBILITY
1492 auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1494 return __c.rbegin();
1497 template <class _Cp>
1498 inline _LIBCPP_INLINE_VISIBILITY
1499 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1501 return __c.rbegin();
1504 template <class _Cp>
1505 inline _LIBCPP_INLINE_VISIBILITY
1506 auto rend(_Cp& __c) -> decltype(__c.rend())
1511 template <class _Cp>
1512 inline _LIBCPP_INLINE_VISIBILITY
1513 auto rend(const _Cp& __c) -> decltype(__c.rend())
1518 template <class _Cp>
1519 inline _LIBCPP_INLINE_VISIBILITY
1520 auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
1525 template <class _Cp>
1526 inline _LIBCPP_INLINE_VISIBILITY
1527 auto crend(const _Cp& __c) -> decltype(rend(__c))
1535 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1537 template <class _Cp>
1538 inline _LIBCPP_INLINE_VISIBILITY
1539 typename _Cp::iterator
1545 template <class _Cp>
1546 inline _LIBCPP_INLINE_VISIBILITY
1547 typename _Cp::const_iterator
1548 begin(const _Cp& __c)
1553 template <class _Cp>
1554 inline _LIBCPP_INLINE_VISIBILITY
1555 typename _Cp::iterator
1561 template <class _Cp>
1562 inline _LIBCPP_INLINE_VISIBILITY
1563 typename _Cp::const_iterator
1569 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1571 _LIBCPP_END_NAMESPACE_STD
1573 #endif // _LIBCPP_ITERATOR