blob: 70a664d99091d8e006bee0c6c16a09f42ac6a924 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_ITERATOR
12#define _LIBCPP_ITERATOR
13
14/*
15 iterator synopsis
16
17namespace std
18{
19
20template<class Iterator>
21struct iterator_traits
22{
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;
28};
29
30template<class T>
31struct iterator_traits<T*>
32{
33 typedef ptrdiff_t difference_type;
34 typedef T value_type;
35 typedef T* pointer;
36 typedef T& reference;
37 typedef random_access_iterator_tag iterator_category;
38};
39
40template<class T>
41struct iterator_traits<const T*>
42{
43 typedef ptrdiff_t difference_type;
44 typedef T value_type;
45 typedef const T* pointer;
46 typedef const T& reference;
47 typedef random_access_iterator_tag iterator_category;
48};
49
50template<class Category, class T, class Distance = ptrdiff_t,
51 class Pointer = T*, class Reference = T&>
52struct iterator
53{
54 typedef T value_type;
55 typedef Distance difference_type;
56 typedef Pointer pointer;
57 typedef Reference reference;
58 typedef Category iterator_category;
59};
60
61struct input_iterator_tag {};
62struct output_iterator_tag {};
63struct forward_iterator_tag : public input_iterator_tag {};
64struct bidirectional_iterator_tag : public forward_iterator_tag {};
65struct random_access_iterator_tag : public bidirectional_iterator_tag {};
66
67// extension: second argument not conforming to C++03
68template <class InputIterator>
69void advance(InputIterator& i,
70 typename iterator_traits<InputIterator>::difference_type n);
71
72template <class InputIterator>
73typename iterator_traits<InputIterator>::difference_type
74distance(InputIterator first, InputIterator last);
75
76template <class Iterator>
77class reverse_iterator
78 : public iterator<typename iterator_traits<Iterator>::iterator_category,
79 typename iterator_traits<Iterator>::value_type,
80 typename iterator_traits<Iterator>::difference_type,
81 typename iterator_traits<Iterator>::pointer,
82 typename iterator_traits<Iterator>::reference>
83{
84protected:
85 Iterator current;
86public:
87 typedef Iterator iterator_type;
88 typedef typename iterator_traits<Iterator>::difference_type difference_type;
89 typedef typename iterator_traits<Iterator>::reference reference;
90 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +000091
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092 reverse_iterator();
93 explicit reverse_iterator(Iterator x);
94 template <class U> reverse_iterator(const reverse_iterator<U>& u);
95 Iterator base() const;
96 reference operator*() const;
97 pointer operator->() const;
98 reverse_iterator& operator++();
99 reverse_iterator operator++(int);
100 reverse_iterator& operator--();
101 reverse_iterator operator--(int);
102 reverse_iterator operator+ (difference_type n) const;
103 reverse_iterator& operator+=(difference_type n);
104 reverse_iterator operator- (difference_type n) const;
105 reverse_iterator& operator-=(difference_type n);
106 reference operator[](difference_type n) const;
107};
108
109template <class Iterator1, class Iterator2>
110bool
111operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
112
113template <class Iterator1, class Iterator2>
114bool
115operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
116
117template <class Iterator1, class Iterator2>
118bool
119operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
120
121template <class Iterator1, class Iterator2>
122bool
123operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
124
125template <class Iterator1, class Iterator2>
126bool
127operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
128
129template <class Iterator1, class Iterator2>
130bool
131operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
132
133template <class Iterator1, class Iterator2>
134typename reverse_iterator<Iterator1>::difference_type
135operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
136
137template <class Iterator>
138reverse_iterator<Iterator>
139operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x);
140
141template <class Container>
142class back_insert_iterator
143{
144protected:
145 Container* container;
146public:
147 typedef Container container_type;
148 typedef void value_type;
149 typedef void difference_type;
150 typedef back_insert_iterator<Cont>& reference;
151 typedef void pointer;
152
153 explicit back_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000154 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155 back_insert_iterator& operator*();
156 back_insert_iterator& operator++();
157 back_insert_iterator operator++(int);
158};
159
160template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
161
162template <class Container>
163class front_insert_iterator
164{
165protected:
166 Container* container;
167public:
168 typedef Container container_type;
169 typedef void value_type;
170 typedef void difference_type;
171 typedef front_insert_iterator<Cont>& reference;
172 typedef void pointer;
173
174 explicit front_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000175 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176 front_insert_iterator& operator*();
177 front_insert_iterator& operator++();
178 front_insert_iterator operator++(int);
179};
180
181template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
182
183template <class Container>
184class insert_iterator
185{
186protected:
187 Container* container;
188 typename Container::iterator iter;
189public:
190 typedef Container container_type;
191 typedef void value_type;
192 typedef void difference_type;
193 typedef insert_iterator<Cont>& reference;
194 typedef void pointer;
195
196 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant45f57172010-09-14 20:26:27 +0000197 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198 insert_iterator& operator*();
199 insert_iterator& operator++();
200 insert_iterator& operator++(int);
201};
202
203template <class Container, class Iterator>
204insert_iterator<Container> inserter(Container& x, Iterator i);
205
206template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
207class istream_iterator
208 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
209{
210public:
211 typedef charT char_type;
212 typedef traits traits_type;
213 typedef basic_istream<charT,traits> istream_type;
214
215 istream_iterator();
216 istream_iterator(istream_type& s);
217 istream_iterator(const istream_iterator& x);
218 ~istream_iterator();
219
220 const T& operator*() const;
221 const T* operator->() const;
222 istream_iterator& operator++();
223 istream_iterator operator++(int);
224};
225
226template <class T, class charT, class traits, class Distance>
227bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
228 const istream_iterator<T,charT,traits,Distance>& y);
229template <class T, class charT, class traits, class Distance>
230bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
231 const istream_iterator<T,charT,traits,Distance>& y);
232
233template <class T, class charT = char, class traits = char_traits<charT> >
234class ostream_iterator
235 : public iterator<output_iterator_tag, void, void, void ,void>
236{
237public:
238 typedef charT char_type;
239 typedef traits traits_type;
240 typedef basic_ostream<charT,traits> ostream_type;
241
242 ostream_iterator(ostream_type& s);
243 ostream_iterator(ostream_type& s, const charT* delimiter);
244 ostream_iterator(const ostream_iterator& x);
245 ~ostream_iterator();
246 ostream_iterator& operator=(const T& value);
247
248 ostream_iterator& operator*();
249 ostream_iterator& operator++();
250 ostream_iterator& operator++(int);
251};
252
253template<class charT, class traits = char_traits<charT> >
254class istreambuf_iterator
255 : public iterator<input_iterator_tag, charT,
256 typename traits::off_type, unspecified,
257 charT>
258{
259public:
260 typedef charT char_type;
261 typedef traits traits_type;
262 typedef typename traits::int_type int_type;
263 typedef basic_streambuf<charT,traits> streambuf_type;
264 typedef basic_istream<charT,traits> istream_type;
265
Howard Hinnantd06a6402012-07-20 19:36:34 +0000266 istreambuf_iterator() noexcept;
267 istreambuf_iterator(istream_type& s) noexcept;
268 istreambuf_iterator(streambuf_type* s) noexcept;
269 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270
271 charT operator*() const;
272 pointer operator->() const;
273 istreambuf_iterator& operator++();
274 a-private-type operator++(int);
275
276 bool equal(const istreambuf_iterator& b) const;
277};
278
279template <class charT, class traits>
280bool operator==(const istreambuf_iterator<charT,traits>& a,
281 const istreambuf_iterator<charT,traits>& b);
282template <class charT, class traits>
283bool operator!=(const istreambuf_iterator<charT,traits>& a,
284 const istreambuf_iterator<charT,traits>& b);
285
286template <class charT, class traits = char_traits<charT> >
287class ostreambuf_iterator
288 : public iterator<output_iterator_tag, void, void, void, void>
289{
290public:
291 typedef charT char_type;
292 typedef traits traits_type;
293 typedef basic_streambuf<charT,traits> streambuf_type;
294 typedef basic_ostream<charT,traits> ostream_type;
295
Howard Hinnantd06a6402012-07-20 19:36:34 +0000296 ostreambuf_iterator(ostream_type& s) noexcept;
297 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298 ostreambuf_iterator& operator=(charT c);
299 ostreambuf_iterator& operator*();
300 ostreambuf_iterator& operator++();
301 ostreambuf_iterator& operator++(int);
Howard Hinnantd06a6402012-07-20 19:36:34 +0000302 bool failed() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303};
304
305template <class C> auto begin(C& c) -> decltype(c.begin());
306template <class C> auto begin(const C& c) -> decltype(c.begin());
307template <class C> auto end(C& c) -> decltype(c.end());
308template <class C> auto end(const C& c) -> decltype(c.end());
309template <class T, size_t N> T* begin(T (&array)[N]);
310template <class T, size_t N> T* end(T (&array)[N]);
311
Marshall Clow09da3c02013-08-30 01:17:07 +0000312template <class C> auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14
313template <class C> auto cend(const C& c) -> decltype(std::end(c)); // C++14
314template <class C> auto rbegin(C& c) -> decltype(c.rbegin()); // C++14
315template <class C> auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14
316template <class C> auto rend(C& c) -> decltype(c.rend()); // C++14
317template <class C> auto rend(const C& c) -> decltype(c.rend()); // C++14
318template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14
319template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); // C++14
320template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]); // C++14
321template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]); // C++14
322template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
323template <class C> auto crend(const C& c) -> decltype(std::rend(c)); // C++14
324
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325} // std
326
327*/
328
329#include <__config>
330#include <type_traits>
331#include <cstddef>
332#include <iosfwd>
Marshall Clow09da3c02013-08-30 01:17:07 +0000333#include <initializer_list>
Marshall Clowdece7fe2013-03-18 17:45:34 +0000334#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000335#include <Availability.h>
336#endif
337
Howard Hinnant5e571422013-08-23 20:10:18 +0000338#ifdef _LIBCPP_DEBUG
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000339# include <__debug>
340#else
341# define _LIBCPP_ASSERT(x, m) ((void)0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342#endif
343
Howard Hinnant08e17472011-10-17 20:05:10 +0000344#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000346#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347
348_LIBCPP_BEGIN_NAMESPACE_STD
349
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000350struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
351struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
352struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
353struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
354struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
356template <class _Tp>
357struct __has_iterator_category
358{
359private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000360 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361 template <class _Up> static __two __test(...);
362 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
363public:
364 static const bool value = sizeof(__test<_Tp>(0)) == 1;
365};
366
367template <class _Iter, bool> struct ____iterator_traits {};
368
369template <class _Iter>
370struct ____iterator_traits<_Iter, true>
371{
372 typedef typename _Iter::difference_type difference_type;
373 typedef typename _Iter::value_type value_type;
374 typedef typename _Iter::pointer pointer;
375 typedef typename _Iter::reference reference;
376 typedef typename _Iter::iterator_category iterator_category;
377};
378
379template <class _Iter, bool> struct __iterator_traits {};
380
381template <class _Iter>
382struct __iterator_traits<_Iter, true>
383 : ____iterator_traits
384 <
385 _Iter,
386 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
387 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
388 >
389{};
390
391// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
392// exists. Else iterator_traits<Iterator> will be an empty class. This is a
393// conforming extension which allows some programs to compile and behave as
394// the client expects instead of failing at compile time.
395
396template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000397struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
399
400template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000401struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402{
403 typedef ptrdiff_t difference_type;
404 typedef typename remove_const<_Tp>::type value_type;
405 typedef _Tp* pointer;
406 typedef _Tp& reference;
407 typedef random_access_iterator_tag iterator_category;
408};
409
410template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
411struct __has_iterator_category_convertible_to
412 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
413{};
414
415template <class _Tp, class _Up>
416struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
417
418template <class _Tp>
419struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
420
421template <class _Tp>
422struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
423
424template <class _Tp>
425struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
426
427template <class _Tp>
428struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
429
430template<class _Category, class _Tp, class _Distance = ptrdiff_t,
431 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000432struct _LIBCPP_TYPE_VIS_ONLY iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433{
434 typedef _Tp value_type;
435 typedef _Distance difference_type;
436 typedef _Pointer pointer;
437 typedef _Reference reference;
438 typedef _Category iterator_category;
439};
440
441template <class _InputIter>
442inline _LIBCPP_INLINE_VISIBILITY
443void __advance(_InputIter& __i,
444 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
445{
446 for (; __n > 0; --__n)
447 ++__i;
448}
449
450template <class _BiDirIter>
451inline _LIBCPP_INLINE_VISIBILITY
452void __advance(_BiDirIter& __i,
453 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
454{
455 if (__n >= 0)
456 for (; __n > 0; --__n)
457 ++__i;
458 else
459 for (; __n < 0; ++__n)
460 --__i;
461}
462
463template <class _RandIter>
464inline _LIBCPP_INLINE_VISIBILITY
465void __advance(_RandIter& __i,
466 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
467{
468 __i += __n;
469}
470
471template <class _InputIter>
472inline _LIBCPP_INLINE_VISIBILITY
473void advance(_InputIter& __i,
474 typename iterator_traits<_InputIter>::difference_type __n)
475{
476 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
477}
478
479template <class _InputIter>
480inline _LIBCPP_INLINE_VISIBILITY
481typename iterator_traits<_InputIter>::difference_type
482__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
483{
484 typename iterator_traits<_InputIter>::difference_type __r(0);
485 for (; __first != __last; ++__first)
486 ++__r;
487 return __r;
488}
489
490template <class _RandIter>
491inline _LIBCPP_INLINE_VISIBILITY
492typename iterator_traits<_RandIter>::difference_type
493__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
494{
495 return __last - __first;
496}
497
498template <class _InputIter>
499inline _LIBCPP_INLINE_VISIBILITY
500typename iterator_traits<_InputIter>::difference_type
501distance(_InputIter __first, _InputIter __last)
502{
503 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
504}
505
506template <class _ForwardIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000507inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508_ForwardIter
509next(_ForwardIter __x,
510 typename iterator_traits<_ForwardIter>::difference_type __n = 1,
511 typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
512{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000513 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514 return __x;
515}
516
517template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000518inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519_BidiretionalIter
520prev(_BidiretionalIter __x,
521 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
522 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
523{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000524 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525 return __x;
526}
527
528template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000529class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 : public iterator<typename iterator_traits<_Iter>::iterator_category,
531 typename iterator_traits<_Iter>::value_type,
532 typename iterator_traits<_Iter>::difference_type,
533 typename iterator_traits<_Iter>::pointer,
534 typename iterator_traits<_Iter>::reference>
535{
536private:
537 mutable _Iter __t;
538protected:
539 _Iter current;
540public:
541 typedef _Iter iterator_type;
542 typedef typename iterator_traits<_Iter>::difference_type difference_type;
543 typedef typename iterator_traits<_Iter>::reference reference;
544 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000545
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
547 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
548 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
549 : __t(__u.base()), current(__u.base()) {}
550 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
551 _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;}
552 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &(operator*());}
553 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
554 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
555 {reverse_iterator __tmp(*this); --current; return __tmp;}
556 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
557 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
558 {reverse_iterator __tmp(*this); ++current; return __tmp;}
559 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
560 {return reverse_iterator(current - __n);}
561 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
562 {current -= __n; return *this;}
563 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
564 {return reverse_iterator(current + __n);}
565 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
566 {current += __n; return *this;}
567 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
568 {return current[-__n-1];}
569};
570
571template <class _Iter1, class _Iter2>
572inline _LIBCPP_INLINE_VISIBILITY
573bool
574operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
575{
576 return __x.base() == __y.base();
577}
578
579template <class _Iter1, class _Iter2>
580inline _LIBCPP_INLINE_VISIBILITY
581bool
582operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
583{
584 return __x.base() > __y.base();
585}
586
587template <class _Iter1, class _Iter2>
588inline _LIBCPP_INLINE_VISIBILITY
589bool
590operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
591{
592 return __x.base() != __y.base();
593}
594
595template <class _Iter1, class _Iter2>
596inline _LIBCPP_INLINE_VISIBILITY
597bool
598operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
599{
600 return __x.base() < __y.base();
601}
602
603template <class _Iter1, class _Iter2>
604inline _LIBCPP_INLINE_VISIBILITY
605bool
606operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
607{
608 return __x.base() <= __y.base();
609}
610
611template <class _Iter1, class _Iter2>
612inline _LIBCPP_INLINE_VISIBILITY
613bool
614operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
615{
616 return __x.base() >= __y.base();
617}
618
619template <class _Iter1, class _Iter2>
620inline _LIBCPP_INLINE_VISIBILITY
621typename reverse_iterator<_Iter1>::difference_type
622operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
623{
624 return __y.base() - __x.base();
625}
626
627template <class _Iter>
628inline _LIBCPP_INLINE_VISIBILITY
629reverse_iterator<_Iter>
630operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
631{
632 return reverse_iterator<_Iter>(__x.base() - __n);
633}
634
635template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000636class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637 : public iterator<output_iterator_tag,
638 void,
639 void,
640 void,
641 back_insert_iterator<_Container>&>
642{
643protected:
644 _Container* container;
645public:
646 typedef _Container container_type;
647
648 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000649 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
650 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000651#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000652 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
653 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000654#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
656 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
657 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
658};
659
660template <class _Container>
661inline _LIBCPP_INLINE_VISIBILITY
662back_insert_iterator<_Container>
663back_inserter(_Container& __x)
664{
665 return back_insert_iterator<_Container>(__x);
666}
667
668template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000669class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 : public iterator<output_iterator_tag,
671 void,
672 void,
673 void,
674 front_insert_iterator<_Container>&>
675{
676protected:
677 _Container* container;
678public:
679 typedef _Container container_type;
680
681 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000682 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
683 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000684#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000685 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
686 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000687#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
689 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
690 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
691};
692
693template <class _Container>
694inline _LIBCPP_INLINE_VISIBILITY
695front_insert_iterator<_Container>
696front_inserter(_Container& __x)
697{
698 return front_insert_iterator<_Container>(__x);
699}
700
701template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000702class _LIBCPP_TYPE_VIS_ONLY insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703 : public iterator<output_iterator_tag,
704 void,
705 void,
706 void,
707 insert_iterator<_Container>&>
708{
709protected:
710 _Container* container;
711 typename _Container::iterator iter;
712public:
713 typedef _Container container_type;
714
715 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
716 : container(&__x), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000717 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
718 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000719#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000720 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
721 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000722#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
724 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
725 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
726};
727
728template <class _Container>
729inline _LIBCPP_INLINE_VISIBILITY
730insert_iterator<_Container>
731inserter(_Container& __x, typename _Container::iterator __i)
732{
733 return insert_iterator<_Container>(__x, __i);
734}
735
736template <class _Tp, class _CharT = char,
737 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000738class _LIBCPP_TYPE_VIS_ONLY istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
740{
741public:
742 typedef _CharT char_type;
743 typedef _Traits traits_type;
744 typedef basic_istream<_CharT,_Traits> istream_type;
745private:
746 istream_type* __in_stream_;
747 _Tp __value_;
748public:
749 _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {}
750 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
751 {
752 if (!(*__in_stream_ >> __value_))
753 __in_stream_ = 0;
754 }
755
756 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
757 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
758 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
759 {
760 if (!(*__in_stream_ >> __value_))
761 __in_stream_ = 0;
762 return *this;
763 }
764 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
765 {istream_iterator __t(*this); ++(*this); return __t;}
766
767 friend _LIBCPP_INLINE_VISIBILITY
768 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
769 {return __x.__in_stream_ == __y.__in_stream_;}
770
771 friend _LIBCPP_INLINE_VISIBILITY
772 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
773 {return !(__x == __y);}
774};
775
776template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000777class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000778 : public iterator<output_iterator_tag, void, void, void, void>
779{
780public:
781 typedef _CharT char_type;
782 typedef _Traits traits_type;
783 typedef basic_ostream<_CharT,_Traits> ostream_type;
784private:
785 ostream_type* __out_stream_;
786 const char_type* __delim_;
787public:
788 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
789 : __out_stream_(&__s), __delim_(0) {}
790 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
791 : __out_stream_(&__s), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000792 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000794 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 if (__delim_)
796 *__out_stream_ << __delim_;
797 return *this;
798 }
799
800 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
801 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
802 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
803};
804
805template<class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000806class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 : public iterator<input_iterator_tag, _CharT,
808 typename _Traits::off_type, _CharT*,
809 _CharT>
810{
811public:
812 typedef _CharT char_type;
813 typedef _Traits traits_type;
814 typedef typename _Traits::int_type int_type;
815 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
816 typedef basic_istream<_CharT,_Traits> istream_type;
817private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000818 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819
820 class __proxy
821 {
822 char_type __keep_;
823 streambuf_type* __sbuf_;
824 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
825 : __keep_(__c), __sbuf_(__s) {}
826 friend class istreambuf_iterator;
827 public:
828 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
829 };
830
Howard Hinnant82894812010-09-22 16:48:34 +0000831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000832 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833 {
834 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
835 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000836 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837 }
838public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000839 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000840 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000841 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000842 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000843 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000844 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845 : __sbuf_(__p.__sbuf_) {}
846
Howard Hinnantec3773c2011-12-01 20:21:04 +0000847 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
848 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
850 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
851 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000852 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853 return *this;
854 }
855 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
856 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000857 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 }
859
860 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000861 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862};
863
864template <class _CharT, class _Traits>
865inline _LIBCPP_INLINE_VISIBILITY
866bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
867 const istreambuf_iterator<_CharT,_Traits>& __b)
868 {return __a.equal(__b);}
869
870template <class _CharT, class _Traits>
871inline _LIBCPP_INLINE_VISIBILITY
872bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
873 const istreambuf_iterator<_CharT,_Traits>& __b)
874 {return !__a.equal(__b);}
875
876template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000877class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878 : public iterator<output_iterator_tag, void, void, void, void>
879{
880public:
881 typedef _CharT char_type;
882 typedef _Traits traits_type;
883 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
884 typedef basic_ostream<_CharT,_Traits> ostream_type;
885private:
886 streambuf_type* __sbuf_;
887public:
Howard Hinnantd06a6402012-07-20 19:36:34 +0000888 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000890 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891 : __sbuf_(__s) {}
892 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
893 {
894 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
895 __sbuf_ = 0;
896 return *this;
897 }
898 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
899 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
900 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000901 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +0000902
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000903#if !defined(__APPLE__) || \
904 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
905 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
906
Howard Hinnanta585de62012-09-19 19:14:15 +0000907 template <class _Ch, class _Tr>
908 friend
909 _LIBCPP_HIDDEN
910 ostreambuf_iterator<_Ch, _Tr>
911 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
912 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
913 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000914#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915};
916
917template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000918class _LIBCPP_TYPE_VIS_ONLY move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000919{
920private:
921 _Iter __i;
922public:
923 typedef _Iter iterator_type;
924 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
925 typedef typename iterator_traits<iterator_type>::value_type value_type;
926 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
927 typedef typename iterator_traits<iterator_type>::pointer pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000928#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929 typedef value_type&& reference;
930#else
931 typedef typename iterator_traits<iterator_type>::reference reference;
932#endif
Howard Hinnant324bb032010-08-22 00:02:43 +0000933
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
935 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
936 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
937 : __i(__u.base()) {}
938 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +0000939 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
940 return static_cast<reference>(*__i);
941 }
942 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
943 typename iterator_traits<iterator_type>::reference __ref = *__i;
944 return &__ref;
945 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
947 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
948 {move_iterator __tmp(*this); ++__i; return __tmp;}
949 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
950 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
951 {move_iterator __tmp(*this); --__i; return __tmp;}
952 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
953 {return move_iterator(__i + __n);}
954 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
955 {__i += __n; return *this;}
956 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
957 {return move_iterator(__i - __n);}
958 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
959 {__i -= __n; return *this;}
960 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +0000961 {
962 return static_cast<reference>(__i[__n]);
963 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964};
965
966template <class _Iter1, class _Iter2>
967inline _LIBCPP_INLINE_VISIBILITY
968bool
969operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
970{
971 return __x.base() == __y.base();
972}
973
974template <class _Iter1, class _Iter2>
975inline _LIBCPP_INLINE_VISIBILITY
976bool
977operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
978{
979 return __x.base() < __y.base();
980}
981
982template <class _Iter1, class _Iter2>
983inline _LIBCPP_INLINE_VISIBILITY
984bool
985operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
986{
987 return __x.base() != __y.base();
988}
989
990template <class _Iter1, class _Iter2>
991inline _LIBCPP_INLINE_VISIBILITY
992bool
993operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
994{
995 return __x.base() > __y.base();
996}
997
998template <class _Iter1, class _Iter2>
999inline _LIBCPP_INLINE_VISIBILITY
1000bool
1001operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1002{
1003 return __x.base() >= __y.base();
1004}
1005
1006template <class _Iter1, class _Iter2>
1007inline _LIBCPP_INLINE_VISIBILITY
1008bool
1009operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1010{
1011 return __x.base() <= __y.base();
1012}
1013
1014template <class _Iter1, class _Iter2>
1015inline _LIBCPP_INLINE_VISIBILITY
1016typename move_iterator<_Iter1>::difference_type
1017operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1018{
1019 return __x.base() - __y.base();
1020}
1021
1022template <class _Iter>
1023inline _LIBCPP_INLINE_VISIBILITY
1024move_iterator<_Iter>
1025operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1026{
1027 return move_iterator<_Iter>(__x.base() + __n);
1028}
1029
1030template <class _Iter>
1031inline _LIBCPP_INLINE_VISIBILITY
1032move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:03 +00001033make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001034{
1035 return move_iterator<_Iter>(__i);
1036}
1037
1038// __wrap_iter
1039
1040template <class _Iter> class __wrap_iter;
1041
1042template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001043_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001045operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046
1047template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001048_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001050operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001051
1052template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001053_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001055operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056
1057template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001058_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001060operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001061
1062template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001063_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001065operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066
1067template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001068_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001070operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001071
1072template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001073_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001075operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076
1077template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001078_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001080operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081
Howard Hinnant33be35e2012-09-14 00:39:16 +00001082template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1083template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1084template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1085template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086
1087template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001088_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089typename enable_if
1090<
Howard Hinnant1468b662010-11-19 22:17:28 +00001091 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092 _Tp*
1093>::type
1094__unwrap_iter(__wrap_iter<_Tp*>);
1095
1096template <class _Iter>
1097class __wrap_iter
1098{
1099public:
1100 typedef _Iter iterator_type;
1101 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1102 typedef typename iterator_traits<iterator_type>::value_type value_type;
1103 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1104 typedef typename iterator_traits<iterator_type>::pointer pointer;
1105 typedef typename iterator_traits<iterator_type>::reference reference;
1106private:
1107 iterator_type __i;
1108public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001109 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001110#if _LIBCPP_STD_VER > 11
1111 : __i{}
1112#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001113 {
1114#if _LIBCPP_DEBUG_LEVEL >= 2
1115 __get_db()->__insert_i(this);
1116#endif
1117 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001119 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001120 : __i(__u.base())
1121 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001122#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001123 __get_db()->__iterator_copy(this, &__u);
1124#endif
1125 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001126#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001127 _LIBCPP_INLINE_VISIBILITY
1128 __wrap_iter(const __wrap_iter& __x)
1129 : __i(__x.base())
1130 {
1131 __get_db()->__iterator_copy(this, &__x);
1132 }
1133 _LIBCPP_INLINE_VISIBILITY
1134 __wrap_iter& operator=(const __wrap_iter& __x)
1135 {
1136 if (this != &__x)
1137 {
1138 __get_db()->__iterator_copy(this, &__x);
1139 __i = __x.__i;
1140 }
1141 return *this;
1142 }
1143 _LIBCPP_INLINE_VISIBILITY
1144 ~__wrap_iter()
1145 {
1146 __get_db()->__erase_i(this);
1147 }
1148#endif
1149 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1150 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001151#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001152 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1153 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001154#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001155 return *__i;
1156 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001157 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1158 {
1159#if _LIBCPP_DEBUG_LEVEL >= 2
1160 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1161 "Attempted to dereference a non-dereferenceable iterator");
1162#endif
1163 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
1164 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001165 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1166 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001167#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001168 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1169 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001170#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001171 ++__i;
1172 return *this;
1173 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001174 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001175 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1176 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1177 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001178#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001179 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1180 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001181#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001182 --__i;
1183 return *this;
1184 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001185 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001186 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001187 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001188 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001189 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001190 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001191#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001192 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1193 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001194#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001195 __i += __n;
1196 return *this;
1197 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001198 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001199 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001200 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001201 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001202 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001203 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001204#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001205 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1206 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001207#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001208 return __i[__n];
1209 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001210
Howard Hinnanta6119a82011-05-29 19:57:12 +00001211 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001212
1213private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001214#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001215 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1216 {
1217 __get_db()->__insert_ic(this, __p);
1218 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001219#else
1220 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001221#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222
1223 template <class _Up> friend class __wrap_iter;
1224 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1225 template <class _Tp, class _Alloc> friend class vector;
1226
1227 template <class _Iter1, class _Iter2>
1228 friend
1229 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001230 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001231
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232 template <class _Iter1, class _Iter2>
1233 friend
1234 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001235 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001236
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001237 template <class _Iter1, class _Iter2>
1238 friend
1239 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001240 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001241
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242 template <class _Iter1, class _Iter2>
1243 friend
1244 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001245 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001246
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001247 template <class _Iter1, class _Iter2>
1248 friend
1249 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001250 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001251
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001252 template <class _Iter1, class _Iter2>
1253 friend
1254 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001255 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001256
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257 template <class _Iter1, class _Iter2>
1258 friend
1259 typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001260 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001261
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262 template <class _Iter1>
1263 friend
1264 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001265 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266
Howard Hinnant99968442011-11-29 18:15:50 +00001267 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001269 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001270 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1271
1272 template <class _Tp>
1273 friend
1274 typename enable_if
1275 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001276 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277 _Tp*
1278 >::type
1279 __unwrap_iter(__wrap_iter<_Tp*>);
1280};
1281
1282template <class _Iter1, class _Iter2>
1283inline _LIBCPP_INLINE_VISIBILITY
1284bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001285operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286{
1287 return __x.base() == __y.base();
1288}
1289
1290template <class _Iter1, class _Iter2>
1291inline _LIBCPP_INLINE_VISIBILITY
1292bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001293operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001294{
Howard Hinnantabe26282011-09-16 17:29:17 +00001295#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001296 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001297 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001298#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001299 return __x.base() < __y.base();
1300}
1301
1302template <class _Iter1, class _Iter2>
1303inline _LIBCPP_INLINE_VISIBILITY
1304bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001305operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001307 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001308}
1309
1310template <class _Iter1, class _Iter2>
1311inline _LIBCPP_INLINE_VISIBILITY
1312bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001313operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001315 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316}
1317
1318template <class _Iter1, class _Iter2>
1319inline _LIBCPP_INLINE_VISIBILITY
1320bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001321operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001322{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001323 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324}
1325
1326template <class _Iter1, class _Iter2>
1327inline _LIBCPP_INLINE_VISIBILITY
1328bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001329operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001330{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001331 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332}
1333
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001334template <class _Iter1>
1335inline _LIBCPP_INLINE_VISIBILITY
1336bool
1337operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1338{
1339 return !(__x == __y);
1340}
1341
1342template <class _Iter1>
1343inline _LIBCPP_INLINE_VISIBILITY
1344bool
1345operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1346{
1347 return __y < __x;
1348}
1349
1350template <class _Iter1>
1351inline _LIBCPP_INLINE_VISIBILITY
1352bool
1353operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1354{
1355 return !(__x < __y);
1356}
1357
1358template <class _Iter1>
1359inline _LIBCPP_INLINE_VISIBILITY
1360bool
1361operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1362{
1363 return !(__y < __x);
1364}
1365
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366template <class _Iter1, class _Iter2>
1367inline _LIBCPP_INLINE_VISIBILITY
1368typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001369operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370{
Howard Hinnantabe26282011-09-16 17:29:17 +00001371#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001372 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001373 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001374#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001375 return __x.base() - __y.base();
1376}
1377
1378template <class _Iter>
1379inline _LIBCPP_INLINE_VISIBILITY
1380__wrap_iter<_Iter>
1381operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001382 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001384 __x += __n;
1385 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386}
1387
Marshall Clow6daf5342013-12-02 03:24:33 +00001388template <class _Tp, size_t _Np>
1389inline _LIBCPP_INLINE_VISIBILITY
1390_Tp*
1391begin(_Tp (&__array)[_Np])
1392{
1393 return __array;
1394}
1395
1396template <class _Tp, size_t _Np>
1397inline _LIBCPP_INLINE_VISIBILITY
1398_Tp*
1399end(_Tp (&__array)[_Np])
1400{
1401 return __array + _Np;
1402}
1403
Marshall Clow1c398692013-12-11 19:32:32 +00001404#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1405
Howard Hinnant99968442011-11-29 18:15:50 +00001406template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001407inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408auto
Howard Hinnant99968442011-11-29 18:15:50 +00001409begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410{
1411 return __c.begin();
1412}
1413
Howard Hinnant99968442011-11-29 18:15:50 +00001414template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001415inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416auto
Howard Hinnant99968442011-11-29 18:15:50 +00001417begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418{
1419 return __c.begin();
1420}
1421
Howard Hinnant99968442011-11-29 18:15:50 +00001422template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001423inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424auto
Howard Hinnant99968442011-11-29 18:15:50 +00001425end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426{
1427 return __c.end();
1428}
1429
Howard Hinnant99968442011-11-29 18:15:50 +00001430template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001431inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432auto
Howard Hinnant99968442011-11-29 18:15:50 +00001433end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434{
1435 return __c.end();
1436}
1437
Marshall Clow09da3c02013-08-30 01:17:07 +00001438#if _LIBCPP_STD_VER > 11
1439
Marshall Clow6daf5342013-12-02 03:24:33 +00001440template <class _Tp, size_t _Np>
1441inline _LIBCPP_INLINE_VISIBILITY
1442reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1443{
1444 return reverse_iterator<_Tp*>(__array + _Np);
1445}
1446
1447template <class _Tp, size_t _Np>
1448inline _LIBCPP_INLINE_VISIBILITY
1449reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1450{
1451 return reverse_iterator<_Tp*>(__array);
1452}
1453
1454template <class _Ep>
1455inline _LIBCPP_INLINE_VISIBILITY
1456reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1457{
1458 return reverse_iterator<const _Ep*>(__il.end());
1459}
1460
1461template <class _Ep>
1462inline _LIBCPP_INLINE_VISIBILITY
1463reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1464{
1465 return reverse_iterator<const _Ep*>(__il.begin());
1466}
1467
Marshall Clow09da3c02013-08-30 01:17:07 +00001468template <class _Cp>
1469inline _LIBCPP_INLINE_VISIBILITY
1470auto cbegin(const _Cp& __c) -> decltype(begin(__c))
1471{
Marshall Clow6daf5342013-12-02 03:24:33 +00001472 return _VSTD::begin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001473}
1474
1475template <class _Cp>
1476inline _LIBCPP_INLINE_VISIBILITY
1477auto cend(const _Cp& __c) -> decltype(end(__c))
1478{
Marshall Clow6daf5342013-12-02 03:24:33 +00001479 return _VSTD::end(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001480}
1481
1482template <class _Cp>
1483inline _LIBCPP_INLINE_VISIBILITY
1484auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1485{
1486 return __c.rbegin();
1487}
1488
1489template <class _Cp>
1490inline _LIBCPP_INLINE_VISIBILITY
1491auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1492{
1493 return __c.rbegin();
1494}
1495
1496template <class _Cp>
1497inline _LIBCPP_INLINE_VISIBILITY
1498auto rend(_Cp& __c) -> decltype(__c.rend())
1499{
1500 return __c.rend();
1501}
1502
1503template <class _Cp>
1504inline _LIBCPP_INLINE_VISIBILITY
1505auto rend(const _Cp& __c) -> decltype(__c.rend())
1506{
1507 return __c.rend();
1508}
1509
1510template <class _Cp>
1511inline _LIBCPP_INLINE_VISIBILITY
1512auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
1513{
1514 return rbegin(__c);
1515}
1516
1517template <class _Cp>
1518inline _LIBCPP_INLINE_VISIBILITY
1519auto crend(const _Cp& __c) -> decltype(rend(__c))
1520{
1521 return rend(__c);
1522}
1523
1524#endif
1525
1526
Howard Hinnant726a76f2010-11-16 21:10:23 +00001527#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528
Howard Hinnant99968442011-11-29 18:15:50 +00001529template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001530inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001531typename _Cp::iterator
1532begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533{
1534 return __c.begin();
1535}
1536
Howard Hinnant99968442011-11-29 18:15:50 +00001537template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001538inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001539typename _Cp::const_iterator
1540begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541{
1542 return __c.begin();
1543}
1544
Howard Hinnant99968442011-11-29 18:15:50 +00001545template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001546inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001547typename _Cp::iterator
1548end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001549{
1550 return __c.end();
1551}
1552
Howard Hinnant99968442011-11-29 18:15:50 +00001553template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001554inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001555typename _Cp::const_iterator
1556end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557{
1558 return __c.end();
1559}
1560
Howard Hinnant726a76f2010-11-16 21:10:23 +00001561#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001562
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001563_LIBCPP_END_NAMESPACE_STD
1564
1565#endif // _LIBCPP_ITERATOR