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 // 27.4.3, iterator operations
68 // extension: second argument not conforming to C++03
69 template <class InputIterator> // constexpr in C++17
70 constexpr void advance(InputIterator& i,
71 typename iterator_traits<InputIterator>::difference_type n);
73 template <class InputIterator> // constexpr in C++17
74 constexpr typename iterator_traits<InputIterator>::difference_type
75 distance(InputIterator first, InputIterator last);
77 template <class InputIterator> // constexpr in C++17
78 constexpr InputIterator next(InputIterator x,
79 typename iterator_traits<InputIterator>::difference_type n = 1);
81 template <class BidirectionalIterator> // constexpr in C++17
82 constexpr BidirectionalIterator prev(BidirectionalIterator x,
83 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
85 template <class Iterator>
86 class reverse_iterator
87 : public iterator<typename iterator_traits<Iterator>::iterator_category,
88 typename iterator_traits<Iterator>::value_type,
89 typename iterator_traits<Iterator>::difference_type,
90 typename iterator_traits<Iterator>::pointer,
91 typename iterator_traits<Iterator>::reference>
96 typedef Iterator iterator_type;
97 typedef typename iterator_traits<Iterator>::difference_type difference_type;
98 typedef typename iterator_traits<Iterator>::reference reference;
99 typedef typename iterator_traits<Iterator>::pointer pointer;
101 constexpr reverse_iterator();
102 constexpr explicit reverse_iterator(Iterator x);
103 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
104 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
105 constexpr Iterator base() const;
106 constexpr reference operator*() const;
107 constexpr pointer operator->() const;
108 constexpr reverse_iterator& operator++();
109 constexpr reverse_iterator operator++(int);
110 constexpr reverse_iterator& operator--();
111 constexpr reverse_iterator operator--(int);
112 constexpr reverse_iterator operator+ (difference_type n) const;
113 constexpr reverse_iterator& operator+=(difference_type n);
114 constexpr reverse_iterator operator- (difference_type n) const;
115 constexpr reverse_iterator& operator-=(difference_type n);
116 constexpr reference operator[](difference_type n) const;
119 template <class Iterator1, class Iterator2>
120 constexpr bool // constexpr in C++17
121 operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
123 template <class Iterator1, class Iterator2>
124 constexpr bool // constexpr in C++17
125 operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
127 template <class Iterator1, class Iterator2>
128 constexpr bool // constexpr in C++17
129 operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
131 template <class Iterator1, class Iterator2>
132 constexpr bool // constexpr in C++17
133 operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
135 template <class Iterator1, class Iterator2>
136 constexpr bool // constexpr in C++17
137 operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
139 template <class Iterator1, class Iterator2>
140 constexpr bool // constexpr in C++17
141 operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
143 template <class Iterator1, class Iterator2>
145 operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
146 -> decltype(__y.base() - __x.base()); // constexpr in C++17
148 template <class Iterator>
149 constexpr reverse_iterator<Iterator>
150 operator+(typename reverse_iterator<Iterator>::difference_type n,
151 const reverse_iterator<Iterator>& x); // constexpr in C++17
153 template <class Iterator>
154 constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
156 template <class Container>
157 class back_insert_iterator
160 Container* container;
162 typedef Container container_type;
163 typedef void value_type;
164 typedef void difference_type;
165 typedef void reference;
166 typedef void pointer;
168 explicit back_insert_iterator(Container& x);
169 back_insert_iterator& operator=(const typename Container::value_type& value);
170 back_insert_iterator& operator*();
171 back_insert_iterator& operator++();
172 back_insert_iterator operator++(int);
175 template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
177 template <class Container>
178 class front_insert_iterator
181 Container* container;
183 typedef Container container_type;
184 typedef void value_type;
185 typedef void difference_type;
186 typedef void reference;
187 typedef void pointer;
189 explicit front_insert_iterator(Container& x);
190 front_insert_iterator& operator=(const typename Container::value_type& value);
191 front_insert_iterator& operator*();
192 front_insert_iterator& operator++();
193 front_insert_iterator operator++(int);
196 template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
198 template <class Container>
199 class insert_iterator
202 Container* container;
203 typename Container::iterator iter;
205 typedef Container container_type;
206 typedef void value_type;
207 typedef void difference_type;
208 typedef void reference;
209 typedef void pointer;
211 insert_iterator(Container& x, typename Container::iterator i);
212 insert_iterator& operator=(const typename Container::value_type& value);
213 insert_iterator& operator*();
214 insert_iterator& operator++();
215 insert_iterator& operator++(int);
218 template <class Container, class Iterator>
219 insert_iterator<Container> inserter(Container& x, Iterator i);
221 template <class Iterator>
222 class move_iterator {
224 typedef Iterator iterator_type;
225 typedef typename iterator_traits<Iterator>::difference_type difference_type;
226 typedef Iterator pointer;
227 typedef typename iterator_traits<Iterator>::value_type value_type;
228 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
229 typedef value_type&& reference;
231 constexpr move_iterator(); // all the constexprs are in C++17
232 constexpr explicit move_iterator(Iterator i);
234 constexpr move_iterator(const move_iterator<U>& u);
236 constexpr move_iterator& operator=(const move_iterator<U>& u);
237 constexpr iterator_type base() const;
238 constexpr reference operator*() const;
239 constexpr pointer operator->() const;
240 constexpr move_iterator& operator++();
241 constexpr move_iterator operator++(int);
242 constexpr move_iterator& operator--();
243 constexpr move_iterator operator--(int);
244 constexpr move_iterator operator+(difference_type n) const;
245 constexpr move_iterator& operator+=(difference_type n);
246 constexpr move_iterator operator-(difference_type n) const;
247 constexpr move_iterator& operator-=(difference_type n);
248 constexpr unspecified operator[](difference_type n) const;
250 Iterator current; // exposition only
253 template <class Iterator1, class Iterator2>
254 constexpr bool // constexpr in C++17
255 operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
257 template <class Iterator1, class Iterator2>
258 constexpr bool // constexpr in C++17
259 operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
261 template <class Iterator1, class Iterator2>
262 constexpr bool // constexpr in C++17
263 operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
265 template <class Iterator1, class Iterator2>
266 constexpr bool // constexpr in C++17
267 operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
269 template <class Iterator1, class Iterator2>
270 constexpr bool // constexpr in C++17
271 operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
273 template <class Iterator1, class Iterator2>
274 constexpr bool // constexpr in C++17
275 operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
277 template <class Iterator1, class Iterator2>
278 constexpr auto // constexpr in C++17
279 operator-(const move_iterator<Iterator1>& x,
280 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
282 template <class Iterator>
283 constexpr move_iterator<Iterator> operator+( // constexpr in C++17
284 typename move_iterator<Iterator>::difference_type n,
285 const move_iterator<Iterator>& x);
287 template <class Iterator> // constexpr in C++17
288 constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
291 template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
292 class istream_iterator
293 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
296 typedef charT char_type;
297 typedef traits traits_type;
298 typedef basic_istream<charT,traits> istream_type;
300 constexpr istream_iterator();
301 istream_iterator(istream_type& s);
302 istream_iterator(const istream_iterator& x);
305 const T& operator*() const;
306 const T* operator->() const;
307 istream_iterator& operator++();
308 istream_iterator operator++(int);
311 template <class T, class charT, class traits, class Distance>
312 bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
313 const istream_iterator<T,charT,traits,Distance>& y);
314 template <class T, class charT, class traits, class Distance>
315 bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
316 const istream_iterator<T,charT,traits,Distance>& y);
318 template <class T, class charT = char, class traits = char_traits<charT> >
319 class ostream_iterator
320 : public iterator<output_iterator_tag, void, void, void ,void>
323 typedef charT char_type;
324 typedef traits traits_type;
325 typedef basic_ostream<charT,traits> ostream_type;
327 ostream_iterator(ostream_type& s);
328 ostream_iterator(ostream_type& s, const charT* delimiter);
329 ostream_iterator(const ostream_iterator& x);
331 ostream_iterator& operator=(const T& value);
333 ostream_iterator& operator*();
334 ostream_iterator& operator++();
335 ostream_iterator& operator++(int);
338 template<class charT, class traits = char_traits<charT> >
339 class istreambuf_iterator
340 : public iterator<input_iterator_tag, charT,
341 typename traits::off_type, unspecified,
345 typedef charT char_type;
346 typedef traits traits_type;
347 typedef typename traits::int_type int_type;
348 typedef basic_streambuf<charT,traits> streambuf_type;
349 typedef basic_istream<charT,traits> istream_type;
351 istreambuf_iterator() noexcept;
352 istreambuf_iterator(istream_type& s) noexcept;
353 istreambuf_iterator(streambuf_type* s) noexcept;
354 istreambuf_iterator(a-private-type) noexcept;
356 charT operator*() const;
357 pointer operator->() const;
358 istreambuf_iterator& operator++();
359 a-private-type operator++(int);
361 bool equal(const istreambuf_iterator& b) const;
364 template <class charT, class traits>
365 bool operator==(const istreambuf_iterator<charT,traits>& a,
366 const istreambuf_iterator<charT,traits>& b);
367 template <class charT, class traits>
368 bool operator!=(const istreambuf_iterator<charT,traits>& a,
369 const istreambuf_iterator<charT,traits>& b);
371 template <class charT, class traits = char_traits<charT> >
372 class ostreambuf_iterator
373 : public iterator<output_iterator_tag, void, void, void, void>
376 typedef charT char_type;
377 typedef traits traits_type;
378 typedef basic_streambuf<charT,traits> streambuf_type;
379 typedef basic_ostream<charT,traits> ostream_type;
381 ostreambuf_iterator(ostream_type& s) noexcept;
382 ostreambuf_iterator(streambuf_type* s) noexcept;
383 ostreambuf_iterator& operator=(charT c);
384 ostreambuf_iterator& operator*();
385 ostreambuf_iterator& operator++();
386 ostreambuf_iterator& operator++(int);
387 bool failed() const noexcept;
390 template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
391 template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
392 template <class C> constexpr auto end(C& c) -> decltype(c.end());
393 template <class C> constexpr auto end(const C& c) -> decltype(c.end());
394 template <class T, size_t N> constexpr T* begin(T (&array)[N]);
395 template <class T, size_t N> constexpr T* end(T (&array)[N]);
397 template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
398 template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
399 template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
400 template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
401 template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
402 template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
403 template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
404 template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
405 template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
406 template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
407 template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
408 template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
410 // 24.8, container access:
411 template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
412 template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
413 template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
414 template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
415 template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
416 template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
417 template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
418 template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
419 template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
426 #include <iosfwd> // for forward declarations of vector and string.
427 #include <__functional_base>
428 #include <type_traits>
430 #include <initializer_list>
432 #include <Availability.h>
437 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
438 #pragma GCC system_header
441 _LIBCPP_BEGIN_NAMESPACE_STD
443 struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
444 struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
445 struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
446 struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
447 struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
450 struct __has_iterator_category
453 struct __two {char __lx; char __lxx;};
454 template <class _Up> static __two __test(...);
455 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
457 static const bool value = sizeof(__test<_Tp>(0)) == 1;
460 template <class _Iter, bool> struct __iterator_traits_impl {};
462 template <class _Iter>
463 struct __iterator_traits_impl<_Iter, true>
465 typedef typename _Iter::difference_type difference_type;
466 typedef typename _Iter::value_type value_type;
467 typedef typename _Iter::pointer pointer;
468 typedef typename _Iter::reference reference;
469 typedef typename _Iter::iterator_category iterator_category;
472 template <class _Iter, bool> struct __iterator_traits {};
474 template <class _Iter>
475 struct __iterator_traits<_Iter, true>
476 : __iterator_traits_impl
479 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
480 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
484 // iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
485 // exists. Else iterator_traits<Iterator> will be an empty class. This is a
486 // conforming extension which allows some programs to compile and behave as
487 // the client expects instead of failing at compile time.
489 template <class _Iter>
490 struct _LIBCPP_TEMPLATE_VIS iterator_traits
491 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
494 struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
496 typedef ptrdiff_t difference_type;
497 typedef typename remove_const<_Tp>::type value_type;
498 typedef _Tp* pointer;
499 typedef _Tp& reference;
500 typedef random_access_iterator_tag iterator_category;
503 template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
504 struct __has_iterator_category_convertible_to
505 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
508 template <class _Tp, class _Up>
509 struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
512 struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
515 struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
518 struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
521 struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
524 struct __is_exactly_input_iterator
525 : public integral_constant<bool,
526 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
527 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
529 template<class _Category, class _Tp, class _Distance = ptrdiff_t,
530 class _Pointer = _Tp*, class _Reference = _Tp&>
531 struct _LIBCPP_TEMPLATE_VIS iterator
533 typedef _Tp value_type;
534 typedef _Distance difference_type;
535 typedef _Pointer pointer;
536 typedef _Reference reference;
537 typedef _Category iterator_category;
540 template <class _InputIter>
541 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
542 void __advance(_InputIter& __i,
543 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
545 for (; __n > 0; --__n)
549 template <class _BiDirIter>
550 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
551 void __advance(_BiDirIter& __i,
552 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
555 for (; __n > 0; --__n)
558 for (; __n < 0; ++__n)
562 template <class _RandIter>
563 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
564 void __advance(_RandIter& __i,
565 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
570 template <class _InputIter>
571 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
572 void advance(_InputIter& __i,
573 typename iterator_traits<_InputIter>::difference_type __n)
575 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
578 template <class _InputIter>
579 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
580 typename iterator_traits<_InputIter>::difference_type
581 __distance(_InputIter __first, _InputIter __last, input_iterator_tag)
583 typename iterator_traits<_InputIter>::difference_type __r(0);
584 for (; __first != __last; ++__first)
589 template <class _RandIter>
590 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
591 typename iterator_traits<_RandIter>::difference_type
592 __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
594 return __last - __first;
597 template <class _InputIter>
598 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
599 typename iterator_traits<_InputIter>::difference_type
600 distance(_InputIter __first, _InputIter __last)
602 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
605 template <class _InputIter>
606 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
609 typename iterator_traits<_InputIter>::difference_type __n = 1,
610 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
612 _VSTD::advance(__x, __n);
616 template <class _BidiretionalIter>
617 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
619 prev(_BidiretionalIter __x,
620 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
621 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
623 _VSTD::advance(__x, -__n);
628 template <class _Tp, class = void>
629 struct __is_stashing_iterator : false_type {};
632 struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
635 template <class _Iter>
636 class _LIBCPP_TEMPLATE_VIS reverse_iterator
637 : public iterator<typename iterator_traits<_Iter>::iterator_category,
638 typename iterator_traits<_Iter>::value_type,
639 typename iterator_traits<_Iter>::difference_type,
640 typename iterator_traits<_Iter>::pointer,
641 typename iterator_traits<_Iter>::reference>
644 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
646 static_assert(!__is_stashing_iterator<_Iter>::value,
647 "The specified iterator type cannot be used with reverse_iterator; "
648 "Using stashing iterators with reverse_iterator causes undefined behavior");
653 typedef _Iter iterator_type;
654 typedef typename iterator_traits<_Iter>::difference_type difference_type;
655 typedef typename iterator_traits<_Iter>::reference reference;
656 typedef typename iterator_traits<_Iter>::pointer pointer;
658 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
659 reverse_iterator() : __t(), current() {}
660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
661 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
663 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
664 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
667 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
668 { __t = current = __u.base(); return *this; }
669 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
670 _Iter base() const {return current;}
671 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
672 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
673 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
674 pointer operator->() const {return _VSTD::addressof(operator*());}
675 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
676 reverse_iterator& operator++() {--current; return *this;}
677 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
678 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
679 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
680 reverse_iterator& operator--() {++current; return *this;}
681 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
682 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
683 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
684 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
685 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
686 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
687 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
688 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
689 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
690 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
691 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
692 reference operator[](difference_type __n) const {return *(*this + __n);}
695 template <class _Iter1, class _Iter2>
696 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
698 operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
700 return __x.base() == __y.base();
703 template <class _Iter1, class _Iter2>
704 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
706 operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
708 return __x.base() > __y.base();
711 template <class _Iter1, class _Iter2>
712 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
714 operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
716 return __x.base() != __y.base();
719 template <class _Iter1, class _Iter2>
720 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
722 operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
724 return __x.base() < __y.base();
727 template <class _Iter1, class _Iter2>
728 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
730 operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
732 return __x.base() <= __y.base();
735 template <class _Iter1, class _Iter2>
736 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
738 operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
740 return __x.base() >= __y.base();
743 #ifndef _LIBCPP_CXX03_LANG
744 template <class _Iter1, class _Iter2>
745 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
747 operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
748 -> decltype(__y.base() - __x.base())
750 return __y.base() - __x.base();
753 template <class _Iter1, class _Iter2>
754 inline _LIBCPP_INLINE_VISIBILITY
755 typename reverse_iterator<_Iter1>::difference_type
756 operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
758 return __y.base() - __x.base();
762 template <class _Iter>
763 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
764 reverse_iterator<_Iter>
765 operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
767 return reverse_iterator<_Iter>(__x.base() - __n);
770 #if _LIBCPP_STD_VER > 11
771 template <class _Iter>
772 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
773 reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
775 return reverse_iterator<_Iter>(__i);
779 template <class _Container>
780 class _LIBCPP_TEMPLATE_VIS back_insert_iterator
781 : public iterator<output_iterator_tag,
788 _Container* container;
790 typedef _Container container_type;
792 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
793 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
794 {container->push_back(__value_); return *this;}
795 #ifndef _LIBCPP_CXX03_LANG
796 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
797 {container->push_back(_VSTD::move(__value_)); return *this;}
798 #endif // _LIBCPP_CXX03_LANG
799 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
800 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
801 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
804 template <class _Container>
805 inline _LIBCPP_INLINE_VISIBILITY
806 back_insert_iterator<_Container>
807 back_inserter(_Container& __x)
809 return back_insert_iterator<_Container>(__x);
812 template <class _Container>
813 class _LIBCPP_TEMPLATE_VIS front_insert_iterator
814 : public iterator<output_iterator_tag,
821 _Container* container;
823 typedef _Container container_type;
825 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
826 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
827 {container->push_front(__value_); return *this;}
828 #ifndef _LIBCPP_CXX03_LANG
829 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
830 {container->push_front(_VSTD::move(__value_)); return *this;}
831 #endif // _LIBCPP_CXX03_LANG
832 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
833 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
834 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
837 template <class _Container>
838 inline _LIBCPP_INLINE_VISIBILITY
839 front_insert_iterator<_Container>
840 front_inserter(_Container& __x)
842 return front_insert_iterator<_Container>(__x);
845 template <class _Container>
846 class _LIBCPP_TEMPLATE_VIS insert_iterator
847 : public iterator<output_iterator_tag,
854 _Container* container;
855 typename _Container::iterator iter;
857 typedef _Container container_type;
859 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
860 : container(_VSTD::addressof(__x)), iter(__i) {}
861 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
862 {iter = container->insert(iter, __value_); ++iter; return *this;}
863 #ifndef _LIBCPP_CXX03_LANG
864 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
865 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
866 #endif // _LIBCPP_CXX03_LANG
867 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
868 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
869 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
872 template <class _Container>
873 inline _LIBCPP_INLINE_VISIBILITY
874 insert_iterator<_Container>
875 inserter(_Container& __x, typename _Container::iterator __i)
877 return insert_iterator<_Container>(__x, __i);
880 template <class _Tp, class _CharT = char,
881 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
882 class _LIBCPP_TEMPLATE_VIS istream_iterator
883 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
886 typedef _CharT char_type;
887 typedef _Traits traits_type;
888 typedef basic_istream<_CharT,_Traits> istream_type;
890 istream_type* __in_stream_;
893 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
894 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
896 if (!(*__in_stream_ >> __value_))
900 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
901 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
902 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
904 if (!(*__in_stream_ >> __value_))
908 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
909 {istream_iterator __t(*this); ++(*this); return __t;}
911 friend _LIBCPP_INLINE_VISIBILITY
912 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
913 {return __x.__in_stream_ == __y.__in_stream_;}
915 friend _LIBCPP_INLINE_VISIBILITY
916 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
917 {return !(__x == __y);}
920 template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
921 class _LIBCPP_TEMPLATE_VIS ostream_iterator
922 : public iterator<output_iterator_tag, void, void, void, void>
925 typedef _CharT char_type;
926 typedef _Traits traits_type;
927 typedef basic_ostream<_CharT,_Traits> ostream_type;
929 ostream_type* __out_stream_;
930 const char_type* __delim_;
932 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
933 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
934 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
935 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
936 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
938 *__out_stream_ << __value_;
940 *__out_stream_ << __delim_;
944 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
945 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
946 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
949 template<class _CharT, class _Traits>
950 class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
951 : public iterator<input_iterator_tag, _CharT,
952 typename _Traits::off_type, _CharT*,
956 typedef _CharT char_type;
957 typedef _Traits traits_type;
958 typedef typename _Traits::int_type int_type;
959 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
960 typedef basic_istream<_CharT,_Traits> istream_type;
962 mutable streambuf_type* __sbuf_;
967 streambuf_type* __sbuf_;
968 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
969 : __keep_(__c), __sbuf_(__s) {}
970 friend class istreambuf_iterator;
972 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
975 _LIBCPP_INLINE_VISIBILITY
976 bool __test_for_eof() const
978 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
983 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
984 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
985 : __sbuf_(__s.rdbuf()) {}
986 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
988 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
989 : __sbuf_(__p.__sbuf_) {}
991 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
992 {return static_cast<char_type>(__sbuf_->sgetc());}
993 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
998 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1000 return __proxy(__sbuf_->sbumpc(), __sbuf_);
1003 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1004 {return __test_for_eof() == __b.__test_for_eof();}
1007 template <class _CharT, class _Traits>
1008 inline _LIBCPP_INLINE_VISIBILITY
1009 bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1010 const istreambuf_iterator<_CharT,_Traits>& __b)
1011 {return __a.equal(__b);}
1013 template <class _CharT, class _Traits>
1014 inline _LIBCPP_INLINE_VISIBILITY
1015 bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1016 const istreambuf_iterator<_CharT,_Traits>& __b)
1017 {return !__a.equal(__b);}
1019 template <class _CharT, class _Traits>
1020 class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
1021 : public iterator<output_iterator_tag, void, void, void, void>
1024 typedef _CharT char_type;
1025 typedef _Traits traits_type;
1026 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1027 typedef basic_ostream<_CharT,_Traits> ostream_type;
1029 streambuf_type* __sbuf_;
1031 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
1032 : __sbuf_(__s.rdbuf()) {}
1033 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1035 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1037 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1041 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1042 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1043 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1044 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
1046 #if !defined(__APPLE__) || \
1047 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1048 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1050 template <class _Ch, class _Tr>
1053 ostreambuf_iterator<_Ch, _Tr>
1054 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1055 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1056 ios_base& __iob, _Ch __fl);
1060 template <class _Iter>
1061 class _LIBCPP_TEMPLATE_VIS move_iterator
1066 typedef _Iter iterator_type;
1067 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1068 typedef typename iterator_traits<iterator_type>::value_type value_type;
1069 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1070 typedef iterator_type pointer;
1071 #ifndef _LIBCPP_CXX03_LANG
1072 typedef typename iterator_traits<iterator_type>::reference __reference;
1073 typedef typename conditional<
1074 is_reference<__reference>::value,
1075 typename remove_reference<__reference>::type&&,
1079 typedef typename iterator_traits<iterator_type>::reference reference;
1082 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1083 move_iterator() : __i() {}
1084 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1085 explicit move_iterator(_Iter __x) : __i(__x) {}
1086 template <class _Up>
1087 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1088 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1089 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1090 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1091 reference operator*() const { return static_cast<reference>(*__i); }
1092 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1093 pointer operator->() const { return __i;}
1094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1095 move_iterator& operator++() {++__i; return *this;}
1096 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1097 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1098 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1099 move_iterator& operator--() {--__i; return *this;}
1100 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1101 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1102 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1103 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1104 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1105 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1106 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1107 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1108 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1109 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1110 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1111 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
1114 template <class _Iter1, class _Iter2>
1115 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1117 operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1119 return __x.base() == __y.base();
1122 template <class _Iter1, class _Iter2>
1123 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1125 operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1127 return __x.base() < __y.base();
1130 template <class _Iter1, class _Iter2>
1131 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1133 operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1135 return __x.base() != __y.base();
1138 template <class _Iter1, class _Iter2>
1139 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1141 operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1143 return __x.base() > __y.base();
1146 template <class _Iter1, class _Iter2>
1147 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1149 operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1151 return __x.base() >= __y.base();
1154 template <class _Iter1, class _Iter2>
1155 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1157 operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1159 return __x.base() <= __y.base();
1162 #ifndef _LIBCPP_CXX03_LANG
1163 template <class _Iter1, class _Iter2>
1164 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1166 operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1167 -> decltype(__x.base() - __y.base())
1169 return __x.base() - __y.base();
1172 template <class _Iter1, class _Iter2>
1173 inline _LIBCPP_INLINE_VISIBILITY
1174 typename move_iterator<_Iter1>::difference_type
1175 operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1177 return __x.base() - __y.base();
1181 template <class _Iter>
1182 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1183 move_iterator<_Iter>
1184 operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1186 return move_iterator<_Iter>(__x.base() + __n);
1189 template <class _Iter>
1190 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1191 move_iterator<_Iter>
1192 make_move_iterator(_Iter __i)
1194 return move_iterator<_Iter>(__i);
1199 template <class _Iter> class __wrap_iter;
1201 template <class _Iter1, class _Iter2>
1202 _LIBCPP_INLINE_VISIBILITY
1204 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1206 template <class _Iter1, class _Iter2>
1207 _LIBCPP_INLINE_VISIBILITY
1209 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1211 template <class _Iter1, class _Iter2>
1212 _LIBCPP_INLINE_VISIBILITY
1214 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1216 template <class _Iter1, class _Iter2>
1217 _LIBCPP_INLINE_VISIBILITY
1219 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1221 template <class _Iter1, class _Iter2>
1222 _LIBCPP_INLINE_VISIBILITY
1224 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1226 template <class _Iter1, class _Iter2>
1227 _LIBCPP_INLINE_VISIBILITY
1229 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1231 #ifndef _LIBCPP_CXX03_LANG
1232 template <class _Iter1, class _Iter2>
1233 _LIBCPP_INLINE_VISIBILITY
1235 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1236 -> decltype(__x.base() - __y.base());
1238 template <class _Iter1, class _Iter2>
1239 _LIBCPP_INLINE_VISIBILITY
1240 typename __wrap_iter<_Iter1>::difference_type
1241 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1244 template <class _Iter>
1245 _LIBCPP_INLINE_VISIBILITY
1247 operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG;
1249 template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1250 template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1251 template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1252 template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
1254 #if _LIBCPP_DEBUG_LEVEL < 2
1256 template <class _Tp>
1257 _LIBCPP_INLINE_VISIBILITY
1260 is_trivially_copy_assignable<_Tp>::value,
1263 __unwrap_iter(__wrap_iter<_Tp*>);
1267 template <class _Tp>
1268 inline _LIBCPP_INLINE_VISIBILITY
1271 is_trivially_copy_assignable<_Tp>::value,
1274 __unwrap_iter(__wrap_iter<_Tp*> __i);
1278 template <class _Iter>
1282 typedef _Iter iterator_type;
1283 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1284 typedef typename iterator_traits<iterator_type>::value_type value_type;
1285 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1286 typedef typename iterator_traits<iterator_type>::pointer pointer;
1287 typedef typename iterator_traits<iterator_type>::reference reference;
1291 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT_DEBUG
1292 #if _LIBCPP_STD_VER > 11
1296 #if _LIBCPP_DEBUG_LEVEL >= 2
1297 __get_db()->__insert_i(this);
1300 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
1301 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG
1304 #if _LIBCPP_DEBUG_LEVEL >= 2
1305 __get_db()->__iterator_copy(this, &__u);
1308 #if _LIBCPP_DEBUG_LEVEL >= 2
1309 _LIBCPP_INLINE_VISIBILITY
1310 __wrap_iter(const __wrap_iter& __x)
1313 __get_db()->__iterator_copy(this, &__x);
1315 _LIBCPP_INLINE_VISIBILITY
1316 __wrap_iter& operator=(const __wrap_iter& __x)
1320 __get_db()->__iterator_copy(this, &__x);
1325 _LIBCPP_INLINE_VISIBILITY
1328 __get_db()->__erase_i(this);
1331 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT_DEBUG
1333 #if _LIBCPP_DEBUG_LEVEL >= 2
1334 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1335 "Attempted to dereference a non-dereferenceable iterator");
1339 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT_DEBUG
1341 #if _LIBCPP_DEBUG_LEVEL >= 2
1342 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1343 "Attempted to dereference a non-dereferenceable iterator");
1345 return (pointer)_VSTD::addressof(*__i);
1347 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT_DEBUG
1349 #if _LIBCPP_DEBUG_LEVEL >= 2
1350 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1351 "Attempted to increment non-incrementable iterator");
1356 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT_DEBUG
1357 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1358 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT_DEBUG
1360 #if _LIBCPP_DEBUG_LEVEL >= 2
1361 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1362 "Attempted to decrement non-decrementable iterator");
1367 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT_DEBUG
1368 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
1369 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG
1370 {__wrap_iter __w(*this); __w += __n; return __w;}
1371 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG
1373 #if _LIBCPP_DEBUG_LEVEL >= 2
1374 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1375 "Attempted to add/subtract iterator outside of valid range");
1380 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG
1381 {return *this + (-__n);}
1382 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG
1383 {*this += -__n; return *this;}
1384 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT_DEBUG
1386 #if _LIBCPP_DEBUG_LEVEL >= 2
1387 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1388 "Attempted to subscript iterator outside of valid range");
1393 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT_DEBUG {return __i;}
1396 #if _LIBCPP_DEBUG_LEVEL >= 2
1397 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1399 __get_db()->__insert_ic(this, __p);
1402 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {}
1405 template <class _Up> friend class __wrap_iter;
1406 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1407 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
1409 template <class _Iter1, class _Iter2>
1412 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1414 template <class _Iter1, class _Iter2>
1417 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1419 template <class _Iter1, class _Iter2>
1422 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1424 template <class _Iter1, class _Iter2>
1427 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1429 template <class _Iter1, class _Iter2>
1432 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1434 template <class _Iter1, class _Iter2>
1437 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1439 #ifndef _LIBCPP_CXX03_LANG
1440 template <class _Iter1, class _Iter2>
1443 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1444 -> decltype(__x.base() - __y.base());
1446 template <class _Iter1, class _Iter2>
1448 typename __wrap_iter<_Iter1>::difference_type
1449 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1452 template <class _Iter1>
1455 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG;
1457 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
1458 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
1459 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
1460 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1462 #if _LIBCPP_DEBUG_LEVEL < 2
1463 template <class _Tp>
1467 is_trivially_copy_assignable<_Tp>::value,
1470 __unwrap_iter(__wrap_iter<_Tp*>);
1472 template <class _Tp>
1473 inline _LIBCPP_INLINE_VISIBILITY
1476 is_trivially_copy_assignable<_Tp>::value,
1479 __unwrap_iter(__wrap_iter<_Tp*> __i);
1483 template <class _Iter1, class _Iter2>
1484 inline _LIBCPP_INLINE_VISIBILITY
1486 operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1488 return __x.base() == __y.base();
1491 template <class _Iter1, class _Iter2>
1492 inline _LIBCPP_INLINE_VISIBILITY
1494 operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1496 #if _LIBCPP_DEBUG_LEVEL >= 2
1497 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1498 "Attempted to compare incomparable iterators");
1500 return __x.base() < __y.base();
1503 template <class _Iter1, class _Iter2>
1504 inline _LIBCPP_INLINE_VISIBILITY
1506 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1508 return !(__x == __y);
1511 template <class _Iter1, class _Iter2>
1512 inline _LIBCPP_INLINE_VISIBILITY
1514 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1519 template <class _Iter1, class _Iter2>
1520 inline _LIBCPP_INLINE_VISIBILITY
1522 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1524 return !(__x < __y);
1527 template <class _Iter1, class _Iter2>
1528 inline _LIBCPP_INLINE_VISIBILITY
1530 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1532 return !(__y < __x);
1535 template <class _Iter1>
1536 inline _LIBCPP_INLINE_VISIBILITY
1538 operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1540 return !(__x == __y);
1543 template <class _Iter1>
1544 inline _LIBCPP_INLINE_VISIBILITY
1546 operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1551 template <class _Iter1>
1552 inline _LIBCPP_INLINE_VISIBILITY
1554 operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1556 return !(__x < __y);
1559 template <class _Iter1>
1560 inline _LIBCPP_INLINE_VISIBILITY
1562 operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1564 return !(__y < __x);
1567 #ifndef _LIBCPP_CXX03_LANG
1568 template <class _Iter1, class _Iter2>
1569 inline _LIBCPP_INLINE_VISIBILITY
1571 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1572 -> decltype(__x.base() - __y.base())
1574 #if _LIBCPP_DEBUG_LEVEL >= 2
1575 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1576 "Attempted to subtract incompatible iterators");
1578 return __x.base() - __y.base();
1581 template <class _Iter1, class _Iter2>
1582 inline _LIBCPP_INLINE_VISIBILITY
1583 typename __wrap_iter<_Iter1>::difference_type
1584 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1586 #if _LIBCPP_DEBUG_LEVEL >= 2
1587 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1588 "Attempted to subtract incompatible iterators");
1590 return __x.base() - __y.base();
1594 template <class _Iter>
1595 inline _LIBCPP_INLINE_VISIBILITY
1597 operator+(typename __wrap_iter<_Iter>::difference_type __n,
1598 __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG
1604 template <class _Iter>
1605 struct __libcpp_is_trivial_iterator
1606 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1608 template <class _Iter>
1609 struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
1610 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1612 template <class _Iter>
1613 struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
1614 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1616 template <class _Iter>
1617 struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
1618 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1621 template <class _Tp, size_t _Np>
1622 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1624 begin(_Tp (&__array)[_Np])
1629 template <class _Tp, size_t _Np>
1630 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1632 end(_Tp (&__array)[_Np])
1634 return __array + _Np;
1637 #if !defined(_LIBCPP_CXX03_LANG)
1639 template <class _Cp>
1640 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1642 begin(_Cp& __c) -> decltype(__c.begin())
1647 template <class _Cp>
1648 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1650 begin(const _Cp& __c) -> decltype(__c.begin())
1655 template <class _Cp>
1656 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1658 end(_Cp& __c) -> decltype(__c.end())
1663 template <class _Cp>
1664 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1666 end(const _Cp& __c) -> decltype(__c.end())
1671 #if _LIBCPP_STD_VER > 11
1673 template <class _Tp, size_t _Np>
1674 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1675 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1677 return reverse_iterator<_Tp*>(__array + _Np);
1680 template <class _Tp, size_t _Np>
1681 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1682 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1684 return reverse_iterator<_Tp*>(__array);
1687 template <class _Ep>
1688 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1689 reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1691 return reverse_iterator<const _Ep*>(__il.end());
1694 template <class _Ep>
1695 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1696 reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1698 return reverse_iterator<const _Ep*>(__il.begin());
1701 template <class _Cp>
1702 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1703 auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
1705 return _VSTD::begin(__c);
1708 template <class _Cp>
1709 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1710 auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
1712 return _VSTD::end(__c);
1715 template <class _Cp>
1716 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1717 auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1719 return __c.rbegin();
1722 template <class _Cp>
1723 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1724 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1726 return __c.rbegin();
1729 template <class _Cp>
1730 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1731 auto rend(_Cp& __c) -> decltype(__c.rend())
1736 template <class _Cp>
1737 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1738 auto rend(const _Cp& __c) -> decltype(__c.rend())
1743 template <class _Cp>
1744 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1745 auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
1747 return _VSTD::rbegin(__c);
1750 template <class _Cp>
1751 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1752 auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
1754 return _VSTD::rend(__c);
1760 #else // defined(_LIBCPP_CXX03_LANG)
1762 template <class _Cp>
1763 inline _LIBCPP_INLINE_VISIBILITY
1764 typename _Cp::iterator
1770 template <class _Cp>
1771 inline _LIBCPP_INLINE_VISIBILITY
1772 typename _Cp::const_iterator
1773 begin(const _Cp& __c)
1778 template <class _Cp>
1779 inline _LIBCPP_INLINE_VISIBILITY
1780 typename _Cp::iterator
1786 template <class _Cp>
1787 inline _LIBCPP_INLINE_VISIBILITY
1788 typename _Cp::const_iterator
1794 #endif // !defined(_LIBCPP_CXX03_LANG)
1796 #if _LIBCPP_STD_VER > 14
1797 template <class _Cont>
1798 constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
1800 template <class _Tp, size_t _Sz>
1801 constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1803 template <class _Cont>
1804 constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
1806 template <class _Tp, size_t _Sz>
1807 constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1809 template <class _Ep>
1810 constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1812 template <class _Cont> constexpr
1813 auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
1815 template <class _Cont> constexpr
1816 auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
1818 template <class _Tp, size_t _Sz>
1819 constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1821 template <class _Ep>
1822 constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1826 _LIBCPP_END_NAMESPACE_STD
1828 #endif // _LIBCPP_ITERATOR