blob: 88e615a32539b8ef798a3d5748cf20e66492d242 [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
Eric Fiselierb9536102014-08-10 23:53:08 +0000341#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
Howard Hinnant08e17472011-10-17 20:05:10 +0000343#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000344#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000345#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346
347_LIBCPP_BEGIN_NAMESPACE_STD
348
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000349struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
350struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
351struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
352struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
353struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354
355template <class _Tp>
356struct __has_iterator_category
357{
358private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000359 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360 template <class _Up> static __two __test(...);
361 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
362public:
363 static const bool value = sizeof(__test<_Tp>(0)) == 1;
364};
365
Marshall Clowa71f9562014-01-03 22:55:49 +0000366template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367
368template <class _Iter>
Marshall Clowa71f9562014-01-03 22:55:49 +0000369struct __iterator_traits_impl<_Iter, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370{
371 typedef typename _Iter::difference_type difference_type;
372 typedef typename _Iter::value_type value_type;
373 typedef typename _Iter::pointer pointer;
374 typedef typename _Iter::reference reference;
375 typedef typename _Iter::iterator_category iterator_category;
376};
377
378template <class _Iter, bool> struct __iterator_traits {};
379
380template <class _Iter>
381struct __iterator_traits<_Iter, true>
Marshall Clowa71f9562014-01-03 22:55:49 +0000382 : __iterator_traits_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000383 <
384 _Iter,
385 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
386 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
387 >
388{};
389
390// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
391// exists. Else iterator_traits<Iterator> will be an empty class. This is a
392// conforming extension which allows some programs to compile and behave as
393// the client expects instead of failing at compile time.
394
395template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000396struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
398
399template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000400struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401{
402 typedef ptrdiff_t difference_type;
403 typedef typename remove_const<_Tp>::type value_type;
404 typedef _Tp* pointer;
405 typedef _Tp& reference;
406 typedef random_access_iterator_tag iterator_category;
407};
408
409template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
410struct __has_iterator_category_convertible_to
411 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
412{};
413
414template <class _Tp, class _Up>
415struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
416
417template <class _Tp>
418struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
419
420template <class _Tp>
421struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
422
423template <class _Tp>
424struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
425
426template <class _Tp>
427struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
428
429template<class _Category, class _Tp, class _Distance = ptrdiff_t,
430 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000431struct _LIBCPP_TYPE_VIS_ONLY iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432{
433 typedef _Tp value_type;
434 typedef _Distance difference_type;
435 typedef _Pointer pointer;
436 typedef _Reference reference;
437 typedef _Category iterator_category;
438};
439
440template <class _InputIter>
441inline _LIBCPP_INLINE_VISIBILITY
442void __advance(_InputIter& __i,
443 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
444{
445 for (; __n > 0; --__n)
446 ++__i;
447}
448
449template <class _BiDirIter>
450inline _LIBCPP_INLINE_VISIBILITY
451void __advance(_BiDirIter& __i,
452 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
453{
454 if (__n >= 0)
455 for (; __n > 0; --__n)
456 ++__i;
457 else
458 for (; __n < 0; ++__n)
459 --__i;
460}
461
462template <class _RandIter>
463inline _LIBCPP_INLINE_VISIBILITY
464void __advance(_RandIter& __i,
465 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
466{
467 __i += __n;
468}
469
470template <class _InputIter>
471inline _LIBCPP_INLINE_VISIBILITY
472void advance(_InputIter& __i,
473 typename iterator_traits<_InputIter>::difference_type __n)
474{
475 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
476}
477
478template <class _InputIter>
479inline _LIBCPP_INLINE_VISIBILITY
480typename iterator_traits<_InputIter>::difference_type
481__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
482{
483 typename iterator_traits<_InputIter>::difference_type __r(0);
484 for (; __first != __last; ++__first)
485 ++__r;
486 return __r;
487}
488
489template <class _RandIter>
490inline _LIBCPP_INLINE_VISIBILITY
491typename iterator_traits<_RandIter>::difference_type
492__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
493{
494 return __last - __first;
495}
496
497template <class _InputIter>
498inline _LIBCPP_INLINE_VISIBILITY
499typename iterator_traits<_InputIter>::difference_type
500distance(_InputIter __first, _InputIter __last)
501{
502 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
503}
504
505template <class _ForwardIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000506inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000507_ForwardIter
508next(_ForwardIter __x,
509 typename iterator_traits<_ForwardIter>::difference_type __n = 1,
510 typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
511{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000512 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000513 return __x;
514}
515
516template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000517inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518_BidiretionalIter
519prev(_BidiretionalIter __x,
520 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
521 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
522{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000523 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 return __x;
525}
526
527template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000528class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 : public iterator<typename iterator_traits<_Iter>::iterator_category,
530 typename iterator_traits<_Iter>::value_type,
531 typename iterator_traits<_Iter>::difference_type,
532 typename iterator_traits<_Iter>::pointer,
533 typename iterator_traits<_Iter>::reference>
534{
Marshall Clow668a1d82014-03-11 22:05:31 +0000535private:
536 mutable _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000537protected:
538 _Iter current;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539public:
540 typedef _Iter iterator_type;
541 typedef typename iterator_traits<_Iter>::difference_type difference_type;
542 typedef typename iterator_traits<_Iter>::reference reference;
543 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000544
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000545 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
546 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000548 : __t(__u.base()), current(__u.base()) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
Marshall Clowb1ead682014-03-11 17:16:17 +0000550 _LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;}
Marshall Clow02ca8af2014-02-27 02:11:50 +0000551 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
553 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
554 {reverse_iterator __tmp(*this); --current; return __tmp;}
555 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
556 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
557 {reverse_iterator __tmp(*this); ++current; return __tmp;}
558 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
559 {return reverse_iterator(current - __n);}
560 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
561 {current -= __n; return *this;}
562 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
563 {return reverse_iterator(current + __n);}
564 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
565 {current += __n; return *this;}
566 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
567 {return current[-__n-1];}
568};
569
570template <class _Iter1, class _Iter2>
571inline _LIBCPP_INLINE_VISIBILITY
572bool
573operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
574{
575 return __x.base() == __y.base();
576}
577
578template <class _Iter1, class _Iter2>
579inline _LIBCPP_INLINE_VISIBILITY
580bool
581operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
582{
583 return __x.base() > __y.base();
584}
585
586template <class _Iter1, class _Iter2>
587inline _LIBCPP_INLINE_VISIBILITY
588bool
589operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
590{
591 return __x.base() != __y.base();
592}
593
594template <class _Iter1, class _Iter2>
595inline _LIBCPP_INLINE_VISIBILITY
596bool
597operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
598{
599 return __x.base() < __y.base();
600}
601
602template <class _Iter1, class _Iter2>
603inline _LIBCPP_INLINE_VISIBILITY
604bool
605operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
606{
607 return __x.base() <= __y.base();
608}
609
610template <class _Iter1, class _Iter2>
611inline _LIBCPP_INLINE_VISIBILITY
612bool
613operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
614{
615 return __x.base() >= __y.base();
616}
617
618template <class _Iter1, class _Iter2>
619inline _LIBCPP_INLINE_VISIBILITY
620typename reverse_iterator<_Iter1>::difference_type
621operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
622{
623 return __y.base() - __x.base();
624}
625
626template <class _Iter>
627inline _LIBCPP_INLINE_VISIBILITY
628reverse_iterator<_Iter>
629operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
630{
631 return reverse_iterator<_Iter>(__x.base() - __n);
632}
633
Marshall Clowff137e92014-03-03 01:24:04 +0000634#if _LIBCPP_STD_VER > 11
635template <class _Iter>
636inline _LIBCPP_INLINE_VISIBILITY
637reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
638{
639 return reverse_iterator<_Iter>(__i);
640}
641#endif
642
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000644class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 : public iterator<output_iterator_tag,
646 void,
647 void,
648 void,
649 back_insert_iterator<_Container>&>
650{
651protected:
652 _Container* container;
653public:
654 typedef _Container container_type;
655
Marshall Clow53c0e722014-03-03 19:20:40 +0000656 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000657 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
658 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000659#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000660 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
661 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000662#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
664 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
665 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
666};
667
668template <class _Container>
669inline _LIBCPP_INLINE_VISIBILITY
670back_insert_iterator<_Container>
671back_inserter(_Container& __x)
672{
673 return back_insert_iterator<_Container>(__x);
674}
675
676template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000677class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678 : public iterator<output_iterator_tag,
679 void,
680 void,
681 void,
682 front_insert_iterator<_Container>&>
683{
684protected:
685 _Container* container;
686public:
687 typedef _Container container_type;
688
Marshall Clow53c0e722014-03-03 19:20:40 +0000689 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000690 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
691 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000692#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000693 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
694 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000695#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
697 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
698 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
699};
700
701template <class _Container>
702inline _LIBCPP_INLINE_VISIBILITY
703front_insert_iterator<_Container>
704front_inserter(_Container& __x)
705{
706 return front_insert_iterator<_Container>(__x);
707}
708
709template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000710class _LIBCPP_TYPE_VIS_ONLY insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 : public iterator<output_iterator_tag,
712 void,
713 void,
714 void,
715 insert_iterator<_Container>&>
716{
717protected:
718 _Container* container;
719 typename _Container::iterator iter;
720public:
721 typedef _Container container_type;
722
723 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clow53c0e722014-03-03 19:20:40 +0000724 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000725 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
726 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000727#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000728 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
729 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000730#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
732 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
733 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
734};
735
736template <class _Container>
737inline _LIBCPP_INLINE_VISIBILITY
738insert_iterator<_Container>
739inserter(_Container& __x, typename _Container::iterator __i)
740{
741 return insert_iterator<_Container>(__x, __i);
742}
743
744template <class _Tp, class _CharT = char,
745 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000746class _LIBCPP_TYPE_VIS_ONLY istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
748{
749public:
750 typedef _CharT char_type;
751 typedef _Traits traits_type;
752 typedef basic_istream<_CharT,_Traits> istream_type;
753private:
754 istream_type* __in_stream_;
755 _Tp __value_;
756public:
757 _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {}
758 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
759 {
760 if (!(*__in_stream_ >> __value_))
761 __in_stream_ = 0;
762 }
763
764 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
765 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
766 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
767 {
768 if (!(*__in_stream_ >> __value_))
769 __in_stream_ = 0;
770 return *this;
771 }
772 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
773 {istream_iterator __t(*this); ++(*this); return __t;}
774
775 friend _LIBCPP_INLINE_VISIBILITY
776 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
777 {return __x.__in_stream_ == __y.__in_stream_;}
778
779 friend _LIBCPP_INLINE_VISIBILITY
780 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
781 {return !(__x == __y);}
782};
783
784template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000785class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786 : public iterator<output_iterator_tag, void, void, void, void>
787{
788public:
789 typedef _CharT char_type;
790 typedef _Traits traits_type;
791 typedef basic_ostream<_CharT,_Traits> ostream_type;
792private:
793 ostream_type* __out_stream_;
794 const char_type* __delim_;
795public:
796 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
797 : __out_stream_(&__s), __delim_(0) {}
798 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
799 : __out_stream_(&__s), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000800 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000801 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000802 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 if (__delim_)
804 *__out_stream_ << __delim_;
805 return *this;
806 }
807
808 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
809 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
810 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
811};
812
813template<class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000814class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000815 : public iterator<input_iterator_tag, _CharT,
816 typename _Traits::off_type, _CharT*,
817 _CharT>
818{
819public:
820 typedef _CharT char_type;
821 typedef _Traits traits_type;
822 typedef typename _Traits::int_type int_type;
823 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
824 typedef basic_istream<_CharT,_Traits> istream_type;
825private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000826 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827
828 class __proxy
829 {
830 char_type __keep_;
831 streambuf_type* __sbuf_;
832 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
833 : __keep_(__c), __sbuf_(__s) {}
834 friend class istreambuf_iterator;
835 public:
836 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
837 };
838
Howard Hinnant82894812010-09-22 16:48:34 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000840 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 {
842 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
843 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000844 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845 }
846public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000847 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000848 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000849 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000850 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000851 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000852 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853 : __sbuf_(__p.__sbuf_) {}
854
Howard Hinnantec3773c2011-12-01 20:21:04 +0000855 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
856 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
858 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
859 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000860 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 return *this;
862 }
863 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
864 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000865 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 }
867
868 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000869 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870};
871
872template <class _CharT, class _Traits>
873inline _LIBCPP_INLINE_VISIBILITY
874bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
875 const istreambuf_iterator<_CharT,_Traits>& __b)
876 {return __a.equal(__b);}
877
878template <class _CharT, class _Traits>
879inline _LIBCPP_INLINE_VISIBILITY
880bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
881 const istreambuf_iterator<_CharT,_Traits>& __b)
882 {return !__a.equal(__b);}
883
884template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000885class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886 : public iterator<output_iterator_tag, void, void, void, void>
887{
888public:
889 typedef _CharT char_type;
890 typedef _Traits traits_type;
891 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
892 typedef basic_ostream<_CharT,_Traits> ostream_type;
893private:
894 streambuf_type* __sbuf_;
895public:
Howard Hinnantd06a6402012-07-20 19:36:34 +0000896 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000898 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 : __sbuf_(__s) {}
900 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
901 {
902 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
903 __sbuf_ = 0;
904 return *this;
905 }
906 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
907 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
908 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000909 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +0000910
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000911#if !defined(__APPLE__) || \
912 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
913 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
914
Howard Hinnanta585de62012-09-19 19:14:15 +0000915 template <class _Ch, class _Tr>
916 friend
917 _LIBCPP_HIDDEN
918 ostreambuf_iterator<_Ch, _Tr>
919 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
920 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
921 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000922#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923};
924
925template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000926class _LIBCPP_TYPE_VIS_ONLY move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927{
928private:
929 _Iter __i;
930public:
931 typedef _Iter iterator_type;
932 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
933 typedef typename iterator_traits<iterator_type>::value_type value_type;
934 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
935 typedef typename iterator_traits<iterator_type>::pointer pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000936#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000937 typedef value_type&& reference;
938#else
939 typedef typename iterator_traits<iterator_type>::reference reference;
940#endif
Howard Hinnant324bb032010-08-22 00:02:43 +0000941
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000942 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
943 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
944 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
945 : __i(__u.base()) {}
946 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +0000947 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
948 return static_cast<reference>(*__i);
949 }
950 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
951 typename iterator_traits<iterator_type>::reference __ref = *__i;
952 return &__ref;
953 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
955 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
956 {move_iterator __tmp(*this); ++__i; return __tmp;}
957 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
958 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
959 {move_iterator __tmp(*this); --__i; return __tmp;}
960 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
961 {return move_iterator(__i + __n);}
962 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
963 {__i += __n; return *this;}
964 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
965 {return move_iterator(__i - __n);}
966 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
967 {__i -= __n; return *this;}
968 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +0000969 {
970 return static_cast<reference>(__i[__n]);
971 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972};
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
1016bool
1017operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1018{
1019 return __x.base() <= __y.base();
1020}
1021
1022template <class _Iter1, class _Iter2>
1023inline _LIBCPP_INLINE_VISIBILITY
1024typename move_iterator<_Iter1>::difference_type
1025operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1026{
1027 return __x.base() - __y.base();
1028}
1029
1030template <class _Iter>
1031inline _LIBCPP_INLINE_VISIBILITY
1032move_iterator<_Iter>
1033operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1034{
1035 return move_iterator<_Iter>(__x.base() + __n);
1036}
1037
1038template <class _Iter>
1039inline _LIBCPP_INLINE_VISIBILITY
1040move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:03 +00001041make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042{
1043 return move_iterator<_Iter>(__i);
1044}
1045
1046// __wrap_iter
1047
1048template <class _Iter> class __wrap_iter;
1049
1050template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001051_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001053operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054
1055template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001056_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001058operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059
1060template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001061_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001062bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001063operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064
1065template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001066_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001068operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069
1070template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001071_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001073operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074
1075template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001076_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001078operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079
1080template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001081_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001083operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001084
1085template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001086_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001088operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089
Howard Hinnant33be35e2012-09-14 00:39:16 +00001090template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1091template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1092template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1093template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094
1095template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001096_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097typename enable_if
1098<
Howard Hinnant1468b662010-11-19 22:17:28 +00001099 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100 _Tp*
1101>::type
1102__unwrap_iter(__wrap_iter<_Tp*>);
1103
1104template <class _Iter>
1105class __wrap_iter
1106{
1107public:
1108 typedef _Iter iterator_type;
1109 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1110 typedef typename iterator_traits<iterator_type>::value_type value_type;
1111 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1112 typedef typename iterator_traits<iterator_type>::pointer pointer;
1113 typedef typename iterator_traits<iterator_type>::reference reference;
1114private:
1115 iterator_type __i;
1116public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001117 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001118#if _LIBCPP_STD_VER > 11
1119 : __i{}
1120#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001121 {
1122#if _LIBCPP_DEBUG_LEVEL >= 2
1123 __get_db()->__insert_i(this);
1124#endif
1125 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001126 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001127 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001128 : __i(__u.base())
1129 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001130#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001131 __get_db()->__iterator_copy(this, &__u);
1132#endif
1133 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001134#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001135 _LIBCPP_INLINE_VISIBILITY
1136 __wrap_iter(const __wrap_iter& __x)
1137 : __i(__x.base())
1138 {
1139 __get_db()->__iterator_copy(this, &__x);
1140 }
1141 _LIBCPP_INLINE_VISIBILITY
1142 __wrap_iter& operator=(const __wrap_iter& __x)
1143 {
1144 if (this != &__x)
1145 {
1146 __get_db()->__iterator_copy(this, &__x);
1147 __i = __x.__i;
1148 }
1149 return *this;
1150 }
1151 _LIBCPP_INLINE_VISIBILITY
1152 ~__wrap_iter()
1153 {
1154 __get_db()->__erase_i(this);
1155 }
1156#endif
1157 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1158 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001159#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001160 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1161 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001162#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001163 return *__i;
1164 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001165 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1166 {
1167#if _LIBCPP_DEBUG_LEVEL >= 2
1168 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1169 "Attempted to dereference a non-dereferenceable iterator");
1170#endif
1171 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
1172 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001173 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1174 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001175#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001176 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1177 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001178#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001179 ++__i;
1180 return *this;
1181 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001182 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001183 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1184 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1185 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001186#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001187 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1188 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001189#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001190 --__i;
1191 return *this;
1192 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001193 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001194 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001195 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001196 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001197 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001198 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001199#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001200 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1201 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001202#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001203 __i += __n;
1204 return *this;
1205 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001206 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001207 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001208 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001209 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001210 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001211 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001212#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001213 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1214 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001215#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001216 return __i[__n];
1217 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218
Howard Hinnanta6119a82011-05-29 19:57:12 +00001219 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220
1221private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001222#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001223 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1224 {
1225 __get_db()->__insert_ic(this, __p);
1226 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001227#else
1228 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001229#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230
1231 template <class _Up> friend class __wrap_iter;
1232 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1233 template <class _Tp, class _Alloc> friend class vector;
1234
1235 template <class _Iter1, class _Iter2>
1236 friend
1237 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001238 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001239
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240 template <class _Iter1, class _Iter2>
1241 friend
1242 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001243 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001244
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245 template <class _Iter1, class _Iter2>
1246 friend
1247 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001248 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001249
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250 template <class _Iter1, class _Iter2>
1251 friend
1252 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001253 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001254
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255 template <class _Iter1, class _Iter2>
1256 friend
1257 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001258 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001259
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260 template <class _Iter1, class _Iter2>
1261 friend
1262 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001263 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001264
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001265 template <class _Iter1, class _Iter2>
1266 friend
1267 typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001268 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001269
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001270 template <class _Iter1>
1271 friend
1272 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001273 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274
Howard Hinnant99968442011-11-29 18:15:50 +00001275 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001276 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001277 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1279
1280 template <class _Tp>
1281 friend
1282 typename enable_if
1283 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001284 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001285 _Tp*
1286 >::type
1287 __unwrap_iter(__wrap_iter<_Tp*>);
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{
1295 return __x.base() == __y.base();
1296}
1297
1298template <class _Iter1, class _Iter2>
1299inline _LIBCPP_INLINE_VISIBILITY
1300bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001301operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001302{
Howard Hinnantabe26282011-09-16 17:29:17 +00001303#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001304 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001305 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001306#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307 return __x.base() < __y.base();
1308}
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 !(__x == __y);
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 __y < __x;
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 !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332}
1333
1334template <class _Iter1, class _Iter2>
1335inline _LIBCPP_INLINE_VISIBILITY
1336bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001337operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001339 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340}
1341
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001342template <class _Iter1>
1343inline _LIBCPP_INLINE_VISIBILITY
1344bool
1345operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1346{
1347 return !(__x == __y);
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 __y < __x;
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 !(__x < __y);
1364}
1365
1366template <class _Iter1>
1367inline _LIBCPP_INLINE_VISIBILITY
1368bool
1369operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1370{
1371 return !(__y < __x);
1372}
1373
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374template <class _Iter1, class _Iter2>
1375inline _LIBCPP_INLINE_VISIBILITY
1376typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001377operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378{
Howard Hinnantabe26282011-09-16 17:29:17 +00001379#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001380 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001381 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001382#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383 return __x.base() - __y.base();
1384}
1385
1386template <class _Iter>
1387inline _LIBCPP_INLINE_VISIBILITY
1388__wrap_iter<_Iter>
1389operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001390 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001392 __x += __n;
1393 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394}
1395
Marshall Clow6daf5342013-12-02 03:24:33 +00001396template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001397inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001398_Tp*
1399begin(_Tp (&__array)[_Np])
1400{
1401 return __array;
1402}
1403
1404template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001405inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001406_Tp*
1407end(_Tp (&__array)[_Np])
1408{
1409 return __array + _Np;
1410}
1411
Marshall Clow1c398692013-12-11 19:32:32 +00001412#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
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(_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 +00001425begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426{
1427 return __c.begin();
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(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434{
1435 return __c.end();
1436}
1437
Howard Hinnant99968442011-11-29 18:15:50 +00001438template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001439inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001440auto
Howard Hinnant99968442011-11-29 18:15:50 +00001441end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442{
1443 return __c.end();
1444}
1445
Marshall Clow09da3c02013-08-30 01:17:07 +00001446#if _LIBCPP_STD_VER > 11
1447
Marshall Clow6daf5342013-12-02 03:24:33 +00001448template <class _Tp, size_t _Np>
1449inline _LIBCPP_INLINE_VISIBILITY
1450reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1451{
1452 return reverse_iterator<_Tp*>(__array + _Np);
1453}
1454
1455template <class _Tp, size_t _Np>
1456inline _LIBCPP_INLINE_VISIBILITY
1457reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1458{
1459 return reverse_iterator<_Tp*>(__array);
1460}
1461
1462template <class _Ep>
1463inline _LIBCPP_INLINE_VISIBILITY
1464reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1465{
1466 return reverse_iterator<const _Ep*>(__il.end());
1467}
1468
1469template <class _Ep>
1470inline _LIBCPP_INLINE_VISIBILITY
1471reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1472{
1473 return reverse_iterator<const _Ep*>(__il.begin());
1474}
1475
Marshall Clow09da3c02013-08-30 01:17:07 +00001476template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001477inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001478auto cbegin(const _Cp& __c) -> decltype(begin(__c))
1479{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001480 return begin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001481}
1482
1483template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001484inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001485auto cend(const _Cp& __c) -> decltype(end(__c))
1486{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001487 return end(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001488}
1489
1490template <class _Cp>
1491inline _LIBCPP_INLINE_VISIBILITY
1492auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1493{
1494 return __c.rbegin();
1495}
1496
1497template <class _Cp>
1498inline _LIBCPP_INLINE_VISIBILITY
1499auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1500{
1501 return __c.rbegin();
1502}
1503
1504template <class _Cp>
1505inline _LIBCPP_INLINE_VISIBILITY
1506auto rend(_Cp& __c) -> decltype(__c.rend())
1507{
1508 return __c.rend();
1509}
1510
1511template <class _Cp>
1512inline _LIBCPP_INLINE_VISIBILITY
1513auto rend(const _Cp& __c) -> decltype(__c.rend())
1514{
1515 return __c.rend();
1516}
1517
1518template <class _Cp>
1519inline _LIBCPP_INLINE_VISIBILITY
1520auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
1521{
1522 return rbegin(__c);
1523}
1524
1525template <class _Cp>
1526inline _LIBCPP_INLINE_VISIBILITY
1527auto crend(const _Cp& __c) -> decltype(rend(__c))
1528{
1529 return rend(__c);
1530}
1531
1532#endif
1533
1534
Howard Hinnant726a76f2010-11-16 21:10:23 +00001535#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001536
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::iterator
1540begin(_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::const_iterator
1548begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001549{
1550 return __c.begin();
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::iterator
1556end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557{
1558 return __c.end();
1559}
1560
Howard Hinnant99968442011-11-29 18:15:50 +00001561template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001562inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001563typename _Cp::const_iterator
1564end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565{
1566 return __c.end();
1567}
1568
Howard Hinnant726a76f2010-11-16 21:10:23 +00001569#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001570
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571_LIBCPP_END_NAMESPACE_STD
1572
1573#endif // _LIBCPP_ITERATOR