blob: 242f18814e6919171e7aabb143cc406d08c50154 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Andrew Walbran16937d02019-10-22 13:54:20 +01004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ITERATOR
11#define _LIBCPP_ITERATOR
12
13/*
14 iterator synopsis
15
16namespace std
17{
18
19template<class Iterator>
20struct iterator_traits
21{
22 typedef typename Iterator::difference_type difference_type;
23 typedef typename Iterator::value_type value_type;
24 typedef typename Iterator::pointer pointer;
25 typedef typename Iterator::reference reference;
26 typedef typename Iterator::iterator_category iterator_category;
27};
28
29template<class T>
30struct iterator_traits<T*>
31{
32 typedef ptrdiff_t difference_type;
33 typedef T value_type;
34 typedef T* pointer;
35 typedef T& reference;
36 typedef random_access_iterator_tag iterator_category;
37};
38
39template<class Category, class T, class Distance = ptrdiff_t,
40 class Pointer = T*, class Reference = T&>
41struct iterator
42{
43 typedef T value_type;
44 typedef Distance difference_type;
45 typedef Pointer pointer;
46 typedef Reference reference;
47 typedef Category iterator_category;
48};
49
50struct input_iterator_tag {};
51struct output_iterator_tag {};
52struct forward_iterator_tag : public input_iterator_tag {};
53struct bidirectional_iterator_tag : public forward_iterator_tag {};
54struct random_access_iterator_tag : public bidirectional_iterator_tag {};
55
56// 27.4.3, iterator operations
57// extension: second argument not conforming to C++03
58template <class InputIterator> // constexpr in C++17
59 constexpr void advance(InputIterator& i,
60 typename iterator_traits<InputIterator>::difference_type n);
61
62template <class InputIterator> // constexpr in C++17
63 constexpr typename iterator_traits<InputIterator>::difference_type
64 distance(InputIterator first, InputIterator last);
65
66template <class InputIterator> // constexpr in C++17
67 constexpr InputIterator next(InputIterator x,
68typename iterator_traits<InputIterator>::difference_type n = 1);
69
70template <class BidirectionalIterator> // constexpr in C++17
71 constexpr BidirectionalIterator prev(BidirectionalIterator x,
72 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
73
74template <class Iterator>
75class reverse_iterator
76 : public iterator<typename iterator_traits<Iterator>::iterator_category,
77 typename iterator_traits<Iterator>::value_type,
78 typename iterator_traits<Iterator>::difference_type,
79 typename iterator_traits<Iterator>::pointer,
80 typename iterator_traits<Iterator>::reference>
81{
82protected:
83 Iterator current;
84public:
85 typedef Iterator iterator_type;
86 typedef typename iterator_traits<Iterator>::difference_type difference_type;
87 typedef typename iterator_traits<Iterator>::reference reference;
88 typedef typename iterator_traits<Iterator>::pointer pointer;
89
90 constexpr reverse_iterator();
91 constexpr explicit reverse_iterator(Iterator x);
92 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
93 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
94 constexpr Iterator base() const;
95 constexpr reference operator*() const;
96 constexpr pointer operator->() const;
97 constexpr reverse_iterator& operator++();
98 constexpr reverse_iterator operator++(int);
99 constexpr reverse_iterator& operator--();
100 constexpr reverse_iterator operator--(int);
101 constexpr reverse_iterator operator+ (difference_type n) const;
102 constexpr reverse_iterator& operator+=(difference_type n);
103 constexpr reverse_iterator operator- (difference_type n) const;
104 constexpr reverse_iterator& operator-=(difference_type n);
105 constexpr reference operator[](difference_type n) const;
106};
107
108template <class Iterator1, class Iterator2>
109constexpr bool // constexpr in C++17
110operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
111
112template <class Iterator1, class Iterator2>
113constexpr bool // constexpr in C++17
114operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
115
116template <class Iterator1, class Iterator2>
117constexpr bool // constexpr in C++17
118operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
119
120template <class Iterator1, class Iterator2>
121constexpr bool // constexpr in C++17
122operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
123
124template <class Iterator1, class Iterator2>
125constexpr bool // constexpr in C++17
126operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
127
128template <class Iterator1, class Iterator2>
129constexpr bool // constexpr in C++17
130operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
131
132template <class Iterator1, class Iterator2>
133constexpr auto
134operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
135-> decltype(__y.base() - __x.base()); // constexpr in C++17
136
137template <class Iterator>
138constexpr reverse_iterator<Iterator>
139operator+(typename reverse_iterator<Iterator>::difference_type n,
140 const reverse_iterator<Iterator>& x); // constexpr in C++17
141
142template <class Iterator>
143constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
144
145template <class Container>
146class back_insert_iterator
147{
148protected:
149 Container* container;
150public:
151 typedef Container container_type;
152 typedef void value_type;
153 typedef void difference_type;
154 typedef void reference;
155 typedef void pointer;
156
157 explicit back_insert_iterator(Container& x);
158 back_insert_iterator& operator=(const typename Container::value_type& value);
159 back_insert_iterator& operator*();
160 back_insert_iterator& operator++();
161 back_insert_iterator operator++(int);
162};
163
164template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
165
166template <class Container>
167class front_insert_iterator
168{
169protected:
170 Container* container;
171public:
172 typedef Container container_type;
173 typedef void value_type;
174 typedef void difference_type;
175 typedef void reference;
176 typedef void pointer;
177
178 explicit front_insert_iterator(Container& x);
179 front_insert_iterator& operator=(const typename Container::value_type& value);
180 front_insert_iterator& operator*();
181 front_insert_iterator& operator++();
182 front_insert_iterator operator++(int);
183};
184
185template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
186
187template <class Container>
188class insert_iterator
189{
190protected:
191 Container* container;
192 typename Container::iterator iter;
193public:
194 typedef Container container_type;
195 typedef void value_type;
196 typedef void difference_type;
197 typedef void reference;
198 typedef void pointer;
199
200 insert_iterator(Container& x, typename Container::iterator i);
201 insert_iterator& operator=(const typename Container::value_type& value);
202 insert_iterator& operator*();
203 insert_iterator& operator++();
204 insert_iterator& operator++(int);
205};
206
207template <class Container, class Iterator>
208insert_iterator<Container> inserter(Container& x, Iterator i);
209
210template <class Iterator>
211class move_iterator {
212public:
213 typedef Iterator iterator_type;
214 typedef typename iterator_traits<Iterator>::difference_type difference_type;
215 typedef Iterator pointer;
216 typedef typename iterator_traits<Iterator>::value_type value_type;
217 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
218 typedef value_type&& reference;
219
220 constexpr move_iterator(); // all the constexprs are in C++17
221 constexpr explicit move_iterator(Iterator i);
222 template <class U>
223 constexpr move_iterator(const move_iterator<U>& u);
224 template <class U>
225 constexpr move_iterator& operator=(const move_iterator<U>& u);
226 constexpr iterator_type base() const;
227 constexpr reference operator*() const;
228 constexpr pointer operator->() const;
229 constexpr move_iterator& operator++();
230 constexpr move_iterator operator++(int);
231 constexpr move_iterator& operator--();
232 constexpr move_iterator operator--(int);
233 constexpr move_iterator operator+(difference_type n) const;
234 constexpr move_iterator& operator+=(difference_type n);
235 constexpr move_iterator operator-(difference_type n) const;
236 constexpr move_iterator& operator-=(difference_type n);
237 constexpr unspecified operator[](difference_type n) const;
238private:
239 Iterator current; // exposition only
240};
241
242template <class Iterator1, class Iterator2>
243constexpr bool // constexpr in C++17
244operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
245
246template <class Iterator1, class Iterator2>
247constexpr bool // constexpr in C++17
248operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
249
250template <class Iterator1, class Iterator2>
251constexpr bool // constexpr in C++17
252operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
253
254template <class Iterator1, class Iterator2>
255constexpr bool // constexpr in C++17
256operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
257
258template <class Iterator1, class Iterator2>
259constexpr bool // constexpr in C++17
260operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
261
262template <class Iterator1, class Iterator2>
263constexpr bool // constexpr in C++17
264operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
265
266template <class Iterator1, class Iterator2>
267constexpr auto // constexpr in C++17
268operator-(const move_iterator<Iterator1>& x,
269 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
270
271template <class Iterator>
272constexpr move_iterator<Iterator> operator+( // constexpr in C++17
273 typename move_iterator<Iterator>::difference_type n,
274 const move_iterator<Iterator>& x);
275
276template <class Iterator> // constexpr in C++17
277constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
278
279
280template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
281class istream_iterator
282 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
283{
284public:
285 typedef charT char_type;
286 typedef traits traits_type;
287 typedef basic_istream<charT,traits> istream_type;
288
289 constexpr istream_iterator();
290 istream_iterator(istream_type& s);
291 istream_iterator(const istream_iterator& x);
292 ~istream_iterator();
293
294 const T& operator*() const;
295 const T* operator->() const;
296 istream_iterator& operator++();
297 istream_iterator operator++(int);
298};
299
300template <class T, class charT, class traits, class Distance>
301bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
302 const istream_iterator<T,charT,traits,Distance>& y);
303template <class T, class charT, class traits, class Distance>
304bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
305 const istream_iterator<T,charT,traits,Distance>& y);
306
307template <class T, class charT = char, class traits = char_traits<charT> >
308class ostream_iterator
309 : public iterator<output_iterator_tag, void, void, void ,void>
310{
311public:
312 typedef charT char_type;
313 typedef traits traits_type;
314 typedef basic_ostream<charT,traits> ostream_type;
315
316 ostream_iterator(ostream_type& s);
317 ostream_iterator(ostream_type& s, const charT* delimiter);
318 ostream_iterator(const ostream_iterator& x);
319 ~ostream_iterator();
320 ostream_iterator& operator=(const T& value);
321
322 ostream_iterator& operator*();
323 ostream_iterator& operator++();
324 ostream_iterator& operator++(int);
325};
326
327template<class charT, class traits = char_traits<charT> >
328class istreambuf_iterator
329 : public iterator<input_iterator_tag, charT,
330 typename traits::off_type, unspecified,
331 charT>
332{
333public:
334 typedef charT char_type;
335 typedef traits traits_type;
336 typedef typename traits::int_type int_type;
337 typedef basic_streambuf<charT,traits> streambuf_type;
338 typedef basic_istream<charT,traits> istream_type;
339
340 istreambuf_iterator() noexcept;
341 istreambuf_iterator(istream_type& s) noexcept;
342 istreambuf_iterator(streambuf_type* s) noexcept;
343 istreambuf_iterator(a-private-type) noexcept;
344
345 charT operator*() const;
346 pointer operator->() const;
347 istreambuf_iterator& operator++();
348 a-private-type operator++(int);
349
350 bool equal(const istreambuf_iterator& b) const;
351};
352
353template <class charT, class traits>
354bool operator==(const istreambuf_iterator<charT,traits>& a,
355 const istreambuf_iterator<charT,traits>& b);
356template <class charT, class traits>
357bool operator!=(const istreambuf_iterator<charT,traits>& a,
358 const istreambuf_iterator<charT,traits>& b);
359
360template <class charT, class traits = char_traits<charT> >
361class ostreambuf_iterator
362 : public iterator<output_iterator_tag, void, void, void, void>
363{
364public:
365 typedef charT char_type;
366 typedef traits traits_type;
367 typedef basic_streambuf<charT,traits> streambuf_type;
368 typedef basic_ostream<charT,traits> ostream_type;
369
370 ostreambuf_iterator(ostream_type& s) noexcept;
371 ostreambuf_iterator(streambuf_type* s) noexcept;
372 ostreambuf_iterator& operator=(charT c);
373 ostreambuf_iterator& operator*();
374 ostreambuf_iterator& operator++();
375 ostreambuf_iterator& operator++(int);
376 bool failed() const noexcept;
377};
378
379template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
380template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
381template <class C> constexpr auto end(C& c) -> decltype(c.end());
382template <class C> constexpr auto end(const C& c) -> decltype(c.end());
383template <class T, size_t N> constexpr T* begin(T (&array)[N]);
384template <class T, size_t N> constexpr T* end(T (&array)[N]);
385
386template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
387template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
388template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
389template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
390template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
391template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
392template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
393template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
394template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
395template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
396template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
397template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
398
399// 24.8, container access:
400template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
401template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
402template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
403template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
404template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
405template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
406template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
407template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
408template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
409
410} // std
411
412*/
413
414#include <__config>
415#include <iosfwd> // for forward declarations of vector and string.
416#include <__functional_base>
417#include <type_traits>
418#include <cstddef>
419#include <initializer_list>
Andrew Scull0372a572018-11-16 15:47:06 +0000420#include <version>
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100421#ifdef __APPLE__
422#include <Availability.h>
423#endif
424
425#include <__debug>
426
427#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
428#pragma GCC system_header
429#endif
430
431_LIBCPP_BEGIN_NAMESPACE_STD
432
433struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
434struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
435struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
436struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
437struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
438
439template <class _Tp>
Andrew Walbran16937d02019-10-22 13:54:20 +0100440struct __has_iterator_typedefs
441{
442private:
443 struct __two {char __lx; char __lxx;};
444 template <class _Up> static __two __test(...);
445 template <class _Up> static char __test(typename std::__void_t<typename _Up::iterator_category>::type* = 0,
446 typename std::__void_t<typename _Up::difference_type>::type* = 0,
447 typename std::__void_t<typename _Up::value_type>::type* = 0,
448 typename std::__void_t<typename _Up::reference>::type* = 0,
449 typename std::__void_t<typename _Up::pointer>::type* = 0
450 );
451public:
452 static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1;
453};
454
455
456template <class _Tp>
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100457struct __has_iterator_category
458{
459private:
460 struct __two {char __lx; char __lxx;};
461 template <class _Up> static __two __test(...);
462 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
463public:
464 static const bool value = sizeof(__test<_Tp>(0)) == 1;
465};
466
467template <class _Iter, bool> struct __iterator_traits_impl {};
468
469template <class _Iter>
470struct __iterator_traits_impl<_Iter, true>
471{
472 typedef typename _Iter::difference_type difference_type;
473 typedef typename _Iter::value_type value_type;
474 typedef typename _Iter::pointer pointer;
475 typedef typename _Iter::reference reference;
476 typedef typename _Iter::iterator_category iterator_category;
477};
478
479template <class _Iter, bool> struct __iterator_traits {};
480
481template <class _Iter>
482struct __iterator_traits<_Iter, true>
483 : __iterator_traits_impl
484 <
485 _Iter,
486 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
487 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
488 >
489{};
490
491// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
492// exists. Else iterator_traits<Iterator> will be an empty class. This is a
493// conforming extension which allows some programs to compile and behave as
494// the client expects instead of failing at compile time.
495
496template <class _Iter>
497struct _LIBCPP_TEMPLATE_VIS iterator_traits
Andrew Walbran16937d02019-10-22 13:54:20 +0100498 : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {};
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100499
500template<class _Tp>
501struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
502{
503 typedef ptrdiff_t difference_type;
504 typedef typename remove_cv<_Tp>::type value_type;
505 typedef _Tp* pointer;
506 typedef _Tp& reference;
507 typedef random_access_iterator_tag iterator_category;
508};
509
510template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
511struct __has_iterator_category_convertible_to
512 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
513{};
514
515template <class _Tp, class _Up>
516struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
517
518template <class _Tp>
519struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
520
521template <class _Tp>
522struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
523
524template <class _Tp>
525struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
526
527template <class _Tp>
528struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
529
530template <class _Tp>
531struct __is_exactly_input_iterator
532 : public integral_constant<bool,
533 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
534 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
535
536template<class _Category, class _Tp, class _Distance = ptrdiff_t,
537 class _Pointer = _Tp*, class _Reference = _Tp&>
538struct _LIBCPP_TEMPLATE_VIS iterator
539{
540 typedef _Tp value_type;
541 typedef _Distance difference_type;
542 typedef _Pointer pointer;
543 typedef _Reference reference;
544 typedef _Category iterator_category;
545};
546
547template <class _InputIter>
548inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
549void __advance(_InputIter& __i,
550 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
551{
552 for (; __n > 0; --__n)
553 ++__i;
554}
555
556template <class _BiDirIter>
557inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
558void __advance(_BiDirIter& __i,
559 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
560{
561 if (__n >= 0)
562 for (; __n > 0; --__n)
563 ++__i;
564 else
565 for (; __n < 0; ++__n)
566 --__i;
567}
568
569template <class _RandIter>
570inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
571void __advance(_RandIter& __i,
572 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
573{
574 __i += __n;
575}
576
577template <class _InputIter>
578inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
579void advance(_InputIter& __i,
580 typename iterator_traits<_InputIter>::difference_type __n)
581{
582 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
583}
584
585template <class _InputIter>
586inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
587typename iterator_traits<_InputIter>::difference_type
588__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
589{
590 typename iterator_traits<_InputIter>::difference_type __r(0);
591 for (; __first != __last; ++__first)
592 ++__r;
593 return __r;
594}
595
596template <class _RandIter>
597inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
598typename iterator_traits<_RandIter>::difference_type
599__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
600{
601 return __last - __first;
602}
603
604template <class _InputIter>
605inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
606typename iterator_traits<_InputIter>::difference_type
607distance(_InputIter __first, _InputIter __last)
608{
609 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
610}
611
612template <class _InputIter>
613inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
614typename enable_if
615<
616 __is_input_iterator<_InputIter>::value,
617 _InputIter
618>::type
619next(_InputIter __x,
620 typename iterator_traits<_InputIter>::difference_type __n = 1)
621{
622 _VSTD::advance(__x, __n);
623 return __x;
624}
625
626template <class _BidirectionalIter>
627inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
628typename enable_if
629<
630 __is_bidirectional_iterator<_BidirectionalIter>::value,
631 _BidirectionalIter
632>::type
633prev(_BidirectionalIter __x,
634 typename iterator_traits<_BidirectionalIter>::difference_type __n = 1)
635{
636 _VSTD::advance(__x, -__n);
637 return __x;
638}
639
640
641template <class _Tp, class = void>
642struct __is_stashing_iterator : false_type {};
643
644template <class _Tp>
645struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
646 : true_type {};
647
648template <class _Iter>
649class _LIBCPP_TEMPLATE_VIS reverse_iterator
650 : public iterator<typename iterator_traits<_Iter>::iterator_category,
651 typename iterator_traits<_Iter>::value_type,
652 typename iterator_traits<_Iter>::difference_type,
653 typename iterator_traits<_Iter>::pointer,
654 typename iterator_traits<_Iter>::reference>
655{
656private:
657 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
658
659 static_assert(!__is_stashing_iterator<_Iter>::value,
660 "The specified iterator type cannot be used with reverse_iterator; "
661 "Using stashing iterators with reverse_iterator causes undefined behavior");
662
663protected:
664 _Iter current;
665public:
666 typedef _Iter iterator_type;
667 typedef typename iterator_traits<_Iter>::difference_type difference_type;
668 typedef typename iterator_traits<_Iter>::reference reference;
669 typedef typename iterator_traits<_Iter>::pointer pointer;
670
671 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
672 reverse_iterator() : __t(), current() {}
673 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
674 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
675 template <class _Up>
676 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
677 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
678 template <class _Up>
679 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
680 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
681 { __t = current = __u.base(); return *this; }
682 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
683 _Iter base() const {return current;}
684 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
685 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
686 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
687 pointer operator->() const {return _VSTD::addressof(operator*());}
688 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
689 reverse_iterator& operator++() {--current; return *this;}
690 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
691 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
692 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
693 reverse_iterator& operator--() {++current; return *this;}
694 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
695 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
696 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
697 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
698 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
699 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
700 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
701 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
702 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
703 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
704 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
705 reference operator[](difference_type __n) const {return *(*this + __n);}
706};
707
708template <class _Iter1, class _Iter2>
709inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
710bool
711operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
712{
713 return __x.base() == __y.base();
714}
715
716template <class _Iter1, class _Iter2>
717inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
718bool
719operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
720{
721 return __x.base() > __y.base();
722}
723
724template <class _Iter1, class _Iter2>
725inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
726bool
727operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
728{
729 return __x.base() != __y.base();
730}
731
732template <class _Iter1, class _Iter2>
733inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
734bool
735operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
736{
737 return __x.base() < __y.base();
738}
739
740template <class _Iter1, class _Iter2>
741inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
742bool
743operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
744{
745 return __x.base() <= __y.base();
746}
747
748template <class _Iter1, class _Iter2>
749inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
750bool
751operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
752{
753 return __x.base() >= __y.base();
754}
755
756#ifndef _LIBCPP_CXX03_LANG
757template <class _Iter1, class _Iter2>
758inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
759auto
760operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
761-> decltype(__y.base() - __x.base())
762{
763 return __y.base() - __x.base();
764}
765#else
766template <class _Iter1, class _Iter2>
767inline _LIBCPP_INLINE_VISIBILITY
768typename reverse_iterator<_Iter1>::difference_type
769operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
770{
771 return __y.base() - __x.base();
772}
773#endif
774
775template <class _Iter>
776inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
777reverse_iterator<_Iter>
778operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
779{
780 return reverse_iterator<_Iter>(__x.base() - __n);
781}
782
783#if _LIBCPP_STD_VER > 11
784template <class _Iter>
785inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
786reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
787{
788 return reverse_iterator<_Iter>(__i);
789}
790#endif
791
792template <class _Container>
793class _LIBCPP_TEMPLATE_VIS back_insert_iterator
794 : public iterator<output_iterator_tag,
795 void,
796 void,
797 void,
798 void>
799{
800protected:
801 _Container* container;
802public:
803 typedef _Container container_type;
804
805 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
806 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
807 {container->push_back(__value_); return *this;}
808#ifndef _LIBCPP_CXX03_LANG
809 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
810 {container->push_back(_VSTD::move(__value_)); return *this;}
811#endif // _LIBCPP_CXX03_LANG
812 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
813 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
814 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
815};
816
817template <class _Container>
818inline _LIBCPP_INLINE_VISIBILITY
819back_insert_iterator<_Container>
820back_inserter(_Container& __x)
821{
822 return back_insert_iterator<_Container>(__x);
823}
824
825template <class _Container>
826class _LIBCPP_TEMPLATE_VIS front_insert_iterator
827 : public iterator<output_iterator_tag,
828 void,
829 void,
830 void,
831 void>
832{
833protected:
834 _Container* container;
835public:
836 typedef _Container container_type;
837
838 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
839 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
840 {container->push_front(__value_); return *this;}
841#ifndef _LIBCPP_CXX03_LANG
842 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
843 {container->push_front(_VSTD::move(__value_)); return *this;}
844#endif // _LIBCPP_CXX03_LANG
845 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
846 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
847 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
848};
849
850template <class _Container>
851inline _LIBCPP_INLINE_VISIBILITY
852front_insert_iterator<_Container>
853front_inserter(_Container& __x)
854{
855 return front_insert_iterator<_Container>(__x);
856}
857
858template <class _Container>
859class _LIBCPP_TEMPLATE_VIS insert_iterator
860 : public iterator<output_iterator_tag,
861 void,
862 void,
863 void,
864 void>
865{
866protected:
867 _Container* container;
868 typename _Container::iterator iter;
869public:
870 typedef _Container container_type;
871
872 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
873 : container(_VSTD::addressof(__x)), iter(__i) {}
874 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
875 {iter = container->insert(iter, __value_); ++iter; return *this;}
876#ifndef _LIBCPP_CXX03_LANG
877 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
878 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
879#endif // _LIBCPP_CXX03_LANG
880 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
881 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
882 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
883};
884
885template <class _Container>
886inline _LIBCPP_INLINE_VISIBILITY
887insert_iterator<_Container>
888inserter(_Container& __x, typename _Container::iterator __i)
889{
890 return insert_iterator<_Container>(__x, __i);
891}
892
893template <class _Tp, class _CharT = char,
894 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
895class _LIBCPP_TEMPLATE_VIS istream_iterator
896 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
897{
898public:
899 typedef _CharT char_type;
900 typedef _Traits traits_type;
901 typedef basic_istream<_CharT,_Traits> istream_type;
902private:
903 istream_type* __in_stream_;
904 _Tp __value_;
905public:
906 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
907 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
908 {
909 if (!(*__in_stream_ >> __value_))
910 __in_stream_ = 0;
911 }
912
913 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
914 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
915 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
916 {
917 if (!(*__in_stream_ >> __value_))
918 __in_stream_ = 0;
919 return *this;
920 }
921 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
922 {istream_iterator __t(*this); ++(*this); return __t;}
923
924 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
925 friend _LIBCPP_INLINE_VISIBILITY
926 bool
927 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
928 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
929
930 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
931 friend _LIBCPP_INLINE_VISIBILITY
932 bool
933 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
934 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
935};
936
937template <class _Tp, class _CharT, class _Traits, class _Distance>
938inline _LIBCPP_INLINE_VISIBILITY
939bool
940operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
941 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
942{
943 return __x.__in_stream_ == __y.__in_stream_;
944}
945
946template <class _Tp, class _CharT, class _Traits, class _Distance>
947inline _LIBCPP_INLINE_VISIBILITY
948bool
949operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
950 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
951{
952 return !(__x == __y);
953}
954
955template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
956class _LIBCPP_TEMPLATE_VIS ostream_iterator
957 : public iterator<output_iterator_tag, void, void, void, void>
958{
959public:
960 typedef _CharT char_type;
961 typedef _Traits traits_type;
962 typedef basic_ostream<_CharT,_Traits> ostream_type;
963private:
964 ostream_type* __out_stream_;
965 const char_type* __delim_;
966public:
967 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
968 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
969 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
970 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
971 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
972 {
973 *__out_stream_ << __value_;
974 if (__delim_)
975 *__out_stream_ << __delim_;
976 return *this;
977 }
978
979 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
980 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
981 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
982};
983
984template<class _CharT, class _Traits>
985class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
986 : public iterator<input_iterator_tag, _CharT,
987 typename _Traits::off_type, _CharT*,
988 _CharT>
989{
990public:
991 typedef _CharT char_type;
992 typedef _Traits traits_type;
993 typedef typename _Traits::int_type int_type;
994 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
995 typedef basic_istream<_CharT,_Traits> istream_type;
996private:
997 mutable streambuf_type* __sbuf_;
998
999 class __proxy
1000 {
1001 char_type __keep_;
1002 streambuf_type* __sbuf_;
1003 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
1004 : __keep_(__c), __sbuf_(__s) {}
1005 friend class istreambuf_iterator;
1006 public:
1007 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
1008 };
1009
1010 _LIBCPP_INLINE_VISIBILITY
1011 bool __test_for_eof() const
1012 {
1013 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
1014 __sbuf_ = 0;
1015 return __sbuf_ == 0;
1016 }
1017public:
1018 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
1019 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
1020 : __sbuf_(__s.rdbuf()) {}
1021 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1022 : __sbuf_(__s) {}
1023 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
1024 : __sbuf_(__p.__sbuf_) {}
1025
1026 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1027 {return static_cast<char_type>(__sbuf_->sgetc());}
1028 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1029 {
1030 __sbuf_->sbumpc();
1031 return *this;
1032 }
1033 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1034 {
1035 return __proxy(__sbuf_->sbumpc(), __sbuf_);
1036 }
1037
1038 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1039 {return __test_for_eof() == __b.__test_for_eof();}
1040};
1041
1042template <class _CharT, class _Traits>
1043inline _LIBCPP_INLINE_VISIBILITY
1044bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1045 const istreambuf_iterator<_CharT,_Traits>& __b)
1046 {return __a.equal(__b);}
1047
1048template <class _CharT, class _Traits>
1049inline _LIBCPP_INLINE_VISIBILITY
1050bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1051 const istreambuf_iterator<_CharT,_Traits>& __b)
1052 {return !__a.equal(__b);}
1053
1054template <class _CharT, class _Traits>
1055class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
1056 : public iterator<output_iterator_tag, void, void, void, void>
1057{
1058public:
1059 typedef _CharT char_type;
1060 typedef _Traits traits_type;
1061 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1062 typedef basic_ostream<_CharT,_Traits> ostream_type;
1063private:
1064 streambuf_type* __sbuf_;
1065public:
1066 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
1067 : __sbuf_(__s.rdbuf()) {}
1068 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1069 : __sbuf_(__s) {}
1070 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1071 {
1072 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1073 __sbuf_ = 0;
1074 return *this;
1075 }
1076 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1077 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1078 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1079 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
1080
1081#if !defined(__APPLE__) || \
1082 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1083 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1084
1085 template <class _Ch, class _Tr>
1086 friend
1087 _LIBCPP_HIDDEN
1088 ostreambuf_iterator<_Ch, _Tr>
1089 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1090 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1091 ios_base& __iob, _Ch __fl);
1092#endif
1093};
1094
1095template <class _Iter>
1096class _LIBCPP_TEMPLATE_VIS move_iterator
1097{
1098private:
1099 _Iter __i;
1100public:
1101 typedef _Iter iterator_type;
1102 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1103 typedef typename iterator_traits<iterator_type>::value_type value_type;
1104 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1105 typedef iterator_type pointer;
1106#ifndef _LIBCPP_CXX03_LANG
1107 typedef typename iterator_traits<iterator_type>::reference __reference;
1108 typedef typename conditional<
1109 is_reference<__reference>::value,
1110 typename remove_reference<__reference>::type&&,
1111 __reference
1112 >::type reference;
1113#else
1114 typedef typename iterator_traits<iterator_type>::reference reference;
1115#endif
1116
1117 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1118 move_iterator() : __i() {}
1119 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1120 explicit move_iterator(_Iter __x) : __i(__x) {}
1121 template <class _Up>
1122 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1123 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1124 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1125 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1126 reference operator*() const { return static_cast<reference>(*__i); }
1127 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1128 pointer operator->() const { return __i;}
1129 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1130 move_iterator& operator++() {++__i; return *this;}
1131 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1132 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1133 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1134 move_iterator& operator--() {--__i; return *this;}
1135 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1136 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1137 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1138 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1139 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1140 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1141 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1142 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1143 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1144 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1145 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1146 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
1147};
1148
1149template <class _Iter1, class _Iter2>
1150inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1151bool
1152operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1153{
1154 return __x.base() == __y.base();
1155}
1156
1157template <class _Iter1, class _Iter2>
1158inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1159bool
1160operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1161{
1162 return __x.base() < __y.base();
1163}
1164
1165template <class _Iter1, class _Iter2>
1166inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1167bool
1168operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1169{
1170 return __x.base() != __y.base();
1171}
1172
1173template <class _Iter1, class _Iter2>
1174inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1175bool
1176operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1177{
1178 return __x.base() > __y.base();
1179}
1180
1181template <class _Iter1, class _Iter2>
1182inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1183bool
1184operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1185{
1186 return __x.base() >= __y.base();
1187}
1188
1189template <class _Iter1, class _Iter2>
1190inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1191bool
1192operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1193{
1194 return __x.base() <= __y.base();
1195}
1196
1197#ifndef _LIBCPP_CXX03_LANG
1198template <class _Iter1, class _Iter2>
1199inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1200auto
1201operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1202-> decltype(__x.base() - __y.base())
1203{
1204 return __x.base() - __y.base();
1205}
1206#else
1207template <class _Iter1, class _Iter2>
1208inline _LIBCPP_INLINE_VISIBILITY
1209typename move_iterator<_Iter1>::difference_type
1210operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1211{
1212 return __x.base() - __y.base();
1213}
1214#endif
1215
1216template <class _Iter>
1217inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1218move_iterator<_Iter>
1219operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1220{
1221 return move_iterator<_Iter>(__x.base() + __n);
1222}
1223
1224template <class _Iter>
1225inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1226move_iterator<_Iter>
1227make_move_iterator(_Iter __i)
1228{
1229 return move_iterator<_Iter>(__i);
1230}
1231
1232// __wrap_iter
1233
1234template <class _Iter> class __wrap_iter;
1235
1236template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001237_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001238bool
1239operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1240
1241template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001242_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001243bool
1244operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1245
1246template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001247_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001248bool
1249operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1250
1251template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001252_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001253bool
1254operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1255
1256template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001257_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001258bool
1259operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1260
1261template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001262_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001263bool
1264operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1265
1266#ifndef _LIBCPP_CXX03_LANG
1267template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001268_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001269auto
1270operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1271-> decltype(__x.base() - __y.base());
1272#else
1273template <class _Iter1, class _Iter2>
1274_LIBCPP_INLINE_VISIBILITY
1275typename __wrap_iter<_Iter1>::difference_type
1276operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1277#endif
1278
1279template <class _Iter>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001280_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001281__wrap_iter<_Iter>
1282operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG;
1283
1284template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1285template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1286template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1287template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
1288
1289#if _LIBCPP_DEBUG_LEVEL < 2
1290
1291template <class _Tp>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001292_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001293typename enable_if
1294<
1295 is_trivially_copy_assignable<_Tp>::value,
1296 _Tp*
1297>::type
1298__unwrap_iter(__wrap_iter<_Tp*>);
1299
1300#else
1301
1302template <class _Tp>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001303inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001304typename enable_if
1305<
1306 is_trivially_copy_assignable<_Tp>::value,
1307 __wrap_iter<_Tp*>
1308>::type
1309__unwrap_iter(__wrap_iter<_Tp*> __i);
1310
1311#endif
1312
1313template <class _Iter>
1314class __wrap_iter
1315{
1316public:
1317 typedef _Iter iterator_type;
1318 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1319 typedef typename iterator_traits<iterator_type>::value_type value_type;
1320 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1321 typedef typename iterator_traits<iterator_type>::pointer pointer;
1322 typedef typename iterator_traits<iterator_type>::reference reference;
1323private:
1324 iterator_type __i;
1325public:
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001326 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001327#if _LIBCPP_STD_VER > 11
1328 : __i{}
1329#endif
1330 {
1331#if _LIBCPP_DEBUG_LEVEL >= 2
1332 __get_db()->__insert_i(this);
1333#endif
1334 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001335 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1336 __wrap_iter(const __wrap_iter<_Up>& __u,
1337 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG
1338 : __i(__u.base())
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001339 {
1340#if _LIBCPP_DEBUG_LEVEL >= 2
1341 __get_db()->__iterator_copy(this, &__u);
1342#endif
1343 }
1344#if _LIBCPP_DEBUG_LEVEL >= 2
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001345 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001346 __wrap_iter(const __wrap_iter& __x)
1347 : __i(__x.base())
1348 {
1349 __get_db()->__iterator_copy(this, &__x);
1350 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001351 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001352 __wrap_iter& operator=(const __wrap_iter& __x)
1353 {
1354 if (this != &__x)
1355 {
1356 __get_db()->__iterator_copy(this, &__x);
1357 __i = __x.__i;
1358 }
1359 return *this;
1360 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001361 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001362 ~__wrap_iter()
1363 {
1364 __get_db()->__erase_i(this);
1365 }
1366#endif
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001367 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001368 {
1369#if _LIBCPP_DEBUG_LEVEL >= 2
1370 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1371 "Attempted to dereference a non-dereferenceable iterator");
1372#endif
1373 return *__i;
1374 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001375 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001376 {
1377#if _LIBCPP_DEBUG_LEVEL >= 2
1378 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1379 "Attempted to dereference a non-dereferenceable iterator");
1380#endif
1381 return (pointer)_VSTD::addressof(*__i);
1382 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001383 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001384 {
1385#if _LIBCPP_DEBUG_LEVEL >= 2
1386 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1387 "Attempted to increment non-incrementable iterator");
1388#endif
1389 ++__i;
1390 return *this;
1391 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001392 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001393 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001394
1395 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001396 {
1397#if _LIBCPP_DEBUG_LEVEL >= 2
1398 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1399 "Attempted to decrement non-decrementable iterator");
1400#endif
1401 --__i;
1402 return *this;
1403 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001404 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001405 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001406 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001407 {__wrap_iter __w(*this); __w += __n; return __w;}
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001409 {
1410#if _LIBCPP_DEBUG_LEVEL >= 2
1411 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1412 "Attempted to add/subtract iterator outside of valid range");
1413#endif
1414 __i += __n;
1415 return *this;
1416 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001417 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001418 {return *this + (-__n);}
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001419 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001420 {*this += -__n; return *this;}
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001421 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT_DEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001422 {
1423#if _LIBCPP_DEBUG_LEVEL >= 2
1424 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1425 "Attempted to subscript iterator outside of valid range");
1426#endif
1427 return __i[__n];
1428 }
1429
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001430 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT_DEBUG {return __i;}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001431
1432private:
1433#if _LIBCPP_DEBUG_LEVEL >= 2
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001434 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001435 {
1436 __get_db()->__insert_ic(this, __p);
1437 }
1438#else
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001439 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001440#endif
1441
1442 template <class _Up> friend class __wrap_iter;
1443 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1444 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001445 template <class _Tp, ptrdiff_t> friend class _LIBCPP_TEMPLATE_VIS span;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001446
1447 template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001448 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001449 bool
1450 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1451
1452 template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001453 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001454 bool
1455 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1456
1457 template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001458 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001459 bool
1460 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1461
1462 template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001463 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001464 bool
1465 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1466
1467 template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001468 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001469 bool
1470 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1471
1472 template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001473 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001474 bool
1475 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1476
1477#ifndef _LIBCPP_CXX03_LANG
1478 template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001479 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001480 auto
1481 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1482 -> decltype(__x.base() - __y.base());
1483#else
1484 template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001485 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001486 typename __wrap_iter<_Iter1>::difference_type
1487 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1488#endif
1489
1490 template <class _Iter1>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001491 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001492 __wrap_iter<_Iter1>
1493 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG;
1494
1495 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
1496 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
1497 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
1498 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1499
1500#if _LIBCPP_DEBUG_LEVEL < 2
1501 template <class _Tp>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001502 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001503 typename enable_if
1504 <
1505 is_trivially_copy_assignable<_Tp>::value,
1506 _Tp*
1507 >::type
1508 __unwrap_iter(__wrap_iter<_Tp*>);
1509#else
1510 template <class _Tp>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001511 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001512 typename enable_if
1513 <
1514 is_trivially_copy_assignable<_Tp>::value,
1515 __wrap_iter<_Tp*>
1516 >::type
1517 __unwrap_iter(__wrap_iter<_Tp*> __i);
1518#endif
1519};
1520
1521template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001522inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001523bool
1524operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1525{
1526 return __x.base() == __y.base();
1527}
1528
1529template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001530inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001531bool
1532operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1533{
1534#if _LIBCPP_DEBUG_LEVEL >= 2
1535 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1536 "Attempted to compare incomparable iterators");
1537#endif
1538 return __x.base() < __y.base();
1539}
1540
1541template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001542inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001543bool
1544operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1545{
1546 return !(__x == __y);
1547}
1548
1549template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001550inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001551bool
1552operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1553{
1554 return __y < __x;
1555}
1556
1557template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001558inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001559bool
1560operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1561{
1562 return !(__x < __y);
1563}
1564
1565template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001566inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001567bool
1568operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1569{
1570 return !(__y < __x);
1571}
1572
1573template <class _Iter1>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001574inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001575bool
1576operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1577{
1578 return !(__x == __y);
1579}
1580
1581template <class _Iter1>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001582inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001583bool
1584operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1585{
1586 return __y < __x;
1587}
1588
1589template <class _Iter1>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001590inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001591bool
1592operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1593{
1594 return !(__x < __y);
1595}
1596
1597template <class _Iter1>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001598inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001599bool
1600operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
1601{
1602 return !(__y < __x);
1603}
1604
1605#ifndef _LIBCPP_CXX03_LANG
1606template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001607inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001608auto
1609operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1610-> decltype(__x.base() - __y.base())
1611{
1612#if _LIBCPP_DEBUG_LEVEL >= 2
1613 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1614 "Attempted to subtract incompatible iterators");
1615#endif
1616 return __x.base() - __y.base();
1617}
1618#else
1619template <class _Iter1, class _Iter2>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001620inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001621typename __wrap_iter<_Iter1>::difference_type
1622operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1623{
1624#if _LIBCPP_DEBUG_LEVEL >= 2
1625 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1626 "Attempted to subtract incompatible iterators");
1627#endif
1628 return __x.base() - __y.base();
1629}
1630#endif
1631
1632template <class _Iter>
Andrew Scullcdfcccc2018-10-05 20:58:37 +01001633inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001634__wrap_iter<_Iter>
1635operator+(typename __wrap_iter<_Iter>::difference_type __n,
1636 __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG
1637{
1638 __x += __n;
1639 return __x;
1640}
1641
1642template <class _Iter>
1643struct __libcpp_is_trivial_iterator
1644 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1645
1646template <class _Iter>
1647struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
1648 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1649
1650template <class _Iter>
1651struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
1652 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1653
1654template <class _Iter>
1655struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
1656 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1657
1658
1659template <class _Tp, size_t _Np>
1660inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1661_Tp*
1662begin(_Tp (&__array)[_Np])
1663{
1664 return __array;
1665}
1666
1667template <class _Tp, size_t _Np>
1668inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1669_Tp*
1670end(_Tp (&__array)[_Np])
1671{
1672 return __array + _Np;
1673}
1674
1675#if !defined(_LIBCPP_CXX03_LANG)
1676
1677template <class _Cp>
1678inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1679auto
1680begin(_Cp& __c) -> decltype(__c.begin())
1681{
1682 return __c.begin();
1683}
1684
1685template <class _Cp>
1686inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1687auto
1688begin(const _Cp& __c) -> decltype(__c.begin())
1689{
1690 return __c.begin();
1691}
1692
1693template <class _Cp>
1694inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1695auto
1696end(_Cp& __c) -> decltype(__c.end())
1697{
1698 return __c.end();
1699}
1700
1701template <class _Cp>
1702inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1703auto
1704end(const _Cp& __c) -> decltype(__c.end())
1705{
1706 return __c.end();
1707}
1708
1709#if _LIBCPP_STD_VER > 11
1710
1711template <class _Tp, size_t _Np>
1712inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1713reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1714{
1715 return reverse_iterator<_Tp*>(__array + _Np);
1716}
1717
1718template <class _Tp, size_t _Np>
1719inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1720reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1721{
1722 return reverse_iterator<_Tp*>(__array);
1723}
1724
1725template <class _Ep>
1726inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1727reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1728{
1729 return reverse_iterator<const _Ep*>(__il.end());
1730}
1731
1732template <class _Ep>
1733inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1734reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1735{
1736 return reverse_iterator<const _Ep*>(__il.begin());
1737}
1738
1739template <class _Cp>
1740inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1741auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
1742{
1743 return _VSTD::begin(__c);
1744}
1745
1746template <class _Cp>
1747inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1748auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
1749{
1750 return _VSTD::end(__c);
1751}
1752
1753template <class _Cp>
1754inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1755auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1756{
1757 return __c.rbegin();
1758}
1759
1760template <class _Cp>
1761inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1762auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1763{
1764 return __c.rbegin();
1765}
1766
1767template <class _Cp>
1768inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1769auto rend(_Cp& __c) -> decltype(__c.rend())
1770{
1771 return __c.rend();
1772}
1773
1774template <class _Cp>
1775inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1776auto rend(const _Cp& __c) -> decltype(__c.rend())
1777{
1778 return __c.rend();
1779}
1780
1781template <class _Cp>
1782inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1783auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
1784{
1785 return _VSTD::rbegin(__c);
1786}
1787
1788template <class _Cp>
1789inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1790auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
1791{
1792 return _VSTD::rend(__c);
1793}
1794
1795#endif
1796
1797
1798#else // defined(_LIBCPP_CXX03_LANG)
1799
1800template <class _Cp>
1801inline _LIBCPP_INLINE_VISIBILITY
1802typename _Cp::iterator
1803begin(_Cp& __c)
1804{
1805 return __c.begin();
1806}
1807
1808template <class _Cp>
1809inline _LIBCPP_INLINE_VISIBILITY
1810typename _Cp::const_iterator
1811begin(const _Cp& __c)
1812{
1813 return __c.begin();
1814}
1815
1816template <class _Cp>
1817inline _LIBCPP_INLINE_VISIBILITY
1818typename _Cp::iterator
1819end(_Cp& __c)
1820{
1821 return __c.end();
1822}
1823
1824template <class _Cp>
1825inline _LIBCPP_INLINE_VISIBILITY
1826typename _Cp::const_iterator
1827end(const _Cp& __c)
1828{
1829 return __c.end();
1830}
1831
1832#endif // !defined(_LIBCPP_CXX03_LANG)
1833
1834#if _LIBCPP_STD_VER > 14
1835
1836// #if _LIBCPP_STD_VER > 11
1837// template <>
1838// struct _LIBCPP_TEMPLATE_VIS plus<void>
1839// {
1840// template <class _T1, class _T2>
1841// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1842// auto operator()(_T1&& __t, _T2&& __u) const
1843// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1844// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1845// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1846// typedef void is_transparent;
1847// };
1848// #endif
1849
1850template <class _Cont>
1851inline _LIBCPP_INLINE_VISIBILITY
1852constexpr auto size(const _Cont& __c)
1853_NOEXCEPT_(noexcept(__c.size()))
1854-> decltype (__c.size())
1855{ return __c.size(); }
1856
1857template <class _Tp, size_t _Sz>
1858inline _LIBCPP_INLINE_VISIBILITY
1859constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1860
1861template <class _Cont>
1862_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
1863constexpr auto empty(const _Cont& __c)
1864_NOEXCEPT_(noexcept(__c.empty()))
1865-> decltype (__c.empty())
1866{ return __c.empty(); }
1867
1868template <class _Tp, size_t _Sz>
1869_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
1870constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1871
1872template <class _Ep>
1873_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
1874constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1875
1876template <class _Cont> constexpr
1877inline _LIBCPP_INLINE_VISIBILITY
1878auto data(_Cont& __c)
1879_NOEXCEPT_(noexcept(__c.data()))
1880-> decltype (__c.data())
1881{ return __c.data(); }
1882
1883template <class _Cont> constexpr
1884inline _LIBCPP_INLINE_VISIBILITY
1885auto data(const _Cont& __c)
1886_NOEXCEPT_(noexcept(__c.data()))
1887-> decltype (__c.data())
1888{ return __c.data(); }
1889
1890template <class _Tp, size_t _Sz>
1891inline _LIBCPP_INLINE_VISIBILITY
1892constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1893
1894template <class _Ep>
1895inline _LIBCPP_INLINE_VISIBILITY
1896constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1897#endif
1898
1899
1900_LIBCPP_END_NAMESPACE_STD
1901
1902#endif // _LIBCPP_ITERATOR