blob: 4c6b0a6075b986ea2a527275e184aa51e14b3b74 [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
Marshall Clowff137e92014-03-03 01:24:04 +0000141template <class Iterator> reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14
142
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143template <class Container>
144class back_insert_iterator
145{
146protected:
147 Container* container;
148public:
149 typedef Container container_type;
150 typedef void value_type;
151 typedef void difference_type;
152 typedef back_insert_iterator<Cont>& reference;
153 typedef void pointer;
154
155 explicit back_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000156 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000157 back_insert_iterator& operator*();
158 back_insert_iterator& operator++();
159 back_insert_iterator operator++(int);
160};
161
162template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
163
164template <class Container>
165class front_insert_iterator
166{
167protected:
168 Container* container;
169public:
170 typedef Container container_type;
171 typedef void value_type;
172 typedef void difference_type;
173 typedef front_insert_iterator<Cont>& reference;
174 typedef void pointer;
175
176 explicit front_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000177 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178 front_insert_iterator& operator*();
179 front_insert_iterator& operator++();
180 front_insert_iterator operator++(int);
181};
182
183template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
184
185template <class Container>
186class insert_iterator
187{
188protected:
189 Container* container;
190 typename Container::iterator iter;
191public:
192 typedef Container container_type;
193 typedef void value_type;
194 typedef void difference_type;
195 typedef insert_iterator<Cont>& reference;
196 typedef void pointer;
197
198 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant45f57172010-09-14 20:26:27 +0000199 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000200 insert_iterator& operator*();
201 insert_iterator& operator++();
202 insert_iterator& operator++(int);
203};
204
205template <class Container, class Iterator>
206insert_iterator<Container> inserter(Container& x, Iterator i);
207
208template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
209class istream_iterator
210 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
211{
212public:
213 typedef charT char_type;
214 typedef traits traits_type;
215 typedef basic_istream<charT,traits> istream_type;
216
217 istream_iterator();
218 istream_iterator(istream_type& s);
219 istream_iterator(const istream_iterator& x);
220 ~istream_iterator();
221
222 const T& operator*() const;
223 const T* operator->() const;
224 istream_iterator& operator++();
225 istream_iterator operator++(int);
226};
227
228template <class T, class charT, class traits, class Distance>
229bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
230 const istream_iterator<T,charT,traits,Distance>& y);
231template <class T, class charT, class traits, class Distance>
232bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
233 const istream_iterator<T,charT,traits,Distance>& y);
234
235template <class T, class charT = char, class traits = char_traits<charT> >
236class ostream_iterator
237 : public iterator<output_iterator_tag, void, void, void ,void>
238{
239public:
240 typedef charT char_type;
241 typedef traits traits_type;
242 typedef basic_ostream<charT,traits> ostream_type;
243
244 ostream_iterator(ostream_type& s);
245 ostream_iterator(ostream_type& s, const charT* delimiter);
246 ostream_iterator(const ostream_iterator& x);
247 ~ostream_iterator();
248 ostream_iterator& operator=(const T& value);
249
250 ostream_iterator& operator*();
251 ostream_iterator& operator++();
252 ostream_iterator& operator++(int);
253};
254
255template<class charT, class traits = char_traits<charT> >
256class istreambuf_iterator
257 : public iterator<input_iterator_tag, charT,
258 typename traits::off_type, unspecified,
259 charT>
260{
261public:
262 typedef charT char_type;
263 typedef traits traits_type;
264 typedef typename traits::int_type int_type;
265 typedef basic_streambuf<charT,traits> streambuf_type;
266 typedef basic_istream<charT,traits> istream_type;
267
Howard Hinnantd06a6402012-07-20 19:36:34 +0000268 istreambuf_iterator() noexcept;
269 istreambuf_iterator(istream_type& s) noexcept;
270 istreambuf_iterator(streambuf_type* s) noexcept;
271 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272
273 charT operator*() const;
274 pointer operator->() const;
275 istreambuf_iterator& operator++();
276 a-private-type operator++(int);
277
278 bool equal(const istreambuf_iterator& b) const;
279};
280
281template <class charT, class traits>
282bool operator==(const istreambuf_iterator<charT,traits>& a,
283 const istreambuf_iterator<charT,traits>& b);
284template <class charT, class traits>
285bool operator!=(const istreambuf_iterator<charT,traits>& a,
286 const istreambuf_iterator<charT,traits>& b);
287
288template <class charT, class traits = char_traits<charT> >
289class ostreambuf_iterator
290 : public iterator<output_iterator_tag, void, void, void, void>
291{
292public:
293 typedef charT char_type;
294 typedef traits traits_type;
295 typedef basic_streambuf<charT,traits> streambuf_type;
296 typedef basic_ostream<charT,traits> ostream_type;
297
Howard Hinnantd06a6402012-07-20 19:36:34 +0000298 ostreambuf_iterator(ostream_type& s) noexcept;
299 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000300 ostreambuf_iterator& operator=(charT c);
301 ostreambuf_iterator& operator*();
302 ostreambuf_iterator& operator++();
303 ostreambuf_iterator& operator++(int);
Howard Hinnantd06a6402012-07-20 19:36:34 +0000304 bool failed() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305};
306
307template <class C> auto begin(C& c) -> decltype(c.begin());
308template <class C> auto begin(const C& c) -> decltype(c.begin());
309template <class C> auto end(C& c) -> decltype(c.end());
310template <class C> auto end(const C& c) -> decltype(c.end());
311template <class T, size_t N> T* begin(T (&array)[N]);
312template <class T, size_t N> T* end(T (&array)[N]);
313
Marshall Clow09da3c02013-08-30 01:17:07 +0000314template <class C> auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14
315template <class C> auto cend(const C& c) -> decltype(std::end(c)); // C++14
316template <class C> auto rbegin(C& c) -> decltype(c.rbegin()); // C++14
317template <class C> auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14
318template <class C> auto rend(C& c) -> decltype(c.rend()); // C++14
319template <class C> auto rend(const C& c) -> decltype(c.rend()); // C++14
320template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14
321template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); // C++14
322template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]); // C++14
323template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]); // C++14
324template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
325template <class C> auto crend(const C& c) -> decltype(std::rend(c)); // C++14
326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327} // std
328
329*/
330
331#include <__config>
Marshall Clow02ca8af2014-02-27 02:11:50 +0000332#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333#include <type_traits>
334#include <cstddef>
335#include <iosfwd>
Marshall Clow09da3c02013-08-30 01:17:07 +0000336#include <initializer_list>
Marshall Clowdece7fe2013-03-18 17:45:34 +0000337#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000338#include <Availability.h>
339#endif
340
Howard Hinnant5e571422013-08-23 20:10:18 +0000341#ifdef _LIBCPP_DEBUG
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000342# include <__debug>
343#else
344# define _LIBCPP_ASSERT(x, m) ((void)0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345#endif
346
Howard Hinnant08e17472011-10-17 20:05:10 +0000347#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000349#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350
351_LIBCPP_BEGIN_NAMESPACE_STD
352
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000353struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
354struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
355struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
356struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
357struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358
359template <class _Tp>
360struct __has_iterator_category
361{
362private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000363 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364 template <class _Up> static __two __test(...);
365 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
366public:
367 static const bool value = sizeof(__test<_Tp>(0)) == 1;
368};
369
Marshall Clowa71f9562014-01-03 22:55:49 +0000370template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template <class _Iter>
Marshall Clowa71f9562014-01-03 22:55:49 +0000373struct __iterator_traits_impl<_Iter, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374{
375 typedef typename _Iter::difference_type difference_type;
376 typedef typename _Iter::value_type value_type;
377 typedef typename _Iter::pointer pointer;
378 typedef typename _Iter::reference reference;
379 typedef typename _Iter::iterator_category iterator_category;
380};
381
382template <class _Iter, bool> struct __iterator_traits {};
383
384template <class _Iter>
385struct __iterator_traits<_Iter, true>
Marshall Clowa71f9562014-01-03 22:55:49 +0000386 : __iterator_traits_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387 <
388 _Iter,
389 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
390 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
391 >
392{};
393
394// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
395// exists. Else iterator_traits<Iterator> will be an empty class. This is a
396// conforming extension which allows some programs to compile and behave as
397// the client expects instead of failing at compile time.
398
399template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000400struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
402
403template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000404struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405{
406 typedef ptrdiff_t difference_type;
407 typedef typename remove_const<_Tp>::type value_type;
408 typedef _Tp* pointer;
409 typedef _Tp& reference;
410 typedef random_access_iterator_tag iterator_category;
411};
412
413template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
414struct __has_iterator_category_convertible_to
415 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
416{};
417
418template <class _Tp, class _Up>
419struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
420
421template <class _Tp>
422struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
423
424template <class _Tp>
425struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
426
427template <class _Tp>
428struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
429
430template <class _Tp>
431struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
432
433template<class _Category, class _Tp, class _Distance = ptrdiff_t,
434 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000435struct _LIBCPP_TYPE_VIS_ONLY iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436{
437 typedef _Tp value_type;
438 typedef _Distance difference_type;
439 typedef _Pointer pointer;
440 typedef _Reference reference;
441 typedef _Category iterator_category;
442};
443
444template <class _InputIter>
445inline _LIBCPP_INLINE_VISIBILITY
446void __advance(_InputIter& __i,
447 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
448{
449 for (; __n > 0; --__n)
450 ++__i;
451}
452
453template <class _BiDirIter>
454inline _LIBCPP_INLINE_VISIBILITY
455void __advance(_BiDirIter& __i,
456 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
457{
458 if (__n >= 0)
459 for (; __n > 0; --__n)
460 ++__i;
461 else
462 for (; __n < 0; ++__n)
463 --__i;
464}
465
466template <class _RandIter>
467inline _LIBCPP_INLINE_VISIBILITY
468void __advance(_RandIter& __i,
469 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
470{
471 __i += __n;
472}
473
474template <class _InputIter>
475inline _LIBCPP_INLINE_VISIBILITY
476void advance(_InputIter& __i,
477 typename iterator_traits<_InputIter>::difference_type __n)
478{
479 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
480}
481
482template <class _InputIter>
483inline _LIBCPP_INLINE_VISIBILITY
484typename iterator_traits<_InputIter>::difference_type
485__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
486{
487 typename iterator_traits<_InputIter>::difference_type __r(0);
488 for (; __first != __last; ++__first)
489 ++__r;
490 return __r;
491}
492
493template <class _RandIter>
494inline _LIBCPP_INLINE_VISIBILITY
495typename iterator_traits<_RandIter>::difference_type
496__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
497{
498 return __last - __first;
499}
500
501template <class _InputIter>
502inline _LIBCPP_INLINE_VISIBILITY
503typename iterator_traits<_InputIter>::difference_type
504distance(_InputIter __first, _InputIter __last)
505{
506 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
507}
508
509template <class _ForwardIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000510inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511_ForwardIter
512next(_ForwardIter __x,
513 typename iterator_traits<_ForwardIter>::difference_type __n = 1,
514 typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
515{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000516 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517 return __x;
518}
519
520template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000521inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522_BidiretionalIter
523prev(_BidiretionalIter __x,
524 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
525 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
526{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000527 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 return __x;
529}
530
531template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000532class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 : public iterator<typename iterator_traits<_Iter>::iterator_category,
534 typename iterator_traits<_Iter>::value_type,
535 typename iterator_traits<_Iter>::difference_type,
536 typename iterator_traits<_Iter>::pointer,
537 typename iterator_traits<_Iter>::reference>
538{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539protected:
540 _Iter current;
541public:
542 typedef _Iter iterator_type;
543 typedef typename iterator_traits<_Iter>::difference_type difference_type;
544 typedef typename iterator_traits<_Iter>::reference reference;
545 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000546
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
Marshall Clowb1ead682014-03-11 17:16:17 +0000548 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : current(__x) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
Marshall Clowb1ead682014-03-11 17:16:17 +0000550 : current(__u.base()) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
Marshall Clowb1ead682014-03-11 17:16:17 +0000552 _LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;}
Marshall Clow02ca8af2014-02-27 02:11:50 +0000553 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
555 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
556 {reverse_iterator __tmp(*this); --current; return __tmp;}
557 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
558 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
559 {reverse_iterator __tmp(*this); ++current; return __tmp;}
560 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
561 {return reverse_iterator(current - __n);}
562 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
563 {current -= __n; return *this;}
564 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
565 {return reverse_iterator(current + __n);}
566 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
567 {current += __n; return *this;}
568 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
569 {return current[-__n-1];}
570};
571
572template <class _Iter1, class _Iter2>
573inline _LIBCPP_INLINE_VISIBILITY
574bool
575operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
576{
577 return __x.base() == __y.base();
578}
579
580template <class _Iter1, class _Iter2>
581inline _LIBCPP_INLINE_VISIBILITY
582bool
583operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
584{
585 return __x.base() > __y.base();
586}
587
588template <class _Iter1, class _Iter2>
589inline _LIBCPP_INLINE_VISIBILITY
590bool
591operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
592{
593 return __x.base() != __y.base();
594}
595
596template <class _Iter1, class _Iter2>
597inline _LIBCPP_INLINE_VISIBILITY
598bool
599operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
600{
601 return __x.base() < __y.base();
602}
603
604template <class _Iter1, class _Iter2>
605inline _LIBCPP_INLINE_VISIBILITY
606bool
607operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
608{
609 return __x.base() <= __y.base();
610}
611
612template <class _Iter1, class _Iter2>
613inline _LIBCPP_INLINE_VISIBILITY
614bool
615operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
616{
617 return __x.base() >= __y.base();
618}
619
620template <class _Iter1, class _Iter2>
621inline _LIBCPP_INLINE_VISIBILITY
622typename reverse_iterator<_Iter1>::difference_type
623operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
624{
625 return __y.base() - __x.base();
626}
627
628template <class _Iter>
629inline _LIBCPP_INLINE_VISIBILITY
630reverse_iterator<_Iter>
631operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
632{
633 return reverse_iterator<_Iter>(__x.base() - __n);
634}
635
Marshall Clowff137e92014-03-03 01:24:04 +0000636#if _LIBCPP_STD_VER > 11
637template <class _Iter>
638inline _LIBCPP_INLINE_VISIBILITY
639reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
640{
641 return reverse_iterator<_Iter>(__i);
642}
643#endif
644
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000646class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647 : public iterator<output_iterator_tag,
648 void,
649 void,
650 void,
651 back_insert_iterator<_Container>&>
652{
653protected:
654 _Container* container;
655public:
656 typedef _Container container_type;
657
Marshall Clow53c0e722014-03-03 19:20:40 +0000658 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000659 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
660 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000661#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000662 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
663 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000664#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
666 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
667 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
668};
669
670template <class _Container>
671inline _LIBCPP_INLINE_VISIBILITY
672back_insert_iterator<_Container>
673back_inserter(_Container& __x)
674{
675 return back_insert_iterator<_Container>(__x);
676}
677
678template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000679class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680 : public iterator<output_iterator_tag,
681 void,
682 void,
683 void,
684 front_insert_iterator<_Container>&>
685{
686protected:
687 _Container* container;
688public:
689 typedef _Container container_type;
690
Marshall Clow53c0e722014-03-03 19:20:40 +0000691 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000692 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
693 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000694#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000695 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
696 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000697#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
699 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
700 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
701};
702
703template <class _Container>
704inline _LIBCPP_INLINE_VISIBILITY
705front_insert_iterator<_Container>
706front_inserter(_Container& __x)
707{
708 return front_insert_iterator<_Container>(__x);
709}
710
711template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000712class _LIBCPP_TYPE_VIS_ONLY insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 : public iterator<output_iterator_tag,
714 void,
715 void,
716 void,
717 insert_iterator<_Container>&>
718{
719protected:
720 _Container* container;
721 typename _Container::iterator iter;
722public:
723 typedef _Container container_type;
724
725 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clow53c0e722014-03-03 19:20:40 +0000726 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000727 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
728 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000729#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000730 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
731 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000732#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
734 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
735 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
736};
737
738template <class _Container>
739inline _LIBCPP_INLINE_VISIBILITY
740insert_iterator<_Container>
741inserter(_Container& __x, typename _Container::iterator __i)
742{
743 return insert_iterator<_Container>(__x, __i);
744}
745
746template <class _Tp, class _CharT = char,
747 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000748class _LIBCPP_TYPE_VIS_ONLY istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
750{
751public:
752 typedef _CharT char_type;
753 typedef _Traits traits_type;
754 typedef basic_istream<_CharT,_Traits> istream_type;
755private:
756 istream_type* __in_stream_;
757 _Tp __value_;
758public:
759 _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {}
760 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
761 {
762 if (!(*__in_stream_ >> __value_))
763 __in_stream_ = 0;
764 }
765
766 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
767 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
768 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
769 {
770 if (!(*__in_stream_ >> __value_))
771 __in_stream_ = 0;
772 return *this;
773 }
774 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
775 {istream_iterator __t(*this); ++(*this); return __t;}
776
777 friend _LIBCPP_INLINE_VISIBILITY
778 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
779 {return __x.__in_stream_ == __y.__in_stream_;}
780
781 friend _LIBCPP_INLINE_VISIBILITY
782 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
783 {return !(__x == __y);}
784};
785
786template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000787class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788 : public iterator<output_iterator_tag, void, void, void, void>
789{
790public:
791 typedef _CharT char_type;
792 typedef _Traits traits_type;
793 typedef basic_ostream<_CharT,_Traits> ostream_type;
794private:
795 ostream_type* __out_stream_;
796 const char_type* __delim_;
797public:
798 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
799 : __out_stream_(&__s), __delim_(0) {}
800 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
801 : __out_stream_(&__s), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000802 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000804 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805 if (__delim_)
806 *__out_stream_ << __delim_;
807 return *this;
808 }
809
810 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
811 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
812 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
813};
814
815template<class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000816class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817 : public iterator<input_iterator_tag, _CharT,
818 typename _Traits::off_type, _CharT*,
819 _CharT>
820{
821public:
822 typedef _CharT char_type;
823 typedef _Traits traits_type;
824 typedef typename _Traits::int_type int_type;
825 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
826 typedef basic_istream<_CharT,_Traits> istream_type;
827private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000828 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829
830 class __proxy
831 {
832 char_type __keep_;
833 streambuf_type* __sbuf_;
834 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
835 : __keep_(__c), __sbuf_(__s) {}
836 friend class istreambuf_iterator;
837 public:
838 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
839 };
840
Howard Hinnant82894812010-09-22 16:48:34 +0000841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000842 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000843 {
844 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
845 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000846 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847 }
848public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000849 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000850 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000851 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000852 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000853 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000854 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855 : __sbuf_(__p.__sbuf_) {}
856
Howard Hinnantec3773c2011-12-01 20:21:04 +0000857 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
858 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
860 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
861 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000862 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863 return *this;
864 }
865 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
866 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000867 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868 }
869
870 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000871 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000872};
873
874template <class _CharT, class _Traits>
875inline _LIBCPP_INLINE_VISIBILITY
876bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
877 const istreambuf_iterator<_CharT,_Traits>& __b)
878 {return __a.equal(__b);}
879
880template <class _CharT, class _Traits>
881inline _LIBCPP_INLINE_VISIBILITY
882bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
883 const istreambuf_iterator<_CharT,_Traits>& __b)
884 {return !__a.equal(__b);}
885
886template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000887class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 : public iterator<output_iterator_tag, void, void, void, void>
889{
890public:
891 typedef _CharT char_type;
892 typedef _Traits traits_type;
893 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
894 typedef basic_ostream<_CharT,_Traits> ostream_type;
895private:
896 streambuf_type* __sbuf_;
897public:
Howard Hinnantd06a6402012-07-20 19:36:34 +0000898 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000900 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901 : __sbuf_(__s) {}
902 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
903 {
904 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
905 __sbuf_ = 0;
906 return *this;
907 }
908 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
909 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
910 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000911 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +0000912
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000913#if !defined(__APPLE__) || \
914 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
915 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
916
Howard Hinnanta585de62012-09-19 19:14:15 +0000917 template <class _Ch, class _Tr>
918 friend
919 _LIBCPP_HIDDEN
920 ostreambuf_iterator<_Ch, _Tr>
921 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
922 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
923 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000924#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925};
926
927template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000928class _LIBCPP_TYPE_VIS_ONLY move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929{
930private:
931 _Iter __i;
932public:
933 typedef _Iter iterator_type;
934 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
935 typedef typename iterator_traits<iterator_type>::value_type value_type;
936 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
937 typedef typename iterator_traits<iterator_type>::pointer pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000938#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939 typedef value_type&& reference;
940#else
941 typedef typename iterator_traits<iterator_type>::reference reference;
942#endif
Howard Hinnant324bb032010-08-22 00:02:43 +0000943
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000944 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
945 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
946 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
947 : __i(__u.base()) {}
948 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +0000949 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
950 return static_cast<reference>(*__i);
951 }
952 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
953 typename iterator_traits<iterator_type>::reference __ref = *__i;
954 return &__ref;
955 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
957 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
958 {move_iterator __tmp(*this); ++__i; return __tmp;}
959 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
960 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
961 {move_iterator __tmp(*this); --__i; return __tmp;}
962 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
963 {return move_iterator(__i + __n);}
964 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
965 {__i += __n; return *this;}
966 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
967 {return move_iterator(__i - __n);}
968 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
969 {__i -= __n; return *this;}
970 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +0000971 {
972 return static_cast<reference>(__i[__n]);
973 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000974};
975
976template <class _Iter1, class _Iter2>
977inline _LIBCPP_INLINE_VISIBILITY
978bool
979operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
980{
981 return __x.base() == __y.base();
982}
983
984template <class _Iter1, class _Iter2>
985inline _LIBCPP_INLINE_VISIBILITY
986bool
987operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
988{
989 return __x.base() < __y.base();
990}
991
992template <class _Iter1, class _Iter2>
993inline _LIBCPP_INLINE_VISIBILITY
994bool
995operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
996{
997 return __x.base() != __y.base();
998}
999
1000template <class _Iter1, class _Iter2>
1001inline _LIBCPP_INLINE_VISIBILITY
1002bool
1003operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1004{
1005 return __x.base() > __y.base();
1006}
1007
1008template <class _Iter1, class _Iter2>
1009inline _LIBCPP_INLINE_VISIBILITY
1010bool
1011operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1012{
1013 return __x.base() >= __y.base();
1014}
1015
1016template <class _Iter1, class _Iter2>
1017inline _LIBCPP_INLINE_VISIBILITY
1018bool
1019operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1020{
1021 return __x.base() <= __y.base();
1022}
1023
1024template <class _Iter1, class _Iter2>
1025inline _LIBCPP_INLINE_VISIBILITY
1026typename move_iterator<_Iter1>::difference_type
1027operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1028{
1029 return __x.base() - __y.base();
1030}
1031
1032template <class _Iter>
1033inline _LIBCPP_INLINE_VISIBILITY
1034move_iterator<_Iter>
1035operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1036{
1037 return move_iterator<_Iter>(__x.base() + __n);
1038}
1039
1040template <class _Iter>
1041inline _LIBCPP_INLINE_VISIBILITY
1042move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:03 +00001043make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044{
1045 return move_iterator<_Iter>(__i);
1046}
1047
1048// __wrap_iter
1049
1050template <class _Iter> class __wrap_iter;
1051
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 +00001074bool
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 _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001078_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001080operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081
1082template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001083_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001084typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001085operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086
1087template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001088_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001090operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091
Howard Hinnant33be35e2012-09-14 00:39:16 +00001092template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1093template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1094template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1095template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096
1097template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001098_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099typename enable_if
1100<
Howard Hinnant1468b662010-11-19 22:17:28 +00001101 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102 _Tp*
1103>::type
1104__unwrap_iter(__wrap_iter<_Tp*>);
1105
1106template <class _Iter>
1107class __wrap_iter
1108{
1109public:
1110 typedef _Iter iterator_type;
1111 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1112 typedef typename iterator_traits<iterator_type>::value_type value_type;
1113 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1114 typedef typename iterator_traits<iterator_type>::pointer pointer;
1115 typedef typename iterator_traits<iterator_type>::reference reference;
1116private:
1117 iterator_type __i;
1118public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001119 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001120#if _LIBCPP_STD_VER > 11
1121 : __i{}
1122#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001123 {
1124#if _LIBCPP_DEBUG_LEVEL >= 2
1125 __get_db()->__insert_i(this);
1126#endif
1127 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001129 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001130 : __i(__u.base())
1131 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001132#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001133 __get_db()->__iterator_copy(this, &__u);
1134#endif
1135 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001136#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001137 _LIBCPP_INLINE_VISIBILITY
1138 __wrap_iter(const __wrap_iter& __x)
1139 : __i(__x.base())
1140 {
1141 __get_db()->__iterator_copy(this, &__x);
1142 }
1143 _LIBCPP_INLINE_VISIBILITY
1144 __wrap_iter& operator=(const __wrap_iter& __x)
1145 {
1146 if (this != &__x)
1147 {
1148 __get_db()->__iterator_copy(this, &__x);
1149 __i = __x.__i;
1150 }
1151 return *this;
1152 }
1153 _LIBCPP_INLINE_VISIBILITY
1154 ~__wrap_iter()
1155 {
1156 __get_db()->__erase_i(this);
1157 }
1158#endif
1159 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1160 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001161#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001162 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1163 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001164#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001165 return *__i;
1166 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001167 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1168 {
1169#if _LIBCPP_DEBUG_LEVEL >= 2
1170 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1171 "Attempted to dereference a non-dereferenceable iterator");
1172#endif
1173 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
1174 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001175 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1176 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001177#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001178 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1179 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001180#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001181 ++__i;
1182 return *this;
1183 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001184 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001185 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1186 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1187 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001188#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001189 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1190 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001191#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001192 --__i;
1193 return *this;
1194 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001195 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001196 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001197 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001198 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001199 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001200 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001201#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001202 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1203 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001204#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001205 __i += __n;
1206 return *this;
1207 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001208 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001209 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001210 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001211 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001212 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001213 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001214#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001215 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1216 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001217#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001218 return __i[__n];
1219 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220
Howard Hinnanta6119a82011-05-29 19:57:12 +00001221 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222
1223private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001224#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001225 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1226 {
1227 __get_db()->__insert_ic(this, __p);
1228 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001229#else
1230 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001231#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232
1233 template <class _Up> friend class __wrap_iter;
1234 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1235 template <class _Tp, class _Alloc> friend class vector;
1236
1237 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 bool
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, class _Iter2>
1263 friend
1264 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001265 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001266
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267 template <class _Iter1, class _Iter2>
1268 friend
1269 typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001270 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001271
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272 template <class _Iter1>
1273 friend
1274 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001275 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001276
Howard Hinnant99968442011-11-29 18:15:50 +00001277 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001279 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1281
1282 template <class _Tp>
1283 friend
1284 typename enable_if
1285 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001286 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287 _Tp*
1288 >::type
1289 __unwrap_iter(__wrap_iter<_Tp*>);
1290};
1291
1292template <class _Iter1, class _Iter2>
1293inline _LIBCPP_INLINE_VISIBILITY
1294bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001295operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001296{
1297 return __x.base() == __y.base();
1298}
1299
1300template <class _Iter1, class _Iter2>
1301inline _LIBCPP_INLINE_VISIBILITY
1302bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001303operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001304{
Howard Hinnantabe26282011-09-16 17:29:17 +00001305#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001306 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001307 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001308#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309 return __x.base() < __y.base();
1310}
1311
1312template <class _Iter1, class _Iter2>
1313inline _LIBCPP_INLINE_VISIBILITY
1314bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001315operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001317 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318}
1319
1320template <class _Iter1, class _Iter2>
1321inline _LIBCPP_INLINE_VISIBILITY
1322bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001323operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001325 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001326}
1327
1328template <class _Iter1, class _Iter2>
1329inline _LIBCPP_INLINE_VISIBILITY
1330bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001331operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001333 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334}
1335
1336template <class _Iter1, class _Iter2>
1337inline _LIBCPP_INLINE_VISIBILITY
1338bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001339operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001341 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001342}
1343
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001344template <class _Iter1>
1345inline _LIBCPP_INLINE_VISIBILITY
1346bool
1347operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1348{
1349 return !(__x == __y);
1350}
1351
1352template <class _Iter1>
1353inline _LIBCPP_INLINE_VISIBILITY
1354bool
1355operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1356{
1357 return __y < __x;
1358}
1359
1360template <class _Iter1>
1361inline _LIBCPP_INLINE_VISIBILITY
1362bool
1363operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1364{
1365 return !(__x < __y);
1366}
1367
1368template <class _Iter1>
1369inline _LIBCPP_INLINE_VISIBILITY
1370bool
1371operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1372{
1373 return !(__y < __x);
1374}
1375
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376template <class _Iter1, class _Iter2>
1377inline _LIBCPP_INLINE_VISIBILITY
1378typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001379operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380{
Howard Hinnantabe26282011-09-16 17:29:17 +00001381#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001382 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001383 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001384#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385 return __x.base() - __y.base();
1386}
1387
1388template <class _Iter>
1389inline _LIBCPP_INLINE_VISIBILITY
1390__wrap_iter<_Iter>
1391operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001392 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001394 __x += __n;
1395 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396}
1397
Marshall Clow6daf5342013-12-02 03:24:33 +00001398template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001399inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001400_Tp*
1401begin(_Tp (&__array)[_Np])
1402{
1403 return __array;
1404}
1405
1406template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001407inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001408_Tp*
1409end(_Tp (&__array)[_Np])
1410{
1411 return __array + _Np;
1412}
1413
Marshall Clow1c398692013-12-11 19:32:32 +00001414#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1415
Howard Hinnant99968442011-11-29 18:15:50 +00001416template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001417inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418auto
Howard Hinnant99968442011-11-29 18:15:50 +00001419begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001420{
1421 return __c.begin();
1422}
1423
Howard Hinnant99968442011-11-29 18:15:50 +00001424template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001425inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426auto
Howard Hinnant99968442011-11-29 18:15:50 +00001427begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001428{
1429 return __c.begin();
1430}
1431
Howard Hinnant99968442011-11-29 18:15:50 +00001432template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001433inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434auto
Howard Hinnant99968442011-11-29 18:15:50 +00001435end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436{
1437 return __c.end();
1438}
1439
Howard Hinnant99968442011-11-29 18:15:50 +00001440template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001441inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442auto
Howard Hinnant99968442011-11-29 18:15:50 +00001443end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444{
1445 return __c.end();
1446}
1447
Marshall Clow09da3c02013-08-30 01:17:07 +00001448#if _LIBCPP_STD_VER > 11
1449
Marshall Clow6daf5342013-12-02 03:24:33 +00001450template <class _Tp, size_t _Np>
1451inline _LIBCPP_INLINE_VISIBILITY
1452reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1453{
1454 return reverse_iterator<_Tp*>(__array + _Np);
1455}
1456
1457template <class _Tp, size_t _Np>
1458inline _LIBCPP_INLINE_VISIBILITY
1459reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1460{
1461 return reverse_iterator<_Tp*>(__array);
1462}
1463
1464template <class _Ep>
1465inline _LIBCPP_INLINE_VISIBILITY
1466reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1467{
1468 return reverse_iterator<const _Ep*>(__il.end());
1469}
1470
1471template <class _Ep>
1472inline _LIBCPP_INLINE_VISIBILITY
1473reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1474{
1475 return reverse_iterator<const _Ep*>(__il.begin());
1476}
1477
Marshall Clow09da3c02013-08-30 01:17:07 +00001478template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001479inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001480auto cbegin(const _Cp& __c) -> decltype(begin(__c))
1481{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001482 return begin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001483}
1484
1485template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001486inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001487auto cend(const _Cp& __c) -> decltype(end(__c))
1488{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001489 return end(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001490}
1491
1492template <class _Cp>
1493inline _LIBCPP_INLINE_VISIBILITY
1494auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1495{
1496 return __c.rbegin();
1497}
1498
1499template <class _Cp>
1500inline _LIBCPP_INLINE_VISIBILITY
1501auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1502{
1503 return __c.rbegin();
1504}
1505
1506template <class _Cp>
1507inline _LIBCPP_INLINE_VISIBILITY
1508auto rend(_Cp& __c) -> decltype(__c.rend())
1509{
1510 return __c.rend();
1511}
1512
1513template <class _Cp>
1514inline _LIBCPP_INLINE_VISIBILITY
1515auto rend(const _Cp& __c) -> decltype(__c.rend())
1516{
1517 return __c.rend();
1518}
1519
1520template <class _Cp>
1521inline _LIBCPP_INLINE_VISIBILITY
1522auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
1523{
1524 return rbegin(__c);
1525}
1526
1527template <class _Cp>
1528inline _LIBCPP_INLINE_VISIBILITY
1529auto crend(const _Cp& __c) -> decltype(rend(__c))
1530{
1531 return rend(__c);
1532}
1533
1534#endif
1535
1536
Howard Hinnant726a76f2010-11-16 21:10:23 +00001537#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538
Howard Hinnant99968442011-11-29 18:15:50 +00001539template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001540inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001541typename _Cp::iterator
1542begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543{
1544 return __c.begin();
1545}
1546
Howard Hinnant99968442011-11-29 18:15:50 +00001547template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001548inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001549typename _Cp::const_iterator
1550begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551{
1552 return __c.begin();
1553}
1554
Howard Hinnant99968442011-11-29 18:15:50 +00001555template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001556inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001557typename _Cp::iterator
1558end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559{
1560 return __c.end();
1561}
1562
Howard Hinnant99968442011-11-29 18:15:50 +00001563template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001564inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001565typename _Cp::const_iterator
1566end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567{
1568 return __c.end();
1569}
1570
Howard Hinnant726a76f2010-11-16 21:10:23 +00001571#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001573_LIBCPP_END_NAMESPACE_STD
1574
1575#endif // _LIBCPP_ITERATOR