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;
92 constexpr reverse_iterator();
93 constexpr explicit reverse_iterator(Iterator x);
94 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
95 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
96 constexpr Iterator base() const;
97 constexpr reference operator*() const;
98 constexpr pointer operator->() const;
99 constexpr reverse_iterator& operator++();
100 constexpr reverse_iterator operator++(int);
101 constexpr reverse_iterator& operator--();
102 constexpr reverse_iterator operator--(int);
103 constexpr reverse_iterator operator+ (difference_type n) const;
104 constexpr reverse_iterator& operator+=(difference_type n);
105 constexpr reverse_iterator operator- (difference_type n) const;
106 constexpr reverse_iterator& operator-=(difference_type n);
107 constexpr reference operator[](difference_type n) const;
110 template <class Iterator1, class Iterator2>
111 constexpr bool // constexpr in C++17
112 operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
114 template <class Iterator1, class Iterator2>
115 constexpr bool // constexpr in C++17
116 operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
118 template <class Iterator1, class Iterator2>
119 constexpr bool // constexpr in C++17
120 operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
122 template <class Iterator1, class Iterator2>
123 constexpr bool // constexpr in C++17
124 operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
126 template <class Iterator1, class Iterator2>
127 constexpr bool // constexpr in C++17
128 operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
130 template <class Iterator1, class Iterator2>
131 constexpr bool // constexpr in C++17
132 operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
134 template <class Iterator1, class Iterator2>
136 operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
137 -> decltype(__y.base() - __x.base()); // constexpr in C++17
139 template <class Iterator>
140 constexpr reverse_iterator<Iterator>
141 operator+(typename reverse_iterator<Iterator>::difference_type n,
142 const reverse_iterator<Iterator>& x); // constexpr in C++17
144 template <class Iterator>
145 constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
147 template <class Container>
148 class back_insert_iterator
151 Container* container;
153 typedef Container container_type;
154 typedef void value_type;
155 typedef void difference_type;
156 typedef void reference;
157 typedef void pointer;
159 explicit back_insert_iterator(Container& x);
160 back_insert_iterator& operator=(const typename Container::value_type& value);
161 back_insert_iterator& operator*();
162 back_insert_iterator& operator++();
163 back_insert_iterator operator++(int);
166 template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
168 template <class Container>
169 class front_insert_iterator
172 Container* container;
174 typedef Container container_type;
175 typedef void value_type;
176 typedef void difference_type;
177 typedef void reference;
178 typedef void pointer;
180 explicit front_insert_iterator(Container& x);
181 front_insert_iterator& operator=(const typename Container::value_type& value);
182 front_insert_iterator& operator*();
183 front_insert_iterator& operator++();
184 front_insert_iterator operator++(int);
187 template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
189 template <class Container>
190 class insert_iterator
193 Container* container;
194 typename Container::iterator iter;
196 typedef Container container_type;
197 typedef void value_type;
198 typedef void difference_type;
199 typedef void reference;
200 typedef void pointer;
202 insert_iterator(Container& x, typename Container::iterator i);
203 insert_iterator& operator=(const typename Container::value_type& value);
204 insert_iterator& operator*();
205 insert_iterator& operator++();
206 insert_iterator& operator++(int);
209 template <class Container, class Iterator>
210 insert_iterator<Container> inserter(Container& x, Iterator i);
212 template <class Iterator>
213 class move_iterator {
215 typedef Iterator iterator_type;
216 typedef typename iterator_traits<Iterator>::difference_type difference_type;
217 typedef Iterator pointer;
218 typedef typename iterator_traits<Iterator>::value_type value_type;
219 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
220 typedef value_type&& reference;
222 constexpr move_iterator(); // all the constexprs are in C++17
223 constexpr explicit move_iterator(Iterator i);
225 constexpr move_iterator(const move_iterator<U>& u);
227 constexpr move_iterator& operator=(const move_iterator<U>& u);
228 constexpr iterator_type base() const;
229 constexpr reference operator*() const;
230 constexpr pointer operator->() const;
231 constexpr move_iterator& operator++();
232 constexpr move_iterator operator++(int);
233 constexpr move_iterator& operator--();
234 constexpr move_iterator operator--(int);
235 constexpr move_iterator operator+(difference_type n) const;
236 constexpr move_iterator& operator+=(difference_type n);
237 constexpr move_iterator operator-(difference_type n) const;
238 constexpr move_iterator& operator-=(difference_type n);
239 constexpr unspecified operator[](difference_type n) const;
241 Iterator current; // exposition only
244 template <class Iterator1, class Iterator2>
245 constexpr bool // constexpr in C++17
246 operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
248 template <class Iterator1, class Iterator2>
249 constexpr bool // constexpr in C++17
250 operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
252 template <class Iterator1, class Iterator2>
253 constexpr bool // constexpr in C++17
254 operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
256 template <class Iterator1, class Iterator2>
257 constexpr bool // constexpr in C++17
258 operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
260 template <class Iterator1, class Iterator2>
261 constexpr bool // constexpr in C++17
262 operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
264 template <class Iterator1, class Iterator2>
265 constexpr bool // constexpr in C++17
266 operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
268 template <class Iterator1, class Iterator2>
269 constexpr auto // constexpr in C++17
270 operator-(const move_iterator<Iterator1>& x,
271 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
273 template <class Iterator>
274 constexpr move_iterator<Iterator> operator+( // constexpr in C++17
275 typename move_iterator<Iterator>::difference_type n,
276 const move_iterator<Iterator>& x);
278 template <class Iterator> // constexpr in C++17
279 constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
282 template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
283 class istream_iterator
284 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
287 typedef charT char_type;
288 typedef traits traits_type;
289 typedef basic_istream<charT,traits> istream_type;
291 constexpr istream_iterator();
292 istream_iterator(istream_type& s);
293 istream_iterator(const istream_iterator& x);
296 const T& operator*() const;
297 const T* operator->() const;
298 istream_iterator& operator++();
299 istream_iterator operator++(int);
302 template <class T, class charT, class traits, class Distance>
303 bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
304 const istream_iterator<T,charT,traits,Distance>& y);
305 template <class T, class charT, class traits, class Distance>
306 bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
307 const istream_iterator<T,charT,traits,Distance>& y);
309 template <class T, class charT = char, class traits = char_traits<charT> >
310 class ostream_iterator
311 : public iterator<output_iterator_tag, void, void, void ,void>
314 typedef charT char_type;
315 typedef traits traits_type;
316 typedef basic_ostream<charT,traits> ostream_type;
318 ostream_iterator(ostream_type& s);
319 ostream_iterator(ostream_type& s, const charT* delimiter);
320 ostream_iterator(const ostream_iterator& x);
322 ostream_iterator& operator=(const T& value);
324 ostream_iterator& operator*();
325 ostream_iterator& operator++();
326 ostream_iterator& operator++(int);
329 template<class charT, class traits = char_traits<charT> >
330 class istreambuf_iterator
331 : public iterator<input_iterator_tag, charT,
332 typename traits::off_type, unspecified,
336 typedef charT char_type;
337 typedef traits traits_type;
338 typedef typename traits::int_type int_type;
339 typedef basic_streambuf<charT,traits> streambuf_type;
340 typedef basic_istream<charT,traits> istream_type;
342 istreambuf_iterator() noexcept;
343 istreambuf_iterator(istream_type& s) noexcept;
344 istreambuf_iterator(streambuf_type* s) noexcept;
345 istreambuf_iterator(a-private-type) noexcept;
347 charT operator*() const;
348 pointer operator->() const;
349 istreambuf_iterator& operator++();
350 a-private-type operator++(int);
352 bool equal(const istreambuf_iterator& b) const;
355 template <class charT, class traits>
356 bool operator==(const istreambuf_iterator<charT,traits>& a,
357 const istreambuf_iterator<charT,traits>& b);
358 template <class charT, class traits>
359 bool operator!=(const istreambuf_iterator<charT,traits>& a,
360 const istreambuf_iterator<charT,traits>& b);
362 template <class charT, class traits = char_traits<charT> >
363 class ostreambuf_iterator
364 : public iterator<output_iterator_tag, void, void, void, void>
367 typedef charT char_type;
368 typedef traits traits_type;
369 typedef basic_streambuf<charT,traits> streambuf_type;
370 typedef basic_ostream<charT,traits> ostream_type;
372 ostreambuf_iterator(ostream_type& s) noexcept;
373 ostreambuf_iterator(streambuf_type* s) noexcept;
374 ostreambuf_iterator& operator=(charT c);
375 ostreambuf_iterator& operator*();
376 ostreambuf_iterator& operator++();
377 ostreambuf_iterator& operator++(int);
378 bool failed() const noexcept;
381 template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
382 template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
383 template <class C> constexpr auto end(C& c) -> decltype(c.end());
384 template <class C> constexpr auto end(const C& c) -> decltype(c.end());
385 template <class T, size_t N> constexpr T* begin(T (&array)[N]);
386 template <class T, size_t N> constexpr T* end(T (&array)[N]);
388 template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
389 template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
390 template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
391 template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
392 template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
393 template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
394 template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
395 template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
396 template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
397 template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
398 template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
399 template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
401 // 24.8, container access:
402 template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
403 template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
404 template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
405 template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
406 template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
407 template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
408 template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
409 template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
410 template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
417 #include <iosfwd> // for forward declarations of vector and string.
418 #include <__functional_base>
419 #include <type_traits>
421 #include <initializer_list>
423 #include <Availability.h>
428 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
429 #pragma GCC system_header
432 _LIBCPP_BEGIN_NAMESPACE_STD
434 struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
435 struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
436 struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
437 struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
438 struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
441 struct __has_iterator_category
444 struct __two {char __lx; char __lxx;};
445 template <class _Up> static __two __test(...);
446 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
448 static const bool value = sizeof(__test<_Tp>(0)) == 1;
451 template <class _Iter, bool> struct __iterator_traits_impl {};
453 template <class _Iter>
454 struct __iterator_traits_impl<_Iter, true>
456 typedef typename _Iter::difference_type difference_type;
457 typedef typename _Iter::value_type value_type;
458 typedef typename _Iter::pointer pointer;
459 typedef typename _Iter::reference reference;
460 typedef typename _Iter::iterator_category iterator_category;
463 template <class _Iter, bool> struct __iterator_traits {};
465 template <class _Iter>
466 struct __iterator_traits<_Iter, true>
467 : __iterator_traits_impl
470 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
471 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
475 // iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
476 // exists. Else iterator_traits<Iterator> will be an empty class. This is a
477 // conforming extension which allows some programs to compile and behave as
478 // the client expects instead of failing at compile time.
480 template <class _Iter>
481 struct _LIBCPP_TEMPLATE_VIS iterator_traits
482 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
485 struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
487 typedef ptrdiff_t difference_type;
488 typedef typename remove_const<_Tp>::type value_type;
489 typedef _Tp* pointer;
490 typedef _Tp& reference;
491 typedef random_access_iterator_tag iterator_category;
494 template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
495 struct __has_iterator_category_convertible_to
496 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
499 template <class _Tp, class _Up>
500 struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
503 struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
506 struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
509 struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
512 struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
515 struct __is_exactly_input_iterator
516 : public integral_constant<bool,
517 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
518 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
520 template<class _Category, class _Tp, class _Distance = ptrdiff_t,
521 class _Pointer = _Tp*, class _Reference = _Tp&>
522 struct _LIBCPP_TEMPLATE_VIS iterator
524 typedef _Tp value_type;
525 typedef _Distance difference_type;
526 typedef _Pointer pointer;
527 typedef _Reference reference;
528 typedef _Category iterator_category;
531 template <class _InputIter>
532 inline _LIBCPP_INLINE_VISIBILITY
533 void __advance(_InputIter& __i,
534 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
536 for (; __n > 0; --__n)
540 template <class _BiDirIter>
541 inline _LIBCPP_INLINE_VISIBILITY
542 void __advance(_BiDirIter& __i,
543 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
546 for (; __n > 0; --__n)
549 for (; __n < 0; ++__n)
553 template <class _RandIter>
554 inline _LIBCPP_INLINE_VISIBILITY
555 void __advance(_RandIter& __i,
556 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
561 template <class _InputIter>
562 inline _LIBCPP_INLINE_VISIBILITY
563 void advance(_InputIter& __i,
564 typename iterator_traits<_InputIter>::difference_type __n)
566 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
569 template <class _InputIter>
570 inline _LIBCPP_INLINE_VISIBILITY
571 typename iterator_traits<_InputIter>::difference_type
572 __distance(_InputIter __first, _InputIter __last, input_iterator_tag)
574 typename iterator_traits<_InputIter>::difference_type __r(0);
575 for (; __first != __last; ++__first)
580 template <class _RandIter>
581 inline _LIBCPP_INLINE_VISIBILITY
582 typename iterator_traits<_RandIter>::difference_type
583 __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
585 return __last - __first;
588 template <class _InputIter>
589 inline _LIBCPP_INLINE_VISIBILITY
590 typename iterator_traits<_InputIter>::difference_type
591 distance(_InputIter __first, _InputIter __last)
593 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
596 template <class _InputIter>
597 inline _LIBCPP_INLINE_VISIBILITY
600 typename iterator_traits<_InputIter>::difference_type __n = 1,
601 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
603 _VSTD::advance(__x, __n);
607 template <class _BidiretionalIter>
608 inline _LIBCPP_INLINE_VISIBILITY
610 prev(_BidiretionalIter __x,
611 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
612 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
614 _VSTD::advance(__x, -__n);
618 template <class _Iter>
619 class _LIBCPP_TEMPLATE_VIS reverse_iterator
620 : public iterator<typename iterator_traits<_Iter>::iterator_category,
621 typename iterator_traits<_Iter>::value_type,
622 typename iterator_traits<_Iter>::difference_type,
623 typename iterator_traits<_Iter>::pointer,
624 typename iterator_traits<_Iter>::reference>
627 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
631 typedef _Iter iterator_type;
632 typedef typename iterator_traits<_Iter>::difference_type difference_type;
633 typedef typename iterator_traits<_Iter>::reference reference;
634 typedef typename iterator_traits<_Iter>::pointer pointer;
636 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
637 reverse_iterator() : __t(), current() {}
638 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
639 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
642 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
644 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
645 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
646 { __t = current = __u.base(); return *this; }
647 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
648 _Iter base() const {return current;}
649 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
650 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
651 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
652 pointer operator->() const {return _VSTD::addressof(operator*());}
653 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
654 reverse_iterator& operator++() {--current; return *this;}
655 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
656 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
657 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
658 reverse_iterator& operator--() {++current; return *this;}
659 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
660 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
661 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
662 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
663 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
664 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
665 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
666 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
667 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
668 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
669 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
670 reference operator[](difference_type __n) const {return *(*this + __n);}
673 template <class _Iter1, class _Iter2>
674 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
676 operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
678 return __x.base() == __y.base();
681 template <class _Iter1, class _Iter2>
682 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
684 operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
686 return __x.base() > __y.base();
689 template <class _Iter1, class _Iter2>
690 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
692 operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
694 return __x.base() != __y.base();
697 template <class _Iter1, class _Iter2>
698 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
700 operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
702 return __x.base() < __y.base();
705 template <class _Iter1, class _Iter2>
706 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
708 operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
710 return __x.base() <= __y.base();
713 template <class _Iter1, class _Iter2>
714 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
716 operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
718 return __x.base() >= __y.base();
721 #ifndef _LIBCPP_CXX03_LANG
722 template <class _Iter1, class _Iter2>
723 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
725 operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
726 -> decltype(__y.base() - __x.base())
728 return __y.base() - __x.base();
731 template <class _Iter1, class _Iter2>
732 inline _LIBCPP_INLINE_VISIBILITY
733 typename reverse_iterator<_Iter1>::difference_type
734 operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
736 return __y.base() - __x.base();
740 template <class _Iter>
741 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
742 reverse_iterator<_Iter>
743 operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
745 return reverse_iterator<_Iter>(__x.base() - __n);
748 #if _LIBCPP_STD_VER > 11
749 template <class _Iter>
750 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
751 reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
753 return reverse_iterator<_Iter>(__i);
757 template <class _Container>
758 class _LIBCPP_TEMPLATE_VIS back_insert_iterator
759 : public iterator<output_iterator_tag,
766 _Container* container;
768 typedef _Container container_type;
770 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
771 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
772 {container->push_back(__value_); return *this;}
773 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
774 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
775 {container->push_back(_VSTD::move(__value_)); return *this;}
776 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
777 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
778 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
779 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
782 template <class _Container>
783 inline _LIBCPP_INLINE_VISIBILITY
784 back_insert_iterator<_Container>
785 back_inserter(_Container& __x)
787 return back_insert_iterator<_Container>(__x);
790 template <class _Container>
791 class _LIBCPP_TEMPLATE_VIS front_insert_iterator
792 : public iterator<output_iterator_tag,
799 _Container* container;
801 typedef _Container container_type;
803 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
804 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
805 {container->push_front(__value_); return *this;}
806 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
807 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
808 {container->push_front(_VSTD::move(__value_)); return *this;}
809 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
810 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
811 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
812 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
815 template <class _Container>
816 inline _LIBCPP_INLINE_VISIBILITY
817 front_insert_iterator<_Container>
818 front_inserter(_Container& __x)
820 return front_insert_iterator<_Container>(__x);
823 template <class _Container>
824 class _LIBCPP_TEMPLATE_VIS insert_iterator
825 : public iterator<output_iterator_tag,
832 _Container* container;
833 typename _Container::iterator iter;
835 typedef _Container container_type;
837 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
838 : container(_VSTD::addressof(__x)), iter(__i) {}
839 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
840 {iter = container->insert(iter, __value_); ++iter; return *this;}
841 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
842 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
843 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
844 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
845 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
846 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
847 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
850 template <class _Container>
851 inline _LIBCPP_INLINE_VISIBILITY
852 insert_iterator<_Container>
853 inserter(_Container& __x, typename _Container::iterator __i)
855 return insert_iterator<_Container>(__x, __i);
858 template <class _Tp, class _CharT = char,
859 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
860 class _LIBCPP_TEMPLATE_VIS istream_iterator
861 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
864 typedef _CharT char_type;
865 typedef _Traits traits_type;
866 typedef basic_istream<_CharT,_Traits> istream_type;
868 istream_type* __in_stream_;
871 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
872 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
874 if (!(*__in_stream_ >> __value_))
878 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
879 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
880 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
882 if (!(*__in_stream_ >> __value_))
886 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
887 {istream_iterator __t(*this); ++(*this); return __t;}
889 friend _LIBCPP_INLINE_VISIBILITY
890 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
891 {return __x.__in_stream_ == __y.__in_stream_;}
893 friend _LIBCPP_INLINE_VISIBILITY
894 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
895 {return !(__x == __y);}
898 template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
899 class _LIBCPP_TEMPLATE_VIS ostream_iterator
900 : public iterator<output_iterator_tag, void, void, void, void>
903 typedef _CharT char_type;
904 typedef _Traits traits_type;
905 typedef basic_ostream<_CharT,_Traits> ostream_type;
907 ostream_type* __out_stream_;
908 const char_type* __delim_;
910 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
911 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
912 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
913 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
914 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
916 *__out_stream_ << __value_;
918 *__out_stream_ << __delim_;
922 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
923 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
924 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
927 template<class _CharT, class _Traits>
928 class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
929 : public iterator<input_iterator_tag, _CharT,
930 typename _Traits::off_type, _CharT*,
934 typedef _CharT char_type;
935 typedef _Traits traits_type;
936 typedef typename _Traits::int_type int_type;
937 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
938 typedef basic_istream<_CharT,_Traits> istream_type;
940 mutable streambuf_type* __sbuf_;
945 streambuf_type* __sbuf_;
946 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
947 : __keep_(__c), __sbuf_(__s) {}
948 friend class istreambuf_iterator;
950 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
953 _LIBCPP_INLINE_VISIBILITY
954 bool __test_for_eof() const
956 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
961 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
962 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
963 : __sbuf_(__s.rdbuf()) {}
964 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
966 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
967 : __sbuf_(__p.__sbuf_) {}
969 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
970 {return static_cast<char_type>(__sbuf_->sgetc());}
971 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
972 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
977 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
979 return __proxy(__sbuf_->sbumpc(), __sbuf_);
982 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
983 {return __test_for_eof() == __b.__test_for_eof();}
986 template <class _CharT, class _Traits>
987 inline _LIBCPP_INLINE_VISIBILITY
988 bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
989 const istreambuf_iterator<_CharT,_Traits>& __b)
990 {return __a.equal(__b);}
992 template <class _CharT, class _Traits>
993 inline _LIBCPP_INLINE_VISIBILITY
994 bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
995 const istreambuf_iterator<_CharT,_Traits>& __b)
996 {return !__a.equal(__b);}
998 template <class _CharT, class _Traits>
999 class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
1000 : public iterator<output_iterator_tag, void, void, void, void>
1003 typedef _CharT char_type;
1004 typedef _Traits traits_type;
1005 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1006 typedef basic_ostream<_CharT,_Traits> ostream_type;
1008 streambuf_type* __sbuf_;
1010 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
1011 : __sbuf_(__s.rdbuf()) {}
1012 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1014 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1016 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1020 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1021 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1022 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1023 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
1025 #if !defined(__APPLE__) || \
1026 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1027 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1029 template <class _Ch, class _Tr>
1032 ostreambuf_iterator<_Ch, _Tr>
1033 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1034 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1035 ios_base& __iob, _Ch __fl);
1039 template <class _Iter>
1040 class _LIBCPP_TEMPLATE_VIS move_iterator
1045 typedef _Iter iterator_type;
1046 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1047 typedef typename iterator_traits<iterator_type>::value_type value_type;
1048 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1049 typedef iterator_type pointer;
1050 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1051 typedef typename iterator_traits<iterator_type>::reference __reference;
1052 typedef typename conditional<
1053 is_reference<__reference>::value,
1054 typename remove_reference<__reference>::type&&,
1058 typedef typename iterator_traits<iterator_type>::reference reference;
1061 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1062 move_iterator() : __i() {}
1063 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1064 explicit move_iterator(_Iter __x) : __i(__x) {}
1065 template <class _Up>
1066 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1067 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1068 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1069 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1070 reference operator*() const { return static_cast<reference>(*__i); }
1071 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1072 pointer operator->() const { return __i;}
1073 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1074 move_iterator& operator++() {++__i; return *this;}
1075 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1076 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1077 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1078 move_iterator& operator--() {--__i; return *this;}
1079 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1080 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1081 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1082 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1083 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1084 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1085 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1086 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1087 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1088 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1089 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1090 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
1093 template <class _Iter1, class _Iter2>
1094 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1096 operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1098 return __x.base() == __y.base();
1101 template <class _Iter1, class _Iter2>
1102 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1104 operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1106 return __x.base() < __y.base();
1109 template <class _Iter1, class _Iter2>
1110 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1112 operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1114 return __x.base() != __y.base();
1117 template <class _Iter1, class _Iter2>
1118 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1120 operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1122 return __x.base() > __y.base();
1125 template <class _Iter1, class _Iter2>
1126 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1128 operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1130 return __x.base() >= __y.base();
1133 template <class _Iter1, class _Iter2>
1134 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1136 operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1138 return __x.base() <= __y.base();
1141 #ifndef _LIBCPP_CXX03_LANG
1142 template <class _Iter1, class _Iter2>
1143 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1145 operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1146 -> decltype(__x.base() - __y.base())
1148 return __x.base() - __y.base();
1151 template <class _Iter1, class _Iter2>
1152 inline _LIBCPP_INLINE_VISIBILITY
1153 typename move_iterator<_Iter1>::difference_type
1154 operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1156 return __x.base() - __y.base();
1160 template <class _Iter>
1161 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1162 move_iterator<_Iter>
1163 operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1165 return move_iterator<_Iter>(__x.base() + __n);
1168 template <class _Iter>
1169 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1170 move_iterator<_Iter>
1171 make_move_iterator(_Iter __i)
1173 return move_iterator<_Iter>(__i);
1178 template <class _Iter> class __wrap_iter;
1180 template <class _Iter1, class _Iter2>
1181 _LIBCPP_INLINE_VISIBILITY
1183 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1185 template <class _Iter1, class _Iter2>
1186 _LIBCPP_INLINE_VISIBILITY
1188 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1190 template <class _Iter1, class _Iter2>
1191 _LIBCPP_INLINE_VISIBILITY
1193 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1195 template <class _Iter1, class _Iter2>
1196 _LIBCPP_INLINE_VISIBILITY
1198 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1200 template <class _Iter1, class _Iter2>
1201 _LIBCPP_INLINE_VISIBILITY
1203 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1205 template <class _Iter1, class _Iter2>
1206 _LIBCPP_INLINE_VISIBILITY
1208 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1210 #ifndef _LIBCPP_CXX03_LANG
1211 template <class _Iter1, class _Iter2>
1212 _LIBCPP_INLINE_VISIBILITY
1214 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1215 -> decltype(__x.base() - __y.base());
1217 template <class _Iter1, class _Iter2>
1218 _LIBCPP_INLINE_VISIBILITY
1219 typename __wrap_iter<_Iter1>::difference_type
1220 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1223 template <class _Iter>
1224 _LIBCPP_INLINE_VISIBILITY
1226 operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG;
1228 template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1229 template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1230 template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1231 template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
1233 #if _LIBCPP_DEBUG_LEVEL < 2
1235 template <class _Tp>
1236 _LIBCPP_INLINE_VISIBILITY
1239 is_trivially_copy_assignable<_Tp>::value,
1242 __unwrap_iter(__wrap_iter<_Tp*>);
1246 template <class _Tp>
1247 inline _LIBCPP_INLINE_VISIBILITY
1250 is_trivially_copy_assignable<_Tp>::value,
1253 __unwrap_iter(__wrap_iter<_Tp*> __i);
1257 template <class _Iter>
1261 typedef _Iter iterator_type;
1262 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1263 typedef typename iterator_traits<iterator_type>::value_type value_type;
1264 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1265 typedef typename iterator_traits<iterator_type>::pointer pointer;
1266 typedef typename iterator_traits<iterator_type>::reference reference;
1270 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT_DEBUG
1271 #if _LIBCPP_STD_VER > 11
1275 #if _LIBCPP_DEBUG_LEVEL >= 2
1276 __get_db()->__insert_i(this);
1279 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
1280 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG
1283 #if _LIBCPP_DEBUG_LEVEL >= 2
1284 __get_db()->__iterator_copy(this, &__u);
1287 #if _LIBCPP_DEBUG_LEVEL >= 2
1288 _LIBCPP_INLINE_VISIBILITY
1289 __wrap_iter(const __wrap_iter& __x)
1292 __get_db()->__iterator_copy(this, &__x);
1294 _LIBCPP_INLINE_VISIBILITY
1295 __wrap_iter& operator=(const __wrap_iter& __x)
1299 __get_db()->__iterator_copy(this, &__x);
1304 _LIBCPP_INLINE_VISIBILITY
1307 __get_db()->__erase_i(this);
1310 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT_DEBUG
1312 #if _LIBCPP_DEBUG_LEVEL >= 2
1313 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1314 "Attempted to dereference a non-dereferenceable iterator");
1318 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT_DEBUG
1320 #if _LIBCPP_DEBUG_LEVEL >= 2
1321 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1322 "Attempted to dereference a non-dereferenceable iterator");
1324 return (pointer)_VSTD::addressof(*__i);
1326 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT_DEBUG
1328 #if _LIBCPP_DEBUG_LEVEL >= 2
1329 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1330 "Attempted to increment non-incrementable iterator");
1335 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT_DEBUG
1336 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1337 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT_DEBUG
1339 #if _LIBCPP_DEBUG_LEVEL >= 2
1340 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1341 "Attempted to decrement non-decrementable iterator");
1346 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT_DEBUG
1347 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
1348 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG
1349 {__wrap_iter __w(*this); __w += __n; return __w;}
1350 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG
1352 #if _LIBCPP_DEBUG_LEVEL >= 2
1353 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1354 "Attempted to add/subtract iterator outside of valid range");
1359 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG
1360 {return *this + (-__n);}
1361 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG
1362 {*this += -__n; return *this;}
1363 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT_DEBUG
1365 #if _LIBCPP_DEBUG_LEVEL >= 2
1366 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1367 "Attempted to subscript iterator outside of valid range");
1372 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT_DEBUG {return __i;}
1375 #if _LIBCPP_DEBUG_LEVEL >= 2
1376 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1378 __get_db()->__insert_ic(this, __p);
1381 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {}
1384 template <class _Up> friend class __wrap_iter;
1385 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1386 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
1388 template <class _Iter1, class _Iter2>
1391 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1393 template <class _Iter1, class _Iter2>
1396 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1398 template <class _Iter1, class _Iter2>
1401 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1403 template <class _Iter1, class _Iter2>
1406 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1408 template <class _Iter1, class _Iter2>
1411 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1413 template <class _Iter1, class _Iter2>
1416 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1418 #ifndef _LIBCPP_CXX03_LANG
1419 template <class _Iter1, class _Iter2>
1422 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1423 -> decltype(__x.base() - __y.base());
1425 template <class _Iter1, class _Iter2>
1427 typename __wrap_iter<_Iter1>::difference_type
1428 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1431 template <class _Iter1>
1434 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG;
1436 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
1437 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
1438 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
1439 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1441 #if _LIBCPP_DEBUG_LEVEL < 2
1442 template <class _Tp>
1446 is_trivially_copy_assignable<_Tp>::value,
1449 __unwrap_iter(__wrap_iter<_Tp*>);
1451 template <class _Tp>
1452 inline _LIBCPP_INLINE_VISIBILITY
1455 is_trivially_copy_assignable<_Tp>::value,
1458 __unwrap_iter(__wrap_iter<_Tp*> __i);
1462 template <class _Iter1, class _Iter2>
1463 inline _LIBCPP_INLINE_VISIBILITY
1465 operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1467 return __x.base() == __y.base();
1470 template <class _Iter1, class _Iter2>
1471 inline _LIBCPP_INLINE_VISIBILITY
1473 operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1475 #if _LIBCPP_DEBUG_LEVEL >= 2
1476 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1477 "Attempted to compare incomparable iterators");
1479 return __x.base() < __y.base();
1482 template <class _Iter1, class _Iter2>
1483 inline _LIBCPP_INLINE_VISIBILITY
1485 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1487 return !(__x == __y);
1490 template <class _Iter1, class _Iter2>
1491 inline _LIBCPP_INLINE_VISIBILITY
1493 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1498 template <class _Iter1, class _Iter2>
1499 inline _LIBCPP_INLINE_VISIBILITY
1501 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1503 return !(__x < __y);
1506 template <class _Iter1, class _Iter2>
1507 inline _LIBCPP_INLINE_VISIBILITY
1509 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1511 return !(__y < __x);
1514 template <class _Iter1>
1515 inline _LIBCPP_INLINE_VISIBILITY
1517 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1519 return !(__x == __y);
1522 template <class _Iter1>
1523 inline _LIBCPP_INLINE_VISIBILITY
1525 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1530 template <class _Iter1>
1531 inline _LIBCPP_INLINE_VISIBILITY
1533 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1535 return !(__x < __y);
1538 template <class _Iter1>
1539 inline _LIBCPP_INLINE_VISIBILITY
1541 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1543 return !(__y < __x);
1546 #ifndef _LIBCPP_CXX03_LANG
1547 template <class _Iter1, class _Iter2>
1548 inline _LIBCPP_INLINE_VISIBILITY
1550 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1551 -> decltype(__x.base() - __y.base())
1553 #if _LIBCPP_DEBUG_LEVEL >= 2
1554 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1555 "Attempted to subtract incompatible iterators");
1557 return __x.base() - __y.base();
1560 template <class _Iter1, class _Iter2>
1561 inline _LIBCPP_INLINE_VISIBILITY
1562 typename __wrap_iter<_Iter1>::difference_type
1563 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1565 #if _LIBCPP_DEBUG_LEVEL >= 2
1566 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1567 "Attempted to subtract incompatible iterators");
1569 return __x.base() - __y.base();
1573 template <class _Iter>
1574 inline _LIBCPP_INLINE_VISIBILITY
1576 operator+(typename __wrap_iter<_Iter>::difference_type __n,
1577 __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG
1583 template <class _Iter>
1584 struct __libcpp_is_trivial_iterator
1585 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1587 template <class _Iter>
1588 struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
1589 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1591 template <class _Iter>
1592 struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
1593 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1595 template <class _Iter>
1596 struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
1597 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1600 template <class _Tp, size_t _Np>
1601 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1603 begin(_Tp (&__array)[_Np])
1608 template <class _Tp, size_t _Np>
1609 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1611 end(_Tp (&__array)[_Np])
1613 return __array + _Np;
1616 #if !defined(_LIBCPP_CXX03_LANG)
1618 template <class _Cp>
1619 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1621 begin(_Cp& __c) -> decltype(__c.begin())
1626 template <class _Cp>
1627 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1629 begin(const _Cp& __c) -> decltype(__c.begin())
1634 template <class _Cp>
1635 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1637 end(_Cp& __c) -> decltype(__c.end())
1642 template <class _Cp>
1643 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1645 end(const _Cp& __c) -> decltype(__c.end())
1650 #if _LIBCPP_STD_VER > 11
1652 template <class _Tp, size_t _Np>
1653 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1654 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1656 return reverse_iterator<_Tp*>(__array + _Np);
1659 template <class _Tp, size_t _Np>
1660 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1661 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1663 return reverse_iterator<_Tp*>(__array);
1666 template <class _Ep>
1667 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1668 reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1670 return reverse_iterator<const _Ep*>(__il.end());
1673 template <class _Ep>
1674 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1675 reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1677 return reverse_iterator<const _Ep*>(__il.begin());
1680 template <class _Cp>
1681 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1682 auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
1684 return _VSTD::begin(__c);
1687 template <class _Cp>
1688 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1689 auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
1691 return _VSTD::end(__c);
1694 template <class _Cp>
1695 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1696 auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1698 return __c.rbegin();
1701 template <class _Cp>
1702 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1703 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1705 return __c.rbegin();
1708 template <class _Cp>
1709 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1710 auto rend(_Cp& __c) -> decltype(__c.rend())
1715 template <class _Cp>
1716 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1717 auto rend(const _Cp& __c) -> decltype(__c.rend())
1722 template <class _Cp>
1723 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1724 auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
1726 return _VSTD::rbegin(__c);
1729 template <class _Cp>
1730 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1731 auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
1733 return _VSTD::rend(__c);
1739 #else // defined(_LIBCPP_CXX03_LANG)
1741 template <class _Cp>
1742 inline _LIBCPP_INLINE_VISIBILITY
1743 typename _Cp::iterator
1749 template <class _Cp>
1750 inline _LIBCPP_INLINE_VISIBILITY
1751 typename _Cp::const_iterator
1752 begin(const _Cp& __c)
1757 template <class _Cp>
1758 inline _LIBCPP_INLINE_VISIBILITY
1759 typename _Cp::iterator
1765 template <class _Cp>
1766 inline _LIBCPP_INLINE_VISIBILITY
1767 typename _Cp::const_iterator
1773 #endif // !defined(_LIBCPP_CXX03_LANG)
1775 #if _LIBCPP_STD_VER > 14
1776 template <class _Cont>
1777 constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
1779 template <class _Tp, size_t _Sz>
1780 constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1782 template <class _Cont>
1783 constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
1785 template <class _Tp, size_t _Sz>
1786 constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1788 template <class _Ep>
1789 constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1791 template <class _Cont> constexpr
1792 auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
1794 template <class _Cont> constexpr
1795 auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
1797 template <class _Tp, size_t _Sz>
1798 constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1800 template <class _Ep>
1801 constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1805 _LIBCPP_END_NAMESPACE_STD
1807 #endif // _LIBCPP_ITERATOR