blob: dda053da33bc3d4ab402e856b1ec35c96f42ef19 [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
312} // std
313
314*/
315
316#include <__config>
317#include <type_traits>
318#include <cstddef>
319#include <iosfwd>
Marshall Clowdece7fe2013-03-18 17:45:34 +0000320#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000321#include <Availability.h>
322#endif
323
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000324#ifdef _LIBCPP_DEBUG
325#include <cassert>
326#endif
327
Howard Hinnant08e17472011-10-17 20:05:10 +0000328#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000330#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331
332_LIBCPP_BEGIN_NAMESPACE_STD
333
Howard Hinnant83eade62013-03-06 23:30:19 +0000334struct _LIBCPP_TYPE_VIS input_iterator_tag {};
335struct _LIBCPP_TYPE_VIS output_iterator_tag {};
336struct _LIBCPP_TYPE_VIS forward_iterator_tag : public input_iterator_tag {};
337struct _LIBCPP_TYPE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
338struct _LIBCPP_TYPE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339
340template <class _Tp>
341struct __has_iterator_category
342{
343private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000344 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345 template <class _Up> static __two __test(...);
346 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
347public:
348 static const bool value = sizeof(__test<_Tp>(0)) == 1;
349};
350
351template <class _Iter, bool> struct ____iterator_traits {};
352
353template <class _Iter>
354struct ____iterator_traits<_Iter, true>
355{
356 typedef typename _Iter::difference_type difference_type;
357 typedef typename _Iter::value_type value_type;
358 typedef typename _Iter::pointer pointer;
359 typedef typename _Iter::reference reference;
360 typedef typename _Iter::iterator_category iterator_category;
361};
362
363template <class _Iter, bool> struct __iterator_traits {};
364
365template <class _Iter>
366struct __iterator_traits<_Iter, true>
367 : ____iterator_traits
368 <
369 _Iter,
370 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
371 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
372 >
373{};
374
375// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
376// exists. Else iterator_traits<Iterator> will be an empty class. This is a
377// conforming extension which allows some programs to compile and behave as
378// the client expects instead of failing at compile time.
379
380template <class _Iter>
Howard Hinnant83eade62013-03-06 23:30:19 +0000381struct _LIBCPP_TYPE_VIS iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
383
384template<class _Tp>
Howard Hinnant83eade62013-03-06 23:30:19 +0000385struct _LIBCPP_TYPE_VIS iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386{
387 typedef ptrdiff_t difference_type;
388 typedef typename remove_const<_Tp>::type value_type;
389 typedef _Tp* pointer;
390 typedef _Tp& reference;
391 typedef random_access_iterator_tag iterator_category;
392};
393
394template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
395struct __has_iterator_category_convertible_to
396 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
397{};
398
399template <class _Tp, class _Up>
400struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
401
402template <class _Tp>
403struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
404
405template <class _Tp>
406struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
407
408template <class _Tp>
409struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
410
411template <class _Tp>
412struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
413
414template<class _Category, class _Tp, class _Distance = ptrdiff_t,
415 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant83eade62013-03-06 23:30:19 +0000416struct _LIBCPP_TYPE_VIS iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417{
418 typedef _Tp value_type;
419 typedef _Distance difference_type;
420 typedef _Pointer pointer;
421 typedef _Reference reference;
422 typedef _Category iterator_category;
423};
424
425template <class _InputIter>
426inline _LIBCPP_INLINE_VISIBILITY
427void __advance(_InputIter& __i,
428 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
429{
430 for (; __n > 0; --__n)
431 ++__i;
432}
433
434template <class _BiDirIter>
435inline _LIBCPP_INLINE_VISIBILITY
436void __advance(_BiDirIter& __i,
437 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
438{
439 if (__n >= 0)
440 for (; __n > 0; --__n)
441 ++__i;
442 else
443 for (; __n < 0; ++__n)
444 --__i;
445}
446
447template <class _RandIter>
448inline _LIBCPP_INLINE_VISIBILITY
449void __advance(_RandIter& __i,
450 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
451{
452 __i += __n;
453}
454
455template <class _InputIter>
456inline _LIBCPP_INLINE_VISIBILITY
457void advance(_InputIter& __i,
458 typename iterator_traits<_InputIter>::difference_type __n)
459{
460 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
461}
462
463template <class _InputIter>
464inline _LIBCPP_INLINE_VISIBILITY
465typename iterator_traits<_InputIter>::difference_type
466__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
467{
468 typename iterator_traits<_InputIter>::difference_type __r(0);
469 for (; __first != __last; ++__first)
470 ++__r;
471 return __r;
472}
473
474template <class _RandIter>
475inline _LIBCPP_INLINE_VISIBILITY
476typename iterator_traits<_RandIter>::difference_type
477__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
478{
479 return __last - __first;
480}
481
482template <class _InputIter>
483inline _LIBCPP_INLINE_VISIBILITY
484typename iterator_traits<_InputIter>::difference_type
485distance(_InputIter __first, _InputIter __last)
486{
487 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
488}
489
490template <class _ForwardIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492_ForwardIter
493next(_ForwardIter __x,
494 typename iterator_traits<_ForwardIter>::difference_type __n = 1,
495 typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
496{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000497 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498 return __x;
499}
500
501template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000502inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503_BidiretionalIter
504prev(_BidiretionalIter __x,
505 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
506 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
507{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000508 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 return __x;
510}
511
512template <class _Iter>
Howard Hinnant83eade62013-03-06 23:30:19 +0000513class _LIBCPP_TYPE_VIS reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514 : public iterator<typename iterator_traits<_Iter>::iterator_category,
515 typename iterator_traits<_Iter>::value_type,
516 typename iterator_traits<_Iter>::difference_type,
517 typename iterator_traits<_Iter>::pointer,
518 typename iterator_traits<_Iter>::reference>
519{
520private:
521 mutable _Iter __t;
522protected:
523 _Iter current;
524public:
525 typedef _Iter iterator_type;
526 typedef typename iterator_traits<_Iter>::difference_type difference_type;
527 typedef typename iterator_traits<_Iter>::reference reference;
528 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000529
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
531 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
532 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
533 : __t(__u.base()), current(__u.base()) {}
534 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
535 _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;}
536 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &(operator*());}
537 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
538 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
539 {reverse_iterator __tmp(*this); --current; return __tmp;}
540 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
541 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
542 {reverse_iterator __tmp(*this); ++current; return __tmp;}
543 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
544 {return reverse_iterator(current - __n);}
545 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
546 {current -= __n; return *this;}
547 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
548 {return reverse_iterator(current + __n);}
549 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
550 {current += __n; return *this;}
551 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
552 {return current[-__n-1];}
553};
554
555template <class _Iter1, class _Iter2>
556inline _LIBCPP_INLINE_VISIBILITY
557bool
558operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
559{
560 return __x.base() == __y.base();
561}
562
563template <class _Iter1, class _Iter2>
564inline _LIBCPP_INLINE_VISIBILITY
565bool
566operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
567{
568 return __x.base() > __y.base();
569}
570
571template <class _Iter1, class _Iter2>
572inline _LIBCPP_INLINE_VISIBILITY
573bool
574operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
575{
576 return __x.base() != __y.base();
577}
578
579template <class _Iter1, class _Iter2>
580inline _LIBCPP_INLINE_VISIBILITY
581bool
582operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
583{
584 return __x.base() < __y.base();
585}
586
587template <class _Iter1, class _Iter2>
588inline _LIBCPP_INLINE_VISIBILITY
589bool
590operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
591{
592 return __x.base() <= __y.base();
593}
594
595template <class _Iter1, class _Iter2>
596inline _LIBCPP_INLINE_VISIBILITY
597bool
598operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
599{
600 return __x.base() >= __y.base();
601}
602
603template <class _Iter1, class _Iter2>
604inline _LIBCPP_INLINE_VISIBILITY
605typename reverse_iterator<_Iter1>::difference_type
606operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
607{
608 return __y.base() - __x.base();
609}
610
611template <class _Iter>
612inline _LIBCPP_INLINE_VISIBILITY
613reverse_iterator<_Iter>
614operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
615{
616 return reverse_iterator<_Iter>(__x.base() - __n);
617}
618
619template <class _Container>
Howard Hinnant83eade62013-03-06 23:30:19 +0000620class _LIBCPP_TYPE_VIS back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621 : public iterator<output_iterator_tag,
622 void,
623 void,
624 void,
625 back_insert_iterator<_Container>&>
626{
627protected:
628 _Container* container;
629public:
630 typedef _Container container_type;
631
632 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000633 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
634 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000635#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000636 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
637 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000638#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
640 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
641 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
642};
643
644template <class _Container>
645inline _LIBCPP_INLINE_VISIBILITY
646back_insert_iterator<_Container>
647back_inserter(_Container& __x)
648{
649 return back_insert_iterator<_Container>(__x);
650}
651
652template <class _Container>
Howard Hinnant83eade62013-03-06 23:30:19 +0000653class _LIBCPP_TYPE_VIS front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654 : public iterator<output_iterator_tag,
655 void,
656 void,
657 void,
658 front_insert_iterator<_Container>&>
659{
660protected:
661 _Container* container;
662public:
663 typedef _Container container_type;
664
665 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000666 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
667 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000668#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000669 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
670 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000671#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
673 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
674 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
675};
676
677template <class _Container>
678inline _LIBCPP_INLINE_VISIBILITY
679front_insert_iterator<_Container>
680front_inserter(_Container& __x)
681{
682 return front_insert_iterator<_Container>(__x);
683}
684
685template <class _Container>
Howard Hinnant83eade62013-03-06 23:30:19 +0000686class _LIBCPP_TYPE_VIS insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687 : public iterator<output_iterator_tag,
688 void,
689 void,
690 void,
691 insert_iterator<_Container>&>
692{
693protected:
694 _Container* container;
695 typename _Container::iterator iter;
696public:
697 typedef _Container container_type;
698
699 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
700 : container(&__x), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000701 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
702 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000703#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000704 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
705 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000706#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
708 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
709 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
710};
711
712template <class _Container>
713inline _LIBCPP_INLINE_VISIBILITY
714insert_iterator<_Container>
715inserter(_Container& __x, typename _Container::iterator __i)
716{
717 return insert_iterator<_Container>(__x, __i);
718}
719
720template <class _Tp, class _CharT = char,
721 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant83eade62013-03-06 23:30:19 +0000722class _LIBCPP_TYPE_VIS istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
724{
725public:
726 typedef _CharT char_type;
727 typedef _Traits traits_type;
728 typedef basic_istream<_CharT,_Traits> istream_type;
729private:
730 istream_type* __in_stream_;
731 _Tp __value_;
732public:
733 _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {}
734 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
735 {
736 if (!(*__in_stream_ >> __value_))
737 __in_stream_ = 0;
738 }
739
740 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
741 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
742 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
743 {
744 if (!(*__in_stream_ >> __value_))
745 __in_stream_ = 0;
746 return *this;
747 }
748 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
749 {istream_iterator __t(*this); ++(*this); return __t;}
750
751 friend _LIBCPP_INLINE_VISIBILITY
752 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
753 {return __x.__in_stream_ == __y.__in_stream_;}
754
755 friend _LIBCPP_INLINE_VISIBILITY
756 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
757 {return !(__x == __y);}
758};
759
760template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant83eade62013-03-06 23:30:19 +0000761class _LIBCPP_TYPE_VIS ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762 : public iterator<output_iterator_tag, void, void, void, void>
763{
764public:
765 typedef _CharT char_type;
766 typedef _Traits traits_type;
767 typedef basic_ostream<_CharT,_Traits> ostream_type;
768private:
769 ostream_type* __out_stream_;
770 const char_type* __delim_;
771public:
772 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
773 : __out_stream_(&__s), __delim_(0) {}
774 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
775 : __out_stream_(&__s), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000776 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000778 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 if (__delim_)
780 *__out_stream_ << __delim_;
781 return *this;
782 }
783
784 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
785 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
786 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
787};
788
789template<class _CharT, class _Traits>
Howard Hinnant83eade62013-03-06 23:30:19 +0000790class _LIBCPP_TYPE_VIS istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791 : public iterator<input_iterator_tag, _CharT,
792 typename _Traits::off_type, _CharT*,
793 _CharT>
794{
795public:
796 typedef _CharT char_type;
797 typedef _Traits traits_type;
798 typedef typename _Traits::int_type int_type;
799 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
800 typedef basic_istream<_CharT,_Traits> istream_type;
801private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000802 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803
804 class __proxy
805 {
806 char_type __keep_;
807 streambuf_type* __sbuf_;
808 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
809 : __keep_(__c), __sbuf_(__s) {}
810 friend class istreambuf_iterator;
811 public:
812 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
813 };
814
Howard Hinnant82894812010-09-22 16:48:34 +0000815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000816 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817 {
818 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
819 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000820 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821 }
822public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000823 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000824 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000825 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000826 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000827 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000828 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829 : __sbuf_(__p.__sbuf_) {}
830
Howard Hinnantec3773c2011-12-01 20:21:04 +0000831 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
832 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
834 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
835 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000836 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837 return *this;
838 }
839 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
840 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000841 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 }
843
844 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000845 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000846};
847
848template <class _CharT, class _Traits>
849inline _LIBCPP_INLINE_VISIBILITY
850bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
851 const istreambuf_iterator<_CharT,_Traits>& __b)
852 {return __a.equal(__b);}
853
854template <class _CharT, class _Traits>
855inline _LIBCPP_INLINE_VISIBILITY
856bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
857 const istreambuf_iterator<_CharT,_Traits>& __b)
858 {return !__a.equal(__b);}
859
860template <class _CharT, class _Traits>
Howard Hinnant83eade62013-03-06 23:30:19 +0000861class _LIBCPP_TYPE_VIS ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 : public iterator<output_iterator_tag, void, void, void, void>
863{
864public:
865 typedef _CharT char_type;
866 typedef _Traits traits_type;
867 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
868 typedef basic_ostream<_CharT,_Traits> ostream_type;
869private:
870 streambuf_type* __sbuf_;
871public:
Howard Hinnantd06a6402012-07-20 19:36:34 +0000872 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000874 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875 : __sbuf_(__s) {}
876 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
877 {
878 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
879 __sbuf_ = 0;
880 return *this;
881 }
882 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
883 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
884 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000885 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +0000886
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000887#if !defined(__APPLE__) || \
888 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
889 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
890
Howard Hinnanta585de62012-09-19 19:14:15 +0000891 template <class _Ch, class _Tr>
892 friend
893 _LIBCPP_HIDDEN
894 ostreambuf_iterator<_Ch, _Tr>
895 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
896 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
897 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000898#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899};
900
901template <class _Iter>
Howard Hinnant83eade62013-03-06 23:30:19 +0000902class _LIBCPP_TYPE_VIS move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903{
904private:
905 _Iter __i;
906public:
907 typedef _Iter iterator_type;
908 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
909 typedef typename iterator_traits<iterator_type>::value_type value_type;
910 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
911 typedef typename iterator_traits<iterator_type>::pointer pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000912#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913 typedef value_type&& reference;
914#else
915 typedef typename iterator_traits<iterator_type>::reference reference;
916#endif
Howard Hinnant324bb032010-08-22 00:02:43 +0000917
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
919 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
920 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
921 : __i(__u.base()) {}
922 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +0000923 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
924 return static_cast<reference>(*__i);
925 }
926 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
927 typename iterator_traits<iterator_type>::reference __ref = *__i;
928 return &__ref;
929 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
931 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
932 {move_iterator __tmp(*this); ++__i; return __tmp;}
933 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
934 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
935 {move_iterator __tmp(*this); --__i; return __tmp;}
936 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
937 {return move_iterator(__i + __n);}
938 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
939 {__i += __n; return *this;}
940 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
941 {return move_iterator(__i - __n);}
942 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
943 {__i -= __n; return *this;}
944 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +0000945 {
946 return static_cast<reference>(__i[__n]);
947 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000948};
949
950template <class _Iter1, class _Iter2>
951inline _LIBCPP_INLINE_VISIBILITY
952bool
953operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
954{
955 return __x.base() == __y.base();
956}
957
958template <class _Iter1, class _Iter2>
959inline _LIBCPP_INLINE_VISIBILITY
960bool
961operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
962{
963 return __x.base() < __y.base();
964}
965
966template <class _Iter1, class _Iter2>
967inline _LIBCPP_INLINE_VISIBILITY
968bool
969operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
970{
971 return __x.base() != __y.base();
972}
973
974template <class _Iter1, class _Iter2>
975inline _LIBCPP_INLINE_VISIBILITY
976bool
977operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
978{
979 return __x.base() > __y.base();
980}
981
982template <class _Iter1, class _Iter2>
983inline _LIBCPP_INLINE_VISIBILITY
984bool
985operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
986{
987 return __x.base() >= __y.base();
988}
989
990template <class _Iter1, class _Iter2>
991inline _LIBCPP_INLINE_VISIBILITY
992bool
993operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
994{
995 return __x.base() <= __y.base();
996}
997
998template <class _Iter1, class _Iter2>
999inline _LIBCPP_INLINE_VISIBILITY
1000typename move_iterator<_Iter1>::difference_type
1001operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1002{
1003 return __x.base() - __y.base();
1004}
1005
1006template <class _Iter>
1007inline _LIBCPP_INLINE_VISIBILITY
1008move_iterator<_Iter>
1009operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1010{
1011 return move_iterator<_Iter>(__x.base() + __n);
1012}
1013
1014template <class _Iter>
1015inline _LIBCPP_INLINE_VISIBILITY
1016move_iterator<_Iter>
1017make_move_iterator(const _Iter& __i)
1018{
1019 return move_iterator<_Iter>(__i);
1020}
1021
1022// __wrap_iter
1023
1024template <class _Iter> class __wrap_iter;
1025
1026template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001027_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001028bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001029operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001030
1031template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001032_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001033bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001034operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035
1036template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001037_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001039operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001040
1041template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001042_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001044operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001045
1046template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001047_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001048bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001049operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050
1051template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001052_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001054operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001055
1056template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001057_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001059operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060
1061template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001062_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001064operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065
Howard Hinnant33be35e2012-09-14 00:39:16 +00001066template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1067template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1068template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1069template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070
1071template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001072_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073typename enable_if
1074<
Howard Hinnant1468b662010-11-19 22:17:28 +00001075 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076 _Tp*
1077>::type
1078__unwrap_iter(__wrap_iter<_Tp*>);
1079
1080template <class _Iter>
1081class __wrap_iter
1082{
1083public:
1084 typedef _Iter iterator_type;
1085 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1086 typedef typename iterator_traits<iterator_type>::value_type value_type;
1087 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1088 typedef typename iterator_traits<iterator_type>::pointer pointer;
1089 typedef typename iterator_traits<iterator_type>::reference reference;
1090private:
1091 iterator_type __i;
1092public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001093 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
1094 {
1095#if _LIBCPP_DEBUG_LEVEL >= 2
1096 __get_db()->__insert_i(this);
1097#endif
1098 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001100 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001101 : __i(__u.base())
1102 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001103#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001104 __get_db()->__iterator_copy(this, &__u);
1105#endif
1106 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001107#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001108 _LIBCPP_INLINE_VISIBILITY
1109 __wrap_iter(const __wrap_iter& __x)
1110 : __i(__x.base())
1111 {
1112 __get_db()->__iterator_copy(this, &__x);
1113 }
1114 _LIBCPP_INLINE_VISIBILITY
1115 __wrap_iter& operator=(const __wrap_iter& __x)
1116 {
1117 if (this != &__x)
1118 {
1119 __get_db()->__iterator_copy(this, &__x);
1120 __i = __x.__i;
1121 }
1122 return *this;
1123 }
1124 _LIBCPP_INLINE_VISIBILITY
1125 ~__wrap_iter()
1126 {
1127 __get_db()->__erase_i(this);
1128 }
1129#endif
1130 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1131 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001132#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001133 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1134 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001135#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001136 return *__i;
1137 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001138 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1139 {
1140#if _LIBCPP_DEBUG_LEVEL >= 2
1141 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1142 "Attempted to dereference a non-dereferenceable iterator");
1143#endif
1144 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
1145 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001146 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1147 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001148#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001149 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1150 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001151#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001152 ++__i;
1153 return *this;
1154 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001155 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001156 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1157 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _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()->__decrementable(this),
1161 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001162#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001163 --__i;
1164 return *this;
1165 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001166 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001167 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001168 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001169 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001170 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001171 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001172#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001173 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1174 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001175#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001176 __i += __n;
1177 return *this;
1178 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001179 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001180 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001181 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001182 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001183 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001184 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001185#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001186 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1187 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001188#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001189 return __i[__n];
1190 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191
Howard Hinnanta6119a82011-05-29 19:57:12 +00001192 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193
1194private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001195 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnantabe26282011-09-16 17:29:17 +00001196#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001197 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1198 {
1199 __get_db()->__insert_ic(this, __p);
1200 }
1201#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001202
1203 template <class _Up> friend class __wrap_iter;
1204 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1205 template <class _Tp, class _Alloc> friend class vector;
1206
1207 template <class _Iter1, class _Iter2>
1208 friend
1209 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001210 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001211
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001212 template <class _Iter1, class _Iter2>
1213 friend
1214 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001215 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001216
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217 template <class _Iter1, class _Iter2>
1218 friend
1219 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001220 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001221
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222 template <class _Iter1, class _Iter2>
1223 friend
1224 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001225 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001226
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227 template <class _Iter1, class _Iter2>
1228 friend
1229 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001230 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001231
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232 template <class _Iter1, class _Iter2>
1233 friend
1234 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001235 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001236
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001237 template <class _Iter1, class _Iter2>
1238 friend
1239 typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001240 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001241
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242 template <class _Iter1>
1243 friend
1244 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001245 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246
Howard Hinnant99968442011-11-29 18:15:50 +00001247 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001249 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1251
1252 template <class _Tp>
1253 friend
1254 typename enable_if
1255 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001256 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257 _Tp*
1258 >::type
1259 __unwrap_iter(__wrap_iter<_Tp*>);
1260};
1261
1262template <class _Iter1, class _Iter2>
1263inline _LIBCPP_INLINE_VISIBILITY
1264bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001265operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266{
Howard Hinnantabe26282011-09-16 17:29:17 +00001267#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001268 _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
1269 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001270#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271 return __x.base() == __y.base();
1272}
1273
1274template <class _Iter1, class _Iter2>
1275inline _LIBCPP_INLINE_VISIBILITY
1276bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001277operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278{
Howard Hinnantabe26282011-09-16 17:29:17 +00001279#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001280 _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
1281 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001282#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283 return __x.base() < __y.base();
1284}
1285
1286template <class _Iter1, class _Iter2>
1287inline _LIBCPP_INLINE_VISIBILITY
1288bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001289operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001290{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001291 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292}
1293
1294template <class _Iter1, class _Iter2>
1295inline _LIBCPP_INLINE_VISIBILITY
1296bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001297operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001299 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001300}
1301
1302template <class _Iter1, class _Iter2>
1303inline _LIBCPP_INLINE_VISIBILITY
1304bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001305operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001307 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001308}
1309
1310template <class _Iter1, class _Iter2>
1311inline _LIBCPP_INLINE_VISIBILITY
1312bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001313operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001315 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316}
1317
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001318template <class _Iter1>
1319inline _LIBCPP_INLINE_VISIBILITY
1320bool
1321operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1322{
1323 return !(__x == __y);
1324}
1325
1326template <class _Iter1>
1327inline _LIBCPP_INLINE_VISIBILITY
1328bool
1329operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1330{
1331 return __y < __x;
1332}
1333
1334template <class _Iter1>
1335inline _LIBCPP_INLINE_VISIBILITY
1336bool
1337operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1338{
1339 return !(__x < __y);
1340}
1341
1342template <class _Iter1>
1343inline _LIBCPP_INLINE_VISIBILITY
1344bool
1345operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1346{
1347 return !(__y < __x);
1348}
1349
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001350template <class _Iter1, class _Iter2>
1351inline _LIBCPP_INLINE_VISIBILITY
1352typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001353operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354{
Howard Hinnantabe26282011-09-16 17:29:17 +00001355#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001356 _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
1357 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001358#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001359 return __x.base() - __y.base();
1360}
1361
1362template <class _Iter>
1363inline _LIBCPP_INLINE_VISIBILITY
1364__wrap_iter<_Iter>
1365operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001366 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001368 __x += __n;
1369 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370}
1371
1372#ifdef _LIBCPP_DEBUG
1373
1374// __debug_iter
1375
1376template <class _Container, class _Iter> class __debug_iter;
1377
1378template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001379_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380bool
1381operator==(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1382
1383template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001384_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385bool
1386operator<(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1387
1388template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001389_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390bool
1391operator!=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1392
1393template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001394_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001395bool
1396operator>(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1397
1398template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001399_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400bool
1401operator>=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1402
1403template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001404_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001405bool
1406operator<=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1407
1408template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001409_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410typename __debug_iter<_Container, _Iter1>::difference_type
1411operator-(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1412
1413template <class _Container, class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001414_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415__debug_iter<_Container, _Iter>
1416operator+(typename __debug_iter<_Container, _Iter>::difference_type, const __debug_iter<_Container, _Iter>&);
1417
1418template <class _Container, class _Iter>
1419class __debug_iter
1420{
1421public:
1422 typedef _Iter iterator_type;
1423 typedef _Container __container_type;
1424 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1425 typedef typename iterator_traits<iterator_type>::value_type value_type;
1426 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1427 typedef typename iterator_traits<iterator_type>::pointer pointer;
1428 typedef typename iterator_traits<iterator_type>::reference reference;
1429private:
1430 iterator_type __i;
1431 __debug_iter* __next;
1432 __container_type* __cont;
Howard Hinnant324bb032010-08-22 00:02:43 +00001433
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434public:
1435 _LIBCPP_INLINE_VISIBILITY __debug_iter() : __next(0), __cont(0) {}
1436 _LIBCPP_INLINE_VISIBILITY __debug_iter(const __debug_iter& __x)
1437 : __i(__x.base()), __next(0), __cont(0) {__set_owner(__x.__cont);}
1438 __debug_iter& operator=(const __debug_iter& __x);
1439 template <class _Up> _LIBCPP_INLINE_VISIBILITY __debug_iter(const __debug_iter<_Container, _Up>& __u,
1440 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0)
1441 : __i(__u.base()), __next(0), __cont(0) {__set_owner(__u.__cont);}
1442 _LIBCPP_INLINE_VISIBILITY ~__debug_iter() {__remove_owner();}
1443 _LIBCPP_INLINE_VISIBILITY reference operator*() const {assert(__is_deref()); return *__i;}
1444 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &(operator*());}
1445 _LIBCPP_INLINE_VISIBILITY __debug_iter& operator++() {assert(__can_increment()); ++__i; return *this;}
1446 _LIBCPP_INLINE_VISIBILITY __debug_iter operator++(int)
1447 {__debug_iter __tmp(*this); operator++(); return __tmp;}
1448 _LIBCPP_INLINE_VISIBILITY __debug_iter& operator--() {assert(__can_decrement()); --__i; return *this;}
1449 _LIBCPP_INLINE_VISIBILITY __debug_iter operator--(int)
1450 {__debug_iter __tmp(*this); operator--(); return __tmp;}
1451 _LIBCPP_INLINE_VISIBILITY __debug_iter operator+ (difference_type __n) const
1452 {__debug_iter __t(*this); __t += __n; return __t;}
1453 __debug_iter& operator+=(difference_type __n);
1454 _LIBCPP_INLINE_VISIBILITY __debug_iter operator- (difference_type __n) const
1455 {__debug_iter __t(*this); __t -= __n; return __t;}
1456 _LIBCPP_INLINE_VISIBILITY __debug_iter& operator-=(difference_type __n)
1457 {*this += -__n; return *this;}
1458 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
1459 {return *(*this + __n);}
1460
1461private:
1462 _LIBCPP_INLINE_VISIBILITY __debug_iter(const __container_type* __c, iterator_type __x)
1463 : __i(__x), __next(0), __cont(0) {__set_owner(__c);}
1464 _LIBCPP_INLINE_VISIBILITY iterator_type base() const {return __i;}
1465
1466 void __set_owner(const __container_type* __c);
1467 void __remove_owner();
1468 static void __remove_all(__container_type* __c);
1469 static void swap(__container_type* __x, __container_type* __y);
Howard Hinnant324bb032010-08-22 00:02:43 +00001470
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471 _LIBCPP_INLINE_VISIBILITY bool __is_deref() const
1472 {return __is_deref(__is_random_access_iterator<iterator_type>());}
1473 bool __is_deref(false_type) const;
1474 bool __is_deref(true_type) const;
1475 _LIBCPP_INLINE_VISIBILITY bool __can_decrement() const
1476 {return __can_decrement(integral_constant<int, is_pointer<iterator_type>::value ? 2:
1477 __is_random_access_iterator<iterator_type>::value ? 1 : 0>());}
1478 bool __can_decrement(integral_constant<int, 0>) const;
1479 bool __can_decrement(integral_constant<int, 1>) const;
1480 bool __can_decrement(integral_constant<int, 2>) const;
1481 _LIBCPP_INLINE_VISIBILITY bool __can_increment() const
1482 {return __can_increment(integral_constant<int, is_pointer<iterator_type>::value ? 2:
1483 __is_random_access_iterator<iterator_type>::value ? 1 : 0>());}
1484 bool __can_increment(integral_constant<int, 0>) const;
1485 bool __can_increment(integral_constant<int, 1>) const;
1486 bool __can_increment(integral_constant<int, 2>) const;
1487
1488 _LIBCPP_INLINE_VISIBILITY bool __can_add(difference_type __n) const
1489 {return __can_add(__n, is_pointer<iterator_type>());}
1490 bool __can_add(difference_type __n, false_type) const;
1491 bool __can_add(difference_type __n, true_type) const;
1492
1493 template <class _Cp, class _Up> friend class __debug_iter;
1494 friend class _Container::__self;
1495
1496 template <class _Cp, class _Iter1, class _Iter2>
1497 friend
1498 bool
1499 operator==(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001500
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501 template <class _Cp, class _Iter1, class _Iter2>
1502 friend
1503 bool
1504 operator<(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001505
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506 template <class _Cp, class _Iter1, class _Iter2>
1507 friend
1508 bool
1509 operator!=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001510
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511 template <class _Cp, class _Iter1, class _Iter2>
1512 friend
1513 bool
1514 operator>(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001515
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001516 template <class _Cp, class _Iter1, class _Iter2>
1517 friend
1518 bool
1519 operator>=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001520
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001521 template <class _Cp, class _Iter1, class _Iter2>
1522 friend
1523 bool
1524 operator<=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001525
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526 template <class _Cp, class _Iter1, class _Iter2>
1527 friend
1528 typename __debug_iter<_Cp, _Iter1>::difference_type
1529 operator-(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001530
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531 template <class _Cp, class _Iter1>
1532 friend
1533 __debug_iter<_Cp, _Iter1>
1534 operator+(typename __debug_iter<_Cp, _Iter1>::difference_type, const __debug_iter<_Cp, _Iter1>&);
1535};
1536
1537template <class _Container, class _Iter>
1538__debug_iter<_Container, _Iter>&
1539__debug_iter<_Container, _Iter>::operator=(const __debug_iter& __x)
1540{
1541 if (this != &__x)
1542 {
1543 __remove_owner();
1544 __i = __x.__i;
1545 __set_owner(__x.__cont);
1546 }
1547 return *this;
1548}
Howard Hinnant324bb032010-08-22 00:02:43 +00001549
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550template <class _Container, class _Iter>
1551void
1552__debug_iter<_Container, _Iter>::__set_owner(const __container_type* __c)
1553{
1554 __cont = const_cast<__container_type*>(__c);
1555 __debug_iter*& __head = __cont->__get_iterator_list(this);
1556 __next = __head;
1557 __head = this;
1558}
1559
1560template <class _Container, class _Iter>
1561void
1562__debug_iter<_Container, _Iter>::__remove_owner()
1563{
1564 if (__cont)
1565 {
1566 __debug_iter*& __head = __cont->__get_iterator_list(this);
1567 if (__head == this)
1568 __head = __next;
1569 else
1570 {
1571 __debug_iter* __prev = __head;
1572 for (__debug_iter* __p = __head->__next; __p != this; __p = __p->__next)
1573 __prev = __p;
1574 __prev->__next = __next;
1575 }
1576 __cont = 0;
1577 }
1578}
1579
1580template <class _Container, class _Iter>
1581void
1582__debug_iter<_Container, _Iter>::__remove_all(__container_type* __c)
1583{
1584 __debug_iter*& __head = __c->__get_iterator_list((__debug_iter*)0);
1585 __debug_iter* __p = __head;
1586 __head = 0;
1587 while (__p)
1588 {
1589 __p->__cont = 0;
1590 __debug_iter* __n = __p->__next;
1591 __p->__next = 0;
1592 __p = __n;
1593 }
1594}
1595
1596template <class _Container, class _Iter>
1597void
1598__debug_iter<_Container, _Iter>::swap(__container_type* __x, __container_type* __y)
1599{
1600 __debug_iter*& __head_x = __x->__get_iterator_list((__debug_iter*)0);
1601 __debug_iter*& __head_y = __y->__get_iterator_list((__debug_iter*)0);
1602 __debug_iter* __p = __head_x;
1603 __head_x = __head_y;
1604 __head_y = __p;
1605 for (__p = __head_x; __p; __p = __p->__next)
1606 __p->__cont = __x;
1607 for (__p = __head_y; __p; __p = __p->__next)
1608 __p->__cont = __y;
1609}
1610
1611template <class _Container, class _Iter>
1612bool
1613__debug_iter<_Container, _Iter>::__is_deref(false_type) const
1614{
1615 if (__cont == 0)
1616 return false;
1617 return __i != __cont->end().base();
1618}
1619
1620template <class _Container, class _Iter>
1621bool
1622__debug_iter<_Container, _Iter>::__is_deref(true_type) const
1623{
1624 if (__cont == 0)
1625 return false;
1626 return __i < __cont->end().base();
1627}
1628
1629template <class _Container, class _Iter>
1630bool
1631__debug_iter<_Container, _Iter>::__can_decrement(integral_constant<int, 0>) const
1632{
1633 if (__cont == 0)
1634 return false;
1635 return __i != __cont->begin().base();
1636}
1637
1638template <class _Container, class _Iter>
1639bool
1640__debug_iter<_Container, _Iter>::__can_decrement(integral_constant<int, 1>) const
1641{
1642 if (__cont == 0)
1643 return false;
1644 iterator_type __b = __cont->begin().base();
1645 return __b < __i && __i <= __b + __cont->size();
1646}
1647
1648template <class _Container, class _Iter>
1649bool
1650__debug_iter<_Container, _Iter>::__can_decrement(integral_constant<int, 2>) const
1651{
1652 if (__cont == 0)
1653 return false;
1654 iterator_type __b = __cont->begin().base();
1655 return __b < __i && __i <= __b + __cont->size();
1656}
1657
1658template <class _Container, class _Iter>
1659bool
1660__debug_iter<_Container, _Iter>::__can_increment(integral_constant<int, 0>) const
1661{
1662 if (__cont == 0)
1663 return false;
1664 return __i != __cont->end().base();
1665}
1666
1667template <class _Container, class _Iter>
1668bool
1669__debug_iter<_Container, _Iter>::__can_increment(integral_constant<int, 1>) const
1670{
1671 if (__cont == 0)
1672 return false;
1673 iterator_type __b = __cont->begin().base();
1674 return __b <= __i && __i < __b + __cont->size();
1675}
1676
1677template <class _Container, class _Iter>
1678bool
1679__debug_iter<_Container, _Iter>::__can_increment(integral_constant<int, 2>) const
1680{
1681 if (__cont == 0)
1682 return false;
1683 iterator_type __b = __cont->begin().base();
1684 return __b <= __i && __i < __b + __cont->size();
1685}
1686
1687template <class _Container, class _Iter>
1688bool
1689__debug_iter<_Container, _Iter>::__can_add(difference_type __n, false_type) const
1690{
1691 if (__cont == 0)
1692 return false;
1693 iterator_type __b = __cont->begin().base();
1694 iterator_type __j = __i + __n;
1695 return __b <= __j && __j <= __b + __cont->size();
1696}
1697
1698template <class _Container, class _Iter>
1699bool
1700__debug_iter<_Container, _Iter>::__can_add(difference_type __n, true_type) const
1701{
1702 if (__cont == 0)
1703 return false;
1704 iterator_type __b = __cont->begin().base();
1705 iterator_type __j = __i + __n;
1706 return __b <= __j && __j <= __b + __cont->size();
1707}
1708
1709template <class _Container, class _Iter>
1710__debug_iter<_Container, _Iter>&
1711__debug_iter<_Container, _Iter>::operator+=(difference_type __n)
1712{
1713 assert(__can_add(__n));
1714 __i += __n;
1715 return *this;
1716}
1717
1718template <class _Container, class _Iter1, class _Iter2>
1719inline _LIBCPP_INLINE_VISIBILITY
1720bool
1721operator==(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1722{
1723 assert(__x.__cont && __x.__cont == __y.__cont);
1724 return __x.base() == __y.base();
1725}
1726
1727template <class _Container, class _Iter1, class _Iter2>
1728inline _LIBCPP_INLINE_VISIBILITY
1729bool
1730operator!=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1731{
1732 return !(__x == __y);
1733}
1734
1735template <class _Container, class _Iter1, class _Iter2>
1736inline _LIBCPP_INLINE_VISIBILITY
1737bool
1738operator<(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1739{
1740 assert(__x.__cont && __x.__cont == __y.__cont);
1741 return __x.base() < __y.base();
1742}
1743
1744template <class _Container, class _Iter1, class _Iter2>
1745inline _LIBCPP_INLINE_VISIBILITY
1746bool
1747operator>(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1748{
1749 return __y < __x;
1750}
1751
1752template <class _Container, class _Iter1, class _Iter2>
1753inline _LIBCPP_INLINE_VISIBILITY
1754bool
1755operator>=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1756{
1757 return !(__x < __y);
1758}
1759
1760template <class _Container, class _Iter1, class _Iter2>
1761inline _LIBCPP_INLINE_VISIBILITY
1762bool
1763operator<=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1764{
1765 return !(__y < __x);
1766}
1767
1768template <class _Container, class _Iter1, class _Iter2>
1769inline _LIBCPP_INLINE_VISIBILITY
1770typename __debug_iter<_Container, _Iter1>::difference_type
1771operator-(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1772{
1773 assert(__x.__cont && __x.__cont == __y.__cont);
1774 return __x.base() - __y.base();
1775}
1776
1777template <class _Container, class _Iter>
1778inline _LIBCPP_INLINE_VISIBILITY
1779__debug_iter<_Container, _Iter>
1780operator+(typename __debug_iter<_Container, _Iter>::difference_type __n,
1781 const __debug_iter<_Container, _Iter>& __x)
1782{
1783 return __x + __n;
1784}
1785
1786#endif // _LIBCPP_DEBUG
1787
Howard Hinnant726a76f2010-11-16 21:10:23 +00001788#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789
Howard Hinnant99968442011-11-29 18:15:50 +00001790template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001791inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001792auto
Howard Hinnant99968442011-11-29 18:15:50 +00001793begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001794{
1795 return __c.begin();
1796}
1797
Howard Hinnant99968442011-11-29 18:15:50 +00001798template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001799inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800auto
Howard Hinnant99968442011-11-29 18:15:50 +00001801begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001802{
1803 return __c.begin();
1804}
1805
Howard Hinnant99968442011-11-29 18:15:50 +00001806template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001807inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808auto
Howard Hinnant99968442011-11-29 18:15:50 +00001809end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810{
1811 return __c.end();
1812}
1813
Howard Hinnant99968442011-11-29 18:15:50 +00001814template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001815inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816auto
Howard Hinnant99968442011-11-29 18:15:50 +00001817end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818{
1819 return __c.end();
1820}
1821
Howard Hinnant726a76f2010-11-16 21:10:23 +00001822#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823
Howard Hinnant99968442011-11-29 18:15:50 +00001824template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001825inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001826typename _Cp::iterator
1827begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828{
1829 return __c.begin();
1830}
1831
Howard Hinnant99968442011-11-29 18:15:50 +00001832template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001834typename _Cp::const_iterator
1835begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001836{
1837 return __c.begin();
1838}
1839
Howard Hinnant99968442011-11-29 18:15:50 +00001840template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001841inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001842typename _Cp::iterator
1843end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001844{
1845 return __c.end();
1846}
1847
Howard Hinnant99968442011-11-29 18:15:50 +00001848template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001849inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001850typename _Cp::const_iterator
1851end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852{
1853 return __c.end();
1854}
1855
Howard Hinnant726a76f2010-11-16 21:10:23 +00001856#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857
Howard Hinnant99968442011-11-29 18:15:50 +00001858template <class _Tp, size_t _Np>
Howard Hinnant82894812010-09-22 16:48:34 +00001859inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001860_Tp*
1861begin(_Tp (&__array)[_Np])
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001862{
1863 return __array;
1864}
1865
Howard Hinnant99968442011-11-29 18:15:50 +00001866template <class _Tp, size_t _Np>
Howard Hinnant82894812010-09-22 16:48:34 +00001867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001868_Tp*
1869end(_Tp (&__array)[_Np])
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001870{
Howard Hinnant99968442011-11-29 18:15:50 +00001871 return __array + _Np;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872}
1873
1874_LIBCPP_END_NAMESPACE_STD
1875
1876#endif // _LIBCPP_ITERATOR