blob: b1bcdfc10b0e718aed1016428ec6eb453e3fc86e [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_ITERATOR
12#define _LIBCPP_ITERATOR
13
14/*
15 iterator synopsis
16
17namespace std
18{
19
20template<class Iterator>
21struct iterator_traits
22{
23 typedef typename Iterator::difference_type difference_type;
24 typedef typename Iterator::value_type value_type;
25 typedef typename Iterator::pointer pointer;
26 typedef typename Iterator::reference reference;
27 typedef typename Iterator::iterator_category iterator_category;
28};
29
30template<class T>
31struct iterator_traits<T*>
32{
33 typedef ptrdiff_t difference_type;
34 typedef T value_type;
35 typedef T* pointer;
36 typedef T& reference;
37 typedef random_access_iterator_tag iterator_category;
38};
39
40template<class T>
41struct iterator_traits<const T*>
42{
43 typedef ptrdiff_t difference_type;
44 typedef T value_type;
45 typedef const T* pointer;
46 typedef const T& reference;
47 typedef random_access_iterator_tag iterator_category;
48};
49
50template<class Category, class T, class Distance = ptrdiff_t,
51 class Pointer = T*, class Reference = T&>
52struct iterator
53{
54 typedef T value_type;
55 typedef Distance difference_type;
56 typedef Pointer pointer;
57 typedef Reference reference;
58 typedef Category iterator_category;
59};
60
61struct input_iterator_tag {};
62struct output_iterator_tag {};
63struct forward_iterator_tag : public input_iterator_tag {};
64struct bidirectional_iterator_tag : public forward_iterator_tag {};
65struct random_access_iterator_tag : public bidirectional_iterator_tag {};
66
67// extension: second argument not conforming to C++03
68template <class InputIterator>
69void advance(InputIterator& i,
70 typename iterator_traits<InputIterator>::difference_type n);
71
72template <class InputIterator>
73typename iterator_traits<InputIterator>::difference_type
74distance(InputIterator first, InputIterator last);
75
76template <class Iterator>
77class reverse_iterator
78 : public iterator<typename iterator_traits<Iterator>::iterator_category,
79 typename iterator_traits<Iterator>::value_type,
80 typename iterator_traits<Iterator>::difference_type,
81 typename iterator_traits<Iterator>::pointer,
82 typename iterator_traits<Iterator>::reference>
83{
84protected:
85 Iterator current;
86public:
87 typedef Iterator iterator_type;
88 typedef typename iterator_traits<Iterator>::difference_type difference_type;
89 typedef typename iterator_traits<Iterator>::reference reference;
90 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +000091
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092 reverse_iterator();
93 explicit reverse_iterator(Iterator x);
94 template <class U> reverse_iterator(const reverse_iterator<U>& u);
95 Iterator base() const;
96 reference operator*() const;
97 pointer operator->() const;
98 reverse_iterator& operator++();
99 reverse_iterator operator++(int);
100 reverse_iterator& operator--();
101 reverse_iterator operator--(int);
102 reverse_iterator operator+ (difference_type n) const;
103 reverse_iterator& operator+=(difference_type n);
104 reverse_iterator operator- (difference_type n) const;
105 reverse_iterator& operator-=(difference_type n);
106 reference operator[](difference_type n) const;
107};
108
109template <class Iterator1, class Iterator2>
110bool
111operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
112
113template <class Iterator1, class Iterator2>
114bool
115operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
116
117template <class Iterator1, class Iterator2>
118bool
119operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
120
121template <class Iterator1, class Iterator2>
122bool
123operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
124
125template <class Iterator1, class Iterator2>
126bool
127operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
128
129template <class Iterator1, class Iterator2>
130bool
131operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
132
133template <class Iterator1, class Iterator2>
134typename reverse_iterator<Iterator1>::difference_type
135operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
136
137template <class Iterator>
138reverse_iterator<Iterator>
139operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x);
140
141template <class Container>
142class back_insert_iterator
143{
144protected:
145 Container* container;
146public:
147 typedef Container container_type;
148 typedef void value_type;
149 typedef void difference_type;
150 typedef back_insert_iterator<Cont>& reference;
151 typedef void pointer;
152
153 explicit back_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000154 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155 back_insert_iterator& operator*();
156 back_insert_iterator& operator++();
157 back_insert_iterator operator++(int);
158};
159
160template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
161
162template <class Container>
163class front_insert_iterator
164{
165protected:
166 Container* container;
167public:
168 typedef Container container_type;
169 typedef void value_type;
170 typedef void difference_type;
171 typedef front_insert_iterator<Cont>& reference;
172 typedef void pointer;
173
174 explicit front_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000175 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176 front_insert_iterator& operator*();
177 front_insert_iterator& operator++();
178 front_insert_iterator operator++(int);
179};
180
181template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
182
183template <class Container>
184class insert_iterator
185{
186protected:
187 Container* container;
188 typename Container::iterator iter;
189public:
190 typedef Container container_type;
191 typedef void value_type;
192 typedef void difference_type;
193 typedef insert_iterator<Cont>& reference;
194 typedef void pointer;
195
196 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant45f57172010-09-14 20:26:27 +0000197 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198 insert_iterator& operator*();
199 insert_iterator& operator++();
200 insert_iterator& operator++(int);
201};
202
203template <class Container, class Iterator>
204insert_iterator<Container> inserter(Container& x, Iterator i);
205
206template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
207class istream_iterator
208 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
209{
210public:
211 typedef charT char_type;
212 typedef traits traits_type;
213 typedef basic_istream<charT,traits> istream_type;
214
215 istream_iterator();
216 istream_iterator(istream_type& s);
217 istream_iterator(const istream_iterator& x);
218 ~istream_iterator();
219
220 const T& operator*() const;
221 const T* operator->() const;
222 istream_iterator& operator++();
223 istream_iterator operator++(int);
224};
225
226template <class T, class charT, class traits, class Distance>
227bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
228 const istream_iterator<T,charT,traits,Distance>& y);
229template <class T, class charT, class traits, class Distance>
230bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
231 const istream_iterator<T,charT,traits,Distance>& y);
232
233template <class T, class charT = char, class traits = char_traits<charT> >
234class ostream_iterator
235 : public iterator<output_iterator_tag, void, void, void ,void>
236{
237public:
238 typedef charT char_type;
239 typedef traits traits_type;
240 typedef basic_ostream<charT,traits> ostream_type;
241
242 ostream_iterator(ostream_type& s);
243 ostream_iterator(ostream_type& s, const charT* delimiter);
244 ostream_iterator(const ostream_iterator& x);
245 ~ostream_iterator();
246 ostream_iterator& operator=(const T& value);
247
248 ostream_iterator& operator*();
249 ostream_iterator& operator++();
250 ostream_iterator& operator++(int);
251};
252
253template<class charT, class traits = char_traits<charT> >
254class istreambuf_iterator
255 : public iterator<input_iterator_tag, charT,
256 typename traits::off_type, unspecified,
257 charT>
258{
259public:
260 typedef charT char_type;
261 typedef traits traits_type;
262 typedef typename traits::int_type int_type;
263 typedef basic_streambuf<charT,traits> streambuf_type;
264 typedef basic_istream<charT,traits> istream_type;
265
Howard Hinnantd06a6402012-07-20 19:36:34 +0000266 istreambuf_iterator() noexcept;
267 istreambuf_iterator(istream_type& s) noexcept;
268 istreambuf_iterator(streambuf_type* s) noexcept;
269 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270
271 charT operator*() const;
272 pointer operator->() const;
273 istreambuf_iterator& operator++();
274 a-private-type operator++(int);
275
276 bool equal(const istreambuf_iterator& b) const;
277};
278
279template <class charT, class traits>
280bool operator==(const istreambuf_iterator<charT,traits>& a,
281 const istreambuf_iterator<charT,traits>& b);
282template <class charT, class traits>
283bool operator!=(const istreambuf_iterator<charT,traits>& a,
284 const istreambuf_iterator<charT,traits>& b);
285
286template <class charT, class traits = char_traits<charT> >
287class ostreambuf_iterator
288 : public iterator<output_iterator_tag, void, void, void, void>
289{
290public:
291 typedef charT char_type;
292 typedef traits traits_type;
293 typedef basic_streambuf<charT,traits> streambuf_type;
294 typedef basic_ostream<charT,traits> ostream_type;
295
Howard Hinnantd06a6402012-07-20 19:36:34 +0000296 ostreambuf_iterator(ostream_type& s) noexcept;
297 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298 ostreambuf_iterator& operator=(charT c);
299 ostreambuf_iterator& operator*();
300 ostreambuf_iterator& operator++();
301 ostreambuf_iterator& operator++(int);
Howard Hinnantd06a6402012-07-20 19:36:34 +0000302 bool failed() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303};
304
305template <class C> auto begin(C& c) -> decltype(c.begin());
306template <class C> auto begin(const C& c) -> decltype(c.begin());
307template <class C> auto end(C& c) -> decltype(c.end());
308template <class C> auto end(const C& c) -> decltype(c.end());
309template <class T, size_t N> T* begin(T (&array)[N]);
310template <class T, size_t N> T* end(T (&array)[N]);
311
Marshall Clow09da3c02013-08-30 01:17:07 +0000312template <class C> auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14
313template <class C> auto cend(const C& c) -> decltype(std::end(c)); // C++14
314template <class C> auto rbegin(C& c) -> decltype(c.rbegin()); // C++14
315template <class C> auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14
316template <class C> auto rend(C& c) -> decltype(c.rend()); // C++14
317template <class C> auto rend(const C& c) -> decltype(c.rend()); // C++14
318template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14
319template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); // C++14
320template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]); // C++14
321template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]); // C++14
322template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
323template <class C> auto crend(const C& c) -> decltype(std::rend(c)); // C++14
324
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325} // std
326
327*/
328
329#include <__config>
Marshall Clow02ca8af2014-02-27 02:11:50 +0000330#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331#include <type_traits>
332#include <cstddef>
333#include <iosfwd>
Marshall Clow09da3c02013-08-30 01:17:07 +0000334#include <initializer_list>
Marshall Clowdece7fe2013-03-18 17:45:34 +0000335#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000336#include <Availability.h>
337#endif
338
Howard Hinnant5e571422013-08-23 20:10:18 +0000339#ifdef _LIBCPP_DEBUG
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000340# include <__debug>
341#else
342# define _LIBCPP_ASSERT(x, m) ((void)0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343#endif
344
Howard Hinnant08e17472011-10-17 20:05:10 +0000345#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000347#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348
349_LIBCPP_BEGIN_NAMESPACE_STD
350
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000351struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
352struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
353struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
354struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
355struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356
357template <class _Tp>
358struct __has_iterator_category
359{
360private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000361 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362 template <class _Up> static __two __test(...);
363 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
364public:
365 static const bool value = sizeof(__test<_Tp>(0)) == 1;
366};
367
Marshall Clowa71f9562014-01-03 22:55:49 +0000368template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369
370template <class _Iter>
Marshall Clowa71f9562014-01-03 22:55:49 +0000371struct __iterator_traits_impl<_Iter, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372{
373 typedef typename _Iter::difference_type difference_type;
374 typedef typename _Iter::value_type value_type;
375 typedef typename _Iter::pointer pointer;
376 typedef typename _Iter::reference reference;
377 typedef typename _Iter::iterator_category iterator_category;
378};
379
380template <class _Iter, bool> struct __iterator_traits {};
381
382template <class _Iter>
383struct __iterator_traits<_Iter, true>
Marshall Clowa71f9562014-01-03 22:55:49 +0000384 : __iterator_traits_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385 <
386 _Iter,
387 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
388 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
389 >
390{};
391
392// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
393// exists. Else iterator_traits<Iterator> will be an empty class. This is a
394// conforming extension which allows some programs to compile and behave as
395// the client expects instead of failing at compile time.
396
397template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000398struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
400
401template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000402struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403{
404 typedef ptrdiff_t difference_type;
405 typedef typename remove_const<_Tp>::type value_type;
406 typedef _Tp* pointer;
407 typedef _Tp& reference;
408 typedef random_access_iterator_tag iterator_category;
409};
410
411template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
412struct __has_iterator_category_convertible_to
413 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
414{};
415
416template <class _Tp, class _Up>
417struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
418
419template <class _Tp>
420struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
421
422template <class _Tp>
423struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
424
425template <class _Tp>
426struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
427
428template <class _Tp>
429struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
430
431template<class _Category, class _Tp, class _Distance = ptrdiff_t,
432 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000433struct _LIBCPP_TYPE_VIS_ONLY iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434{
435 typedef _Tp value_type;
436 typedef _Distance difference_type;
437 typedef _Pointer pointer;
438 typedef _Reference reference;
439 typedef _Category iterator_category;
440};
441
442template <class _InputIter>
443inline _LIBCPP_INLINE_VISIBILITY
444void __advance(_InputIter& __i,
445 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
446{
447 for (; __n > 0; --__n)
448 ++__i;
449}
450
451template <class _BiDirIter>
452inline _LIBCPP_INLINE_VISIBILITY
453void __advance(_BiDirIter& __i,
454 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
455{
456 if (__n >= 0)
457 for (; __n > 0; --__n)
458 ++__i;
459 else
460 for (; __n < 0; ++__n)
461 --__i;
462}
463
464template <class _RandIter>
465inline _LIBCPP_INLINE_VISIBILITY
466void __advance(_RandIter& __i,
467 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
468{
469 __i += __n;
470}
471
472template <class _InputIter>
473inline _LIBCPP_INLINE_VISIBILITY
474void advance(_InputIter& __i,
475 typename iterator_traits<_InputIter>::difference_type __n)
476{
477 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
478}
479
480template <class _InputIter>
481inline _LIBCPP_INLINE_VISIBILITY
482typename iterator_traits<_InputIter>::difference_type
483__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
484{
485 typename iterator_traits<_InputIter>::difference_type __r(0);
486 for (; __first != __last; ++__first)
487 ++__r;
488 return __r;
489}
490
491template <class _RandIter>
492inline _LIBCPP_INLINE_VISIBILITY
493typename iterator_traits<_RandIter>::difference_type
494__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
495{
496 return __last - __first;
497}
498
499template <class _InputIter>
500inline _LIBCPP_INLINE_VISIBILITY
501typename iterator_traits<_InputIter>::difference_type
502distance(_InputIter __first, _InputIter __last)
503{
504 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
505}
506
507template <class _ForwardIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000508inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509_ForwardIter
510next(_ForwardIter __x,
511 typename iterator_traits<_ForwardIter>::difference_type __n = 1,
512 typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
513{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000514 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 return __x;
516}
517
518template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000519inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520_BidiretionalIter
521prev(_BidiretionalIter __x,
522 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
523 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
524{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000525 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526 return __x;
527}
528
529template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000530class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 : public iterator<typename iterator_traits<_Iter>::iterator_category,
532 typename iterator_traits<_Iter>::value_type,
533 typename iterator_traits<_Iter>::difference_type,
534 typename iterator_traits<_Iter>::pointer,
535 typename iterator_traits<_Iter>::reference>
536{
537private:
538 mutable _Iter __t;
539protected:
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() {}
548 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
549 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
550 : __t(__u.base()), current(__u.base()) {}
551 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
552 _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;}
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
636template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000637class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000638 : public iterator<output_iterator_tag,
639 void,
640 void,
641 void,
642 back_insert_iterator<_Container>&>
643{
644protected:
645 _Container* container;
646public:
647 typedef _Container container_type;
648
649 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000650 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
651 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000652#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000653 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
654 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000655#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
657 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
658 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
659};
660
661template <class _Container>
662inline _LIBCPP_INLINE_VISIBILITY
663back_insert_iterator<_Container>
664back_inserter(_Container& __x)
665{
666 return back_insert_iterator<_Container>(__x);
667}
668
669template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000670class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671 : public iterator<output_iterator_tag,
672 void,
673 void,
674 void,
675 front_insert_iterator<_Container>&>
676{
677protected:
678 _Container* container;
679public:
680 typedef _Container container_type;
681
682 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000683 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
684 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000685#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000686 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
687 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000688#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
690 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
691 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
692};
693
694template <class _Container>
695inline _LIBCPP_INLINE_VISIBILITY
696front_insert_iterator<_Container>
697front_inserter(_Container& __x)
698{
699 return front_insert_iterator<_Container>(__x);
700}
701
702template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000703class _LIBCPP_TYPE_VIS_ONLY insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 : public iterator<output_iterator_tag,
705 void,
706 void,
707 void,
708 insert_iterator<_Container>&>
709{
710protected:
711 _Container* container;
712 typename _Container::iterator iter;
713public:
714 typedef _Container container_type;
715
716 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
717 : container(&__x), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000718 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
719 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000720#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000721 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
722 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000723#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
725 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
726 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
727};
728
729template <class _Container>
730inline _LIBCPP_INLINE_VISIBILITY
731insert_iterator<_Container>
732inserter(_Container& __x, typename _Container::iterator __i)
733{
734 return insert_iterator<_Container>(__x, __i);
735}
736
737template <class _Tp, class _CharT = char,
738 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000739class _LIBCPP_TYPE_VIS_ONLY istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000740 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
741{
742public:
743 typedef _CharT char_type;
744 typedef _Traits traits_type;
745 typedef basic_istream<_CharT,_Traits> istream_type;
746private:
747 istream_type* __in_stream_;
748 _Tp __value_;
749public:
750 _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {}
751 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
752 {
753 if (!(*__in_stream_ >> __value_))
754 __in_stream_ = 0;
755 }
756
757 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
758 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
759 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
760 {
761 if (!(*__in_stream_ >> __value_))
762 __in_stream_ = 0;
763 return *this;
764 }
765 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
766 {istream_iterator __t(*this); ++(*this); return __t;}
767
768 friend _LIBCPP_INLINE_VISIBILITY
769 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
770 {return __x.__in_stream_ == __y.__in_stream_;}
771
772 friend _LIBCPP_INLINE_VISIBILITY
773 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
774 {return !(__x == __y);}
775};
776
777template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000778class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 : public iterator<output_iterator_tag, void, void, void, void>
780{
781public:
782 typedef _CharT char_type;
783 typedef _Traits traits_type;
784 typedef basic_ostream<_CharT,_Traits> ostream_type;
785private:
786 ostream_type* __out_stream_;
787 const char_type* __delim_;
788public:
789 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
790 : __out_stream_(&__s), __delim_(0) {}
791 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
792 : __out_stream_(&__s), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000793 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000795 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000796 if (__delim_)
797 *__out_stream_ << __delim_;
798 return *this;
799 }
800
801 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
802 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
803 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
804};
805
806template<class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000807class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808 : public iterator<input_iterator_tag, _CharT,
809 typename _Traits::off_type, _CharT*,
810 _CharT>
811{
812public:
813 typedef _CharT char_type;
814 typedef _Traits traits_type;
815 typedef typename _Traits::int_type int_type;
816 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
817 typedef basic_istream<_CharT,_Traits> istream_type;
818private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000819 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820
821 class __proxy
822 {
823 char_type __keep_;
824 streambuf_type* __sbuf_;
825 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
826 : __keep_(__c), __sbuf_(__s) {}
827 friend class istreambuf_iterator;
828 public:
829 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
830 };
831
Howard Hinnant82894812010-09-22 16:48:34 +0000832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000833 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000834 {
835 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
836 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000837 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838 }
839public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000840 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000841 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000842 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000843 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000844 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000845 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000846 : __sbuf_(__p.__sbuf_) {}
847
Howard Hinnantec3773c2011-12-01 20:21:04 +0000848 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
849 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
851 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
852 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000853 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854 return *this;
855 }
856 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
857 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000858 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 }
860
861 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000862 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863};
864
865template <class _CharT, class _Traits>
866inline _LIBCPP_INLINE_VISIBILITY
867bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
868 const istreambuf_iterator<_CharT,_Traits>& __b)
869 {return __a.equal(__b);}
870
871template <class _CharT, class _Traits>
872inline _LIBCPP_INLINE_VISIBILITY
873bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
874 const istreambuf_iterator<_CharT,_Traits>& __b)
875 {return !__a.equal(__b);}
876
877template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000878class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 : public iterator<output_iterator_tag, void, void, void, void>
880{
881public:
882 typedef _CharT char_type;
883 typedef _Traits traits_type;
884 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
885 typedef basic_ostream<_CharT,_Traits> ostream_type;
886private:
887 streambuf_type* __sbuf_;
888public:
Howard Hinnantd06a6402012-07-20 19:36:34 +0000889 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000891 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892 : __sbuf_(__s) {}
893 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
894 {
895 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
896 __sbuf_ = 0;
897 return *this;
898 }
899 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
900 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
901 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000902 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +0000903
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000904#if !defined(__APPLE__) || \
905 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
906 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
907
Howard Hinnanta585de62012-09-19 19:14:15 +0000908 template <class _Ch, class _Tr>
909 friend
910 _LIBCPP_HIDDEN
911 ostreambuf_iterator<_Ch, _Tr>
912 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
913 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
914 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000915#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916};
917
918template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000919class _LIBCPP_TYPE_VIS_ONLY move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920{
921private:
922 _Iter __i;
923public:
924 typedef _Iter iterator_type;
925 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
926 typedef typename iterator_traits<iterator_type>::value_type value_type;
927 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
928 typedef typename iterator_traits<iterator_type>::pointer pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000929#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930 typedef value_type&& reference;
931#else
932 typedef typename iterator_traits<iterator_type>::reference reference;
933#endif
Howard Hinnant324bb032010-08-22 00:02:43 +0000934
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
936 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
937 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
938 : __i(__u.base()) {}
939 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +0000940 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
941 return static_cast<reference>(*__i);
942 }
943 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
944 typename iterator_traits<iterator_type>::reference __ref = *__i;
945 return &__ref;
946 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
948 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
949 {move_iterator __tmp(*this); ++__i; return __tmp;}
950 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
951 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
952 {move_iterator __tmp(*this); --__i; return __tmp;}
953 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
954 {return move_iterator(__i + __n);}
955 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
956 {__i += __n; return *this;}
957 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
958 {return move_iterator(__i - __n);}
959 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
960 {__i -= __n; return *this;}
961 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +0000962 {
963 return static_cast<reference>(__i[__n]);
964 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965};
966
967template <class _Iter1, class _Iter2>
968inline _LIBCPP_INLINE_VISIBILITY
969bool
970operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
971{
972 return __x.base() == __y.base();
973}
974
975template <class _Iter1, class _Iter2>
976inline _LIBCPP_INLINE_VISIBILITY
977bool
978operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
979{
980 return __x.base() < __y.base();
981}
982
983template <class _Iter1, class _Iter2>
984inline _LIBCPP_INLINE_VISIBILITY
985bool
986operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
987{
988 return __x.base() != __y.base();
989}
990
991template <class _Iter1, class _Iter2>
992inline _LIBCPP_INLINE_VISIBILITY
993bool
994operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
995{
996 return __x.base() > __y.base();
997}
998
999template <class _Iter1, class _Iter2>
1000inline _LIBCPP_INLINE_VISIBILITY
1001bool
1002operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1003{
1004 return __x.base() >= __y.base();
1005}
1006
1007template <class _Iter1, class _Iter2>
1008inline _LIBCPP_INLINE_VISIBILITY
1009bool
1010operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1011{
1012 return __x.base() <= __y.base();
1013}
1014
1015template <class _Iter1, class _Iter2>
1016inline _LIBCPP_INLINE_VISIBILITY
1017typename move_iterator<_Iter1>::difference_type
1018operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1019{
1020 return __x.base() - __y.base();
1021}
1022
1023template <class _Iter>
1024inline _LIBCPP_INLINE_VISIBILITY
1025move_iterator<_Iter>
1026operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1027{
1028 return move_iterator<_Iter>(__x.base() + __n);
1029}
1030
1031template <class _Iter>
1032inline _LIBCPP_INLINE_VISIBILITY
1033move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:03 +00001034make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035{
1036 return move_iterator<_Iter>(__i);
1037}
1038
1039// __wrap_iter
1040
1041template <class _Iter> class __wrap_iter;
1042
1043template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001044_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001045bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001046operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001047
1048template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001049_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001051operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052
1053template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001054_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001055bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001056operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057
1058template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001059_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001061operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001062
1063template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001064_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001066operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067
1068template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001069_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001071operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072
1073template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001074_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001076operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077
1078template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001079_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001081operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082
Howard Hinnant33be35e2012-09-14 00:39:16 +00001083template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1084template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1085template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1086template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087
1088template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001089_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090typename enable_if
1091<
Howard Hinnant1468b662010-11-19 22:17:28 +00001092 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001093 _Tp*
1094>::type
1095__unwrap_iter(__wrap_iter<_Tp*>);
1096
1097template <class _Iter>
1098class __wrap_iter
1099{
1100public:
1101 typedef _Iter iterator_type;
1102 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1103 typedef typename iterator_traits<iterator_type>::value_type value_type;
1104 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1105 typedef typename iterator_traits<iterator_type>::pointer pointer;
1106 typedef typename iterator_traits<iterator_type>::reference reference;
1107private:
1108 iterator_type __i;
1109public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001110 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001111#if _LIBCPP_STD_VER > 11
1112 : __i{}
1113#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001114 {
1115#if _LIBCPP_DEBUG_LEVEL >= 2
1116 __get_db()->__insert_i(this);
1117#endif
1118 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001120 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001121 : __i(__u.base())
1122 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001123#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001124 __get_db()->__iterator_copy(this, &__u);
1125#endif
1126 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001127#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001128 _LIBCPP_INLINE_VISIBILITY
1129 __wrap_iter(const __wrap_iter& __x)
1130 : __i(__x.base())
1131 {
1132 __get_db()->__iterator_copy(this, &__x);
1133 }
1134 _LIBCPP_INLINE_VISIBILITY
1135 __wrap_iter& operator=(const __wrap_iter& __x)
1136 {
1137 if (this != &__x)
1138 {
1139 __get_db()->__iterator_copy(this, &__x);
1140 __i = __x.__i;
1141 }
1142 return *this;
1143 }
1144 _LIBCPP_INLINE_VISIBILITY
1145 ~__wrap_iter()
1146 {
1147 __get_db()->__erase_i(this);
1148 }
1149#endif
1150 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1151 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001152#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001153 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1154 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001155#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001156 return *__i;
1157 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001158 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1159 {
1160#if _LIBCPP_DEBUG_LEVEL >= 2
1161 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1162 "Attempted to dereference a non-dereferenceable iterator");
1163#endif
1164 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
1165 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001166 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1167 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001168#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001169 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1170 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001171#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001172 ++__i;
1173 return *this;
1174 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001175 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001176 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1177 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1178 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001179#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001180 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1181 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001182#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001183 --__i;
1184 return *this;
1185 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001186 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001187 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001188 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001189 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001190 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001191 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001192#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001193 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1194 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001195#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001196 __i += __n;
1197 return *this;
1198 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001199 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001200 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001201 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001202 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001203 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001204 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001205#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001206 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1207 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001208#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001209 return __i[__n];
1210 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211
Howard Hinnanta6119a82011-05-29 19:57:12 +00001212 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001213
1214private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001215#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001216 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1217 {
1218 __get_db()->__insert_ic(this, __p);
1219 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001220#else
1221 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001222#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223
1224 template <class _Up> friend class __wrap_iter;
1225 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1226 template <class _Tp, class _Alloc> friend class vector;
1227
1228 template <class _Iter1, class _Iter2>
1229 friend
1230 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001231 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001232
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233 template <class _Iter1, class _Iter2>
1234 friend
1235 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001236 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001237
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238 template <class _Iter1, class _Iter2>
1239 friend
1240 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001241 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001242
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243 template <class _Iter1, class _Iter2>
1244 friend
1245 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001246 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001247
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248 template <class _Iter1, class _Iter2>
1249 friend
1250 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001251 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001252
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001253 template <class _Iter1, class _Iter2>
1254 friend
1255 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001256 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001257
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258 template <class _Iter1, class _Iter2>
1259 friend
1260 typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001261 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001262
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263 template <class _Iter1>
1264 friend
1265 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001266 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267
Howard Hinnant99968442011-11-29 18:15:50 +00001268 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001270 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1272
1273 template <class _Tp>
1274 friend
1275 typename enable_if
1276 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001277 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278 _Tp*
1279 >::type
1280 __unwrap_iter(__wrap_iter<_Tp*>);
1281};
1282
1283template <class _Iter1, class _Iter2>
1284inline _LIBCPP_INLINE_VISIBILITY
1285bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001286operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287{
1288 return __x.base() == __y.base();
1289}
1290
1291template <class _Iter1, class _Iter2>
1292inline _LIBCPP_INLINE_VISIBILITY
1293bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001294operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001295{
Howard Hinnantabe26282011-09-16 17:29:17 +00001296#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001297 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001298 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001299#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001300 return __x.base() < __y.base();
1301}
1302
1303template <class _Iter1, class _Iter2>
1304inline _LIBCPP_INLINE_VISIBILITY
1305bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001306operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001308 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309}
1310
1311template <class _Iter1, class _Iter2>
1312inline _LIBCPP_INLINE_VISIBILITY
1313bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001314operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001315{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001316 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001317}
1318
1319template <class _Iter1, class _Iter2>
1320inline _LIBCPP_INLINE_VISIBILITY
1321bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001322operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001324 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001325}
1326
1327template <class _Iter1, class _Iter2>
1328inline _LIBCPP_INLINE_VISIBILITY
1329bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001330operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001332 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333}
1334
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001335template <class _Iter1>
1336inline _LIBCPP_INLINE_VISIBILITY
1337bool
1338operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1339{
1340 return !(__x == __y);
1341}
1342
1343template <class _Iter1>
1344inline _LIBCPP_INLINE_VISIBILITY
1345bool
1346operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1347{
1348 return __y < __x;
1349}
1350
1351template <class _Iter1>
1352inline _LIBCPP_INLINE_VISIBILITY
1353bool
1354operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1355{
1356 return !(__x < __y);
1357}
1358
1359template <class _Iter1>
1360inline _LIBCPP_INLINE_VISIBILITY
1361bool
1362operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1363{
1364 return !(__y < __x);
1365}
1366
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367template <class _Iter1, class _Iter2>
1368inline _LIBCPP_INLINE_VISIBILITY
1369typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001370operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001371{
Howard Hinnantabe26282011-09-16 17:29:17 +00001372#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001373 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001374 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001375#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376 return __x.base() - __y.base();
1377}
1378
1379template <class _Iter>
1380inline _LIBCPP_INLINE_VISIBILITY
1381__wrap_iter<_Iter>
1382operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001383 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001384{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001385 __x += __n;
1386 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387}
1388
Marshall Clow6daf5342013-12-02 03:24:33 +00001389template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001390inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001391_Tp*
1392begin(_Tp (&__array)[_Np])
1393{
1394 return __array;
1395}
1396
1397template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001398inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001399_Tp*
1400end(_Tp (&__array)[_Np])
1401{
1402 return __array + _Np;
1403}
1404
Marshall Clow1c398692013-12-11 19:32:32 +00001405#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1406
Howard Hinnant99968442011-11-29 18:15:50 +00001407template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001408inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409auto
Howard Hinnant99968442011-11-29 18:15:50 +00001410begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411{
1412 return __c.begin();
1413}
1414
Howard Hinnant99968442011-11-29 18:15:50 +00001415template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001416inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417auto
Howard Hinnant99968442011-11-29 18:15:50 +00001418begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419{
1420 return __c.begin();
1421}
1422
Howard Hinnant99968442011-11-29 18:15:50 +00001423template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001424inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425auto
Howard Hinnant99968442011-11-29 18:15:50 +00001426end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427{
1428 return __c.end();
1429}
1430
Howard Hinnant99968442011-11-29 18:15:50 +00001431template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001432inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001433auto
Howard Hinnant99968442011-11-29 18:15:50 +00001434end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001435{
1436 return __c.end();
1437}
1438
Marshall Clow09da3c02013-08-30 01:17:07 +00001439#if _LIBCPP_STD_VER > 11
1440
Marshall Clow6daf5342013-12-02 03:24:33 +00001441template <class _Tp, size_t _Np>
1442inline _LIBCPP_INLINE_VISIBILITY
1443reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1444{
1445 return reverse_iterator<_Tp*>(__array + _Np);
1446}
1447
1448template <class _Tp, size_t _Np>
1449inline _LIBCPP_INLINE_VISIBILITY
1450reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1451{
1452 return reverse_iterator<_Tp*>(__array);
1453}
1454
1455template <class _Ep>
1456inline _LIBCPP_INLINE_VISIBILITY
1457reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1458{
1459 return reverse_iterator<const _Ep*>(__il.end());
1460}
1461
1462template <class _Ep>
1463inline _LIBCPP_INLINE_VISIBILITY
1464reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1465{
1466 return reverse_iterator<const _Ep*>(__il.begin());
1467}
1468
Marshall Clow09da3c02013-08-30 01:17:07 +00001469template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001470inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001471auto cbegin(const _Cp& __c) -> decltype(begin(__c))
1472{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001473 return begin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001474}
1475
1476template <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 cend(const _Cp& __c) -> decltype(end(__c))
1479{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001480 return end(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001481}
1482
1483template <class _Cp>
1484inline _LIBCPP_INLINE_VISIBILITY
1485auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1486{
1487 return __c.rbegin();
1488}
1489
1490template <class _Cp>
1491inline _LIBCPP_INLINE_VISIBILITY
1492auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1493{
1494 return __c.rbegin();
1495}
1496
1497template <class _Cp>
1498inline _LIBCPP_INLINE_VISIBILITY
1499auto rend(_Cp& __c) -> decltype(__c.rend())
1500{
1501 return __c.rend();
1502}
1503
1504template <class _Cp>
1505inline _LIBCPP_INLINE_VISIBILITY
1506auto rend(const _Cp& __c) -> decltype(__c.rend())
1507{
1508 return __c.rend();
1509}
1510
1511template <class _Cp>
1512inline _LIBCPP_INLINE_VISIBILITY
1513auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
1514{
1515 return rbegin(__c);
1516}
1517
1518template <class _Cp>
1519inline _LIBCPP_INLINE_VISIBILITY
1520auto crend(const _Cp& __c) -> decltype(rend(__c))
1521{
1522 return rend(__c);
1523}
1524
1525#endif
1526
1527
Howard Hinnant726a76f2010-11-16 21:10:23 +00001528#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529
Howard Hinnant99968442011-11-29 18:15:50 +00001530template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001531inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001532typename _Cp::iterator
1533begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534{
1535 return __c.begin();
1536}
1537
Howard Hinnant99968442011-11-29 18:15:50 +00001538template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001539inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001540typename _Cp::const_iterator
1541begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542{
1543 return __c.begin();
1544}
1545
Howard Hinnant99968442011-11-29 18:15:50 +00001546template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001547inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001548typename _Cp::iterator
1549end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550{
1551 return __c.end();
1552}
1553
Howard Hinnant99968442011-11-29 18:15:50 +00001554template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001555inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001556typename _Cp::const_iterator
1557end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001558{
1559 return __c.end();
1560}
1561
Howard Hinnant726a76f2010-11-16 21:10:23 +00001562#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001563
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001564_LIBCPP_END_NAMESPACE_STD
1565
1566#endif // _LIBCPP_ITERATOR