blob: 8e92e6fef1e51235dbb8e8ff10a872fe2d68d79f [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 Hinnant8b00e6c2013-08-02 00:26:35 +0000324#ifdef _LIBCPP_DEBUG2
325# include <__debug>
326#else
327# define _LIBCPP_ASSERT(x, m) ((void)0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000328#endif
329
Howard Hinnant08e17472011-10-17 20:05:10 +0000330#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000332#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333
334_LIBCPP_BEGIN_NAMESPACE_STD
335
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000336struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
337struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
338struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
339struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
340struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
342template <class _Tp>
343struct __has_iterator_category
344{
345private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000346 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347 template <class _Up> static __two __test(...);
348 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
349public:
350 static const bool value = sizeof(__test<_Tp>(0)) == 1;
351};
352
353template <class _Iter, bool> struct ____iterator_traits {};
354
355template <class _Iter>
356struct ____iterator_traits<_Iter, true>
357{
358 typedef typename _Iter::difference_type difference_type;
359 typedef typename _Iter::value_type value_type;
360 typedef typename _Iter::pointer pointer;
361 typedef typename _Iter::reference reference;
362 typedef typename _Iter::iterator_category iterator_category;
363};
364
365template <class _Iter, bool> struct __iterator_traits {};
366
367template <class _Iter>
368struct __iterator_traits<_Iter, true>
369 : ____iterator_traits
370 <
371 _Iter,
372 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
373 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
374 >
375{};
376
377// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
378// exists. Else iterator_traits<Iterator> will be an empty class. This is a
379// conforming extension which allows some programs to compile and behave as
380// the client expects instead of failing at compile time.
381
382template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000383struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
385
386template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000387struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388{
389 typedef ptrdiff_t difference_type;
390 typedef typename remove_const<_Tp>::type value_type;
391 typedef _Tp* pointer;
392 typedef _Tp& reference;
393 typedef random_access_iterator_tag iterator_category;
394};
395
396template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
397struct __has_iterator_category_convertible_to
398 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
399{};
400
401template <class _Tp, class _Up>
402struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
403
404template <class _Tp>
405struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
406
407template <class _Tp>
408struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
409
410template <class _Tp>
411struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
412
413template <class _Tp>
414struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
415
416template<class _Category, class _Tp, class _Distance = ptrdiff_t,
417 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000418struct _LIBCPP_TYPE_VIS_ONLY iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419{
420 typedef _Tp value_type;
421 typedef _Distance difference_type;
422 typedef _Pointer pointer;
423 typedef _Reference reference;
424 typedef _Category iterator_category;
425};
426
427template <class _InputIter>
428inline _LIBCPP_INLINE_VISIBILITY
429void __advance(_InputIter& __i,
430 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
431{
432 for (; __n > 0; --__n)
433 ++__i;
434}
435
436template <class _BiDirIter>
437inline _LIBCPP_INLINE_VISIBILITY
438void __advance(_BiDirIter& __i,
439 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
440{
441 if (__n >= 0)
442 for (; __n > 0; --__n)
443 ++__i;
444 else
445 for (; __n < 0; ++__n)
446 --__i;
447}
448
449template <class _RandIter>
450inline _LIBCPP_INLINE_VISIBILITY
451void __advance(_RandIter& __i,
452 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
453{
454 __i += __n;
455}
456
457template <class _InputIter>
458inline _LIBCPP_INLINE_VISIBILITY
459void advance(_InputIter& __i,
460 typename iterator_traits<_InputIter>::difference_type __n)
461{
462 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
463}
464
465template <class _InputIter>
466inline _LIBCPP_INLINE_VISIBILITY
467typename iterator_traits<_InputIter>::difference_type
468__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
469{
470 typename iterator_traits<_InputIter>::difference_type __r(0);
471 for (; __first != __last; ++__first)
472 ++__r;
473 return __r;
474}
475
476template <class _RandIter>
477inline _LIBCPP_INLINE_VISIBILITY
478typename iterator_traits<_RandIter>::difference_type
479__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
480{
481 return __last - __first;
482}
483
484template <class _InputIter>
485inline _LIBCPP_INLINE_VISIBILITY
486typename iterator_traits<_InputIter>::difference_type
487distance(_InputIter __first, _InputIter __last)
488{
489 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
490}
491
492template <class _ForwardIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000493inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494_ForwardIter
495next(_ForwardIter __x,
496 typename iterator_traits<_ForwardIter>::difference_type __n = 1,
497 typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
498{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000499 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 return __x;
501}
502
503template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000504inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505_BidiretionalIter
506prev(_BidiretionalIter __x,
507 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
508 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
509{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000510 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511 return __x;
512}
513
514template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000515class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000516 : public iterator<typename iterator_traits<_Iter>::iterator_category,
517 typename iterator_traits<_Iter>::value_type,
518 typename iterator_traits<_Iter>::difference_type,
519 typename iterator_traits<_Iter>::pointer,
520 typename iterator_traits<_Iter>::reference>
521{
522private:
523 mutable _Iter __t;
524protected:
525 _Iter current;
526public:
527 typedef _Iter iterator_type;
528 typedef typename iterator_traits<_Iter>::difference_type difference_type;
529 typedef typename iterator_traits<_Iter>::reference reference;
530 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000531
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
533 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
534 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
535 : __t(__u.base()), current(__u.base()) {}
536 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
537 _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;}
538 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &(operator*());}
539 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
540 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
541 {reverse_iterator __tmp(*this); --current; return __tmp;}
542 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
543 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
544 {reverse_iterator __tmp(*this); ++current; return __tmp;}
545 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
546 {return reverse_iterator(current - __n);}
547 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
548 {current -= __n; return *this;}
549 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
550 {return reverse_iterator(current + __n);}
551 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
552 {current += __n; return *this;}
553 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
554 {return current[-__n-1];}
555};
556
557template <class _Iter1, class _Iter2>
558inline _LIBCPP_INLINE_VISIBILITY
559bool
560operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
561{
562 return __x.base() == __y.base();
563}
564
565template <class _Iter1, class _Iter2>
566inline _LIBCPP_INLINE_VISIBILITY
567bool
568operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
569{
570 return __x.base() > __y.base();
571}
572
573template <class _Iter1, class _Iter2>
574inline _LIBCPP_INLINE_VISIBILITY
575bool
576operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
577{
578 return __x.base() != __y.base();
579}
580
581template <class _Iter1, class _Iter2>
582inline _LIBCPP_INLINE_VISIBILITY
583bool
584operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
585{
586 return __x.base() < __y.base();
587}
588
589template <class _Iter1, class _Iter2>
590inline _LIBCPP_INLINE_VISIBILITY
591bool
592operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
593{
594 return __x.base() <= __y.base();
595}
596
597template <class _Iter1, class _Iter2>
598inline _LIBCPP_INLINE_VISIBILITY
599bool
600operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
601{
602 return __x.base() >= __y.base();
603}
604
605template <class _Iter1, class _Iter2>
606inline _LIBCPP_INLINE_VISIBILITY
607typename reverse_iterator<_Iter1>::difference_type
608operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
609{
610 return __y.base() - __x.base();
611}
612
613template <class _Iter>
614inline _LIBCPP_INLINE_VISIBILITY
615reverse_iterator<_Iter>
616operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
617{
618 return reverse_iterator<_Iter>(__x.base() - __n);
619}
620
621template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000622class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623 : public iterator<output_iterator_tag,
624 void,
625 void,
626 void,
627 back_insert_iterator<_Container>&>
628{
629protected:
630 _Container* container;
631public:
632 typedef _Container container_type;
633
634 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000635 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
636 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000637#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000638 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
639 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000640#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
642 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
643 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
644};
645
646template <class _Container>
647inline _LIBCPP_INLINE_VISIBILITY
648back_insert_iterator<_Container>
649back_inserter(_Container& __x)
650{
651 return back_insert_iterator<_Container>(__x);
652}
653
654template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000655class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656 : public iterator<output_iterator_tag,
657 void,
658 void,
659 void,
660 front_insert_iterator<_Container>&>
661{
662protected:
663 _Container* container;
664public:
665 typedef _Container container_type;
666
667 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000668 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
669 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000670#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000671 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
672 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000673#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
675 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
676 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
677};
678
679template <class _Container>
680inline _LIBCPP_INLINE_VISIBILITY
681front_insert_iterator<_Container>
682front_inserter(_Container& __x)
683{
684 return front_insert_iterator<_Container>(__x);
685}
686
687template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000688class _LIBCPP_TYPE_VIS_ONLY insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 : public iterator<output_iterator_tag,
690 void,
691 void,
692 void,
693 insert_iterator<_Container>&>
694{
695protected:
696 _Container* container;
697 typename _Container::iterator iter;
698public:
699 typedef _Container container_type;
700
701 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
702 : container(&__x), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000703 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
704 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000705#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000706 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
707 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000708#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
710 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
711 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
712};
713
714template <class _Container>
715inline _LIBCPP_INLINE_VISIBILITY
716insert_iterator<_Container>
717inserter(_Container& __x, typename _Container::iterator __i)
718{
719 return insert_iterator<_Container>(__x, __i);
720}
721
722template <class _Tp, class _CharT = char,
723 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000724class _LIBCPP_TYPE_VIS_ONLY istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
726{
727public:
728 typedef _CharT char_type;
729 typedef _Traits traits_type;
730 typedef basic_istream<_CharT,_Traits> istream_type;
731private:
732 istream_type* __in_stream_;
733 _Tp __value_;
734public:
735 _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {}
736 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
737 {
738 if (!(*__in_stream_ >> __value_))
739 __in_stream_ = 0;
740 }
741
742 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
743 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
744 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
745 {
746 if (!(*__in_stream_ >> __value_))
747 __in_stream_ = 0;
748 return *this;
749 }
750 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
751 {istream_iterator __t(*this); ++(*this); return __t;}
752
753 friend _LIBCPP_INLINE_VISIBILITY
754 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
755 {return __x.__in_stream_ == __y.__in_stream_;}
756
757 friend _LIBCPP_INLINE_VISIBILITY
758 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
759 {return !(__x == __y);}
760};
761
762template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000763class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000764 : public iterator<output_iterator_tag, void, void, void, void>
765{
766public:
767 typedef _CharT char_type;
768 typedef _Traits traits_type;
769 typedef basic_ostream<_CharT,_Traits> ostream_type;
770private:
771 ostream_type* __out_stream_;
772 const char_type* __delim_;
773public:
774 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
775 : __out_stream_(&__s), __delim_(0) {}
776 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
777 : __out_stream_(&__s), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000778 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000780 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781 if (__delim_)
782 *__out_stream_ << __delim_;
783 return *this;
784 }
785
786 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
787 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
788 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
789};
790
791template<class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000792class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793 : public iterator<input_iterator_tag, _CharT,
794 typename _Traits::off_type, _CharT*,
795 _CharT>
796{
797public:
798 typedef _CharT char_type;
799 typedef _Traits traits_type;
800 typedef typename _Traits::int_type int_type;
801 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
802 typedef basic_istream<_CharT,_Traits> istream_type;
803private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000804 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805
806 class __proxy
807 {
808 char_type __keep_;
809 streambuf_type* __sbuf_;
810 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
811 : __keep_(__c), __sbuf_(__s) {}
812 friend class istreambuf_iterator;
813 public:
814 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
815 };
816
Howard Hinnant82894812010-09-22 16:48:34 +0000817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000818 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819 {
820 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
821 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000822 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823 }
824public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000825 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000826 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000827 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000828 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000829 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000830 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831 : __sbuf_(__p.__sbuf_) {}
832
Howard Hinnantec3773c2011-12-01 20:21:04 +0000833 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
834 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
836 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
837 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000838 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839 return *this;
840 }
841 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
842 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000843 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000844 }
845
846 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000847 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848};
849
850template <class _CharT, class _Traits>
851inline _LIBCPP_INLINE_VISIBILITY
852bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
853 const istreambuf_iterator<_CharT,_Traits>& __b)
854 {return __a.equal(__b);}
855
856template <class _CharT, class _Traits>
857inline _LIBCPP_INLINE_VISIBILITY
858bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
859 const istreambuf_iterator<_CharT,_Traits>& __b)
860 {return !__a.equal(__b);}
861
862template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000863class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864 : public iterator<output_iterator_tag, void, void, void, void>
865{
866public:
867 typedef _CharT char_type;
868 typedef _Traits traits_type;
869 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
870 typedef basic_ostream<_CharT,_Traits> ostream_type;
871private:
872 streambuf_type* __sbuf_;
873public:
Howard Hinnantd06a6402012-07-20 19:36:34 +0000874 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000876 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877 : __sbuf_(__s) {}
878 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
879 {
880 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
881 __sbuf_ = 0;
882 return *this;
883 }
884 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
885 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
886 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000887 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +0000888
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000889#if !defined(__APPLE__) || \
890 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
891 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
892
Howard Hinnanta585de62012-09-19 19:14:15 +0000893 template <class _Ch, class _Tr>
894 friend
895 _LIBCPP_HIDDEN
896 ostreambuf_iterator<_Ch, _Tr>
897 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
898 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
899 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000900#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901};
902
903template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000904class _LIBCPP_TYPE_VIS_ONLY move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905{
906private:
907 _Iter __i;
908public:
909 typedef _Iter iterator_type;
910 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
911 typedef typename iterator_traits<iterator_type>::value_type value_type;
912 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
913 typedef typename iterator_traits<iterator_type>::pointer pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000914#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915 typedef value_type&& reference;
916#else
917 typedef typename iterator_traits<iterator_type>::reference reference;
918#endif
Howard Hinnant324bb032010-08-22 00:02:43 +0000919
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
921 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
922 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
923 : __i(__u.base()) {}
924 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +0000925 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
926 return static_cast<reference>(*__i);
927 }
928 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
929 typename iterator_traits<iterator_type>::reference __ref = *__i;
930 return &__ref;
931 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
933 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
934 {move_iterator __tmp(*this); ++__i; return __tmp;}
935 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
936 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
937 {move_iterator __tmp(*this); --__i; return __tmp;}
938 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
939 {return move_iterator(__i + __n);}
940 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
941 {__i += __n; return *this;}
942 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
943 {return move_iterator(__i - __n);}
944 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
945 {__i -= __n; return *this;}
946 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +0000947 {
948 return static_cast<reference>(__i[__n]);
949 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000950};
951
952template <class _Iter1, class _Iter2>
953inline _LIBCPP_INLINE_VISIBILITY
954bool
955operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
956{
957 return __x.base() == __y.base();
958}
959
960template <class _Iter1, class _Iter2>
961inline _LIBCPP_INLINE_VISIBILITY
962bool
963operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
964{
965 return __x.base() < __y.base();
966}
967
968template <class _Iter1, class _Iter2>
969inline _LIBCPP_INLINE_VISIBILITY
970bool
971operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
972{
973 return __x.base() != __y.base();
974}
975
976template <class _Iter1, class _Iter2>
977inline _LIBCPP_INLINE_VISIBILITY
978bool
979operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
980{
981 return __x.base() > __y.base();
982}
983
984template <class _Iter1, class _Iter2>
985inline _LIBCPP_INLINE_VISIBILITY
986bool
987operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
988{
989 return __x.base() >= __y.base();
990}
991
992template <class _Iter1, class _Iter2>
993inline _LIBCPP_INLINE_VISIBILITY
994bool
995operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
996{
997 return __x.base() <= __y.base();
998}
999
1000template <class _Iter1, class _Iter2>
1001inline _LIBCPP_INLINE_VISIBILITY
1002typename move_iterator<_Iter1>::difference_type
1003operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1004{
1005 return __x.base() - __y.base();
1006}
1007
1008template <class _Iter>
1009inline _LIBCPP_INLINE_VISIBILITY
1010move_iterator<_Iter>
1011operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1012{
1013 return move_iterator<_Iter>(__x.base() + __n);
1014}
1015
1016template <class _Iter>
1017inline _LIBCPP_INLINE_VISIBILITY
1018move_iterator<_Iter>
1019make_move_iterator(const _Iter& __i)
1020{
1021 return move_iterator<_Iter>(__i);
1022}
1023
1024// __wrap_iter
1025
1026template <class _Iter> class __wrap_iter;
1027
1028template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001029_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001030bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001031operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001032
1033template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001034_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001036operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001037
1038template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001039_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001040bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001041operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042
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 +00001060typename __wrap_iter<_Iter1>::difference_type
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 _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001064_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001066operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067
Howard Hinnant33be35e2012-09-14 00:39:16 +00001068template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1069template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1070template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1071template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072
1073template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001074_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075typename enable_if
1076<
Howard Hinnant1468b662010-11-19 22:17:28 +00001077 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078 _Tp*
1079>::type
1080__unwrap_iter(__wrap_iter<_Tp*>);
1081
1082template <class _Iter>
1083class __wrap_iter
1084{
1085public:
1086 typedef _Iter iterator_type;
1087 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1088 typedef typename iterator_traits<iterator_type>::value_type value_type;
1089 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1090 typedef typename iterator_traits<iterator_type>::pointer pointer;
1091 typedef typename iterator_traits<iterator_type>::reference reference;
1092private:
1093 iterator_type __i;
1094public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001095 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001096#if _LIBCPP_STD_VER > 11
1097 : __i{}
1098#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001099 {
1100#if _LIBCPP_DEBUG_LEVEL >= 2
1101 __get_db()->__insert_i(this);
1102#endif
1103 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001105 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001106 : __i(__u.base())
1107 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001108#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001109 __get_db()->__iterator_copy(this, &__u);
1110#endif
1111 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001112#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001113 _LIBCPP_INLINE_VISIBILITY
1114 __wrap_iter(const __wrap_iter& __x)
1115 : __i(__x.base())
1116 {
1117 __get_db()->__iterator_copy(this, &__x);
1118 }
1119 _LIBCPP_INLINE_VISIBILITY
1120 __wrap_iter& operator=(const __wrap_iter& __x)
1121 {
1122 if (this != &__x)
1123 {
1124 __get_db()->__iterator_copy(this, &__x);
1125 __i = __x.__i;
1126 }
1127 return *this;
1128 }
1129 _LIBCPP_INLINE_VISIBILITY
1130 ~__wrap_iter()
1131 {
1132 __get_db()->__erase_i(this);
1133 }
1134#endif
1135 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1136 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001137#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001138 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1139 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001140#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001141 return *__i;
1142 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001143 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1144 {
1145#if _LIBCPP_DEBUG_LEVEL >= 2
1146 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1147 "Attempted to dereference a non-dereferenceable iterator");
1148#endif
1149 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
1150 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001151 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1152 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001153#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001154 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1155 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001156#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001157 ++__i;
1158 return *this;
1159 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001160 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001161 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1162 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1163 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001164#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001165 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1166 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001167#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001168 --__i;
1169 return *this;
1170 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001171 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001172 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001173 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001174 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001175 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001176 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001177#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001178 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1179 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001180#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001181 __i += __n;
1182 return *this;
1183 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001184 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001185 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001186 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001187 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001188 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001189 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001190#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001191 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1192 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001193#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001194 return __i[__n];
1195 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001196
Howard Hinnanta6119a82011-05-29 19:57:12 +00001197 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198
1199private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001200#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001201 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1202 {
1203 __get_db()->__insert_ic(this, __p);
1204 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001205#else
1206 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001207#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001208
1209 template <class _Up> friend class __wrap_iter;
1210 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1211 template <class _Tp, class _Alloc> friend class vector;
1212
1213 template <class _Iter1, class _Iter2>
1214 friend
1215 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001216 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001217
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218 template <class _Iter1, class _Iter2>
1219 friend
1220 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001221 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001222
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223 template <class _Iter1, class _Iter2>
1224 friend
1225 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001226 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001227
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001228 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 typename __wrap_iter<_Iter1>::difference_type
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>
1249 friend
1250 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001251 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001252
Howard Hinnant99968442011-11-29 18:15:50 +00001253 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001254 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001255 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001256 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1257
1258 template <class _Tp>
1259 friend
1260 typename enable_if
1261 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001262 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263 _Tp*
1264 >::type
1265 __unwrap_iter(__wrap_iter<_Tp*>);
1266};
1267
1268template <class _Iter1, class _Iter2>
1269inline _LIBCPP_INLINE_VISIBILITY
1270bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001271operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272{
1273 return __x.base() == __y.base();
1274}
1275
1276template <class _Iter1, class _Iter2>
1277inline _LIBCPP_INLINE_VISIBILITY
1278bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001279operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280{
Howard Hinnantabe26282011-09-16 17:29:17 +00001281#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001282 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001283 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001284#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001285 return __x.base() < __y.base();
1286}
1287
1288template <class _Iter1, class _Iter2>
1289inline _LIBCPP_INLINE_VISIBILITY
1290bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001291operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001293 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001294}
1295
1296template <class _Iter1, class _Iter2>
1297inline _LIBCPP_INLINE_VISIBILITY
1298bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001299operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001300{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001301 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001302}
1303
1304template <class _Iter1, class _Iter2>
1305inline _LIBCPP_INLINE_VISIBILITY
1306bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001307operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001308{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001309 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001310}
1311
1312template <class _Iter1, class _Iter2>
1313inline _LIBCPP_INLINE_VISIBILITY
1314bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001315operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001317 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318}
1319
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001320template <class _Iter1>
1321inline _LIBCPP_INLINE_VISIBILITY
1322bool
1323operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1324{
1325 return !(__x == __y);
1326}
1327
1328template <class _Iter1>
1329inline _LIBCPP_INLINE_VISIBILITY
1330bool
1331operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1332{
1333 return __y < __x;
1334}
1335
1336template <class _Iter1>
1337inline _LIBCPP_INLINE_VISIBILITY
1338bool
1339operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1340{
1341 return !(__x < __y);
1342}
1343
1344template <class _Iter1>
1345inline _LIBCPP_INLINE_VISIBILITY
1346bool
1347operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1348{
1349 return !(__y < __x);
1350}
1351
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352template <class _Iter1, class _Iter2>
1353inline _LIBCPP_INLINE_VISIBILITY
1354typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001355operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001356{
Howard Hinnantabe26282011-09-16 17:29:17 +00001357#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001358 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001359 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001360#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361 return __x.base() - __y.base();
1362}
1363
1364template <class _Iter>
1365inline _LIBCPP_INLINE_VISIBILITY
1366__wrap_iter<_Iter>
1367operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001368 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001369{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001370 __x += __n;
1371 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001372}
1373
1374#ifdef _LIBCPP_DEBUG
1375
1376// __debug_iter
1377
1378template <class _Container, class _Iter> class __debug_iter;
1379
1380template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001381_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382bool
1383operator==(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1384
1385template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001386_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387bool
1388operator<(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1389
1390template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001391_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001392bool
1393operator!=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1394
1395template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001396_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001397bool
1398operator>(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1399
1400template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001401_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402bool
1403operator>=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1404
1405template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001406_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001407bool
1408operator<=(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1409
1410template <class _Container, class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001411_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412typename __debug_iter<_Container, _Iter1>::difference_type
1413operator-(const __debug_iter<_Container, _Iter1>&, const __debug_iter<_Container, _Iter2>&);
1414
1415template <class _Container, class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001416_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417__debug_iter<_Container, _Iter>
1418operator+(typename __debug_iter<_Container, _Iter>::difference_type, const __debug_iter<_Container, _Iter>&);
1419
1420template <class _Container, class _Iter>
1421class __debug_iter
1422{
1423public:
1424 typedef _Iter iterator_type;
1425 typedef _Container __container_type;
1426 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1427 typedef typename iterator_traits<iterator_type>::value_type value_type;
1428 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1429 typedef typename iterator_traits<iterator_type>::pointer pointer;
1430 typedef typename iterator_traits<iterator_type>::reference reference;
1431private:
1432 iterator_type __i;
1433 __debug_iter* __next;
1434 __container_type* __cont;
Howard Hinnant324bb032010-08-22 00:02:43 +00001435
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436public:
1437 _LIBCPP_INLINE_VISIBILITY __debug_iter() : __next(0), __cont(0) {}
1438 _LIBCPP_INLINE_VISIBILITY __debug_iter(const __debug_iter& __x)
1439 : __i(__x.base()), __next(0), __cont(0) {__set_owner(__x.__cont);}
1440 __debug_iter& operator=(const __debug_iter& __x);
1441 template <class _Up> _LIBCPP_INLINE_VISIBILITY __debug_iter(const __debug_iter<_Container, _Up>& __u,
1442 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0)
1443 : __i(__u.base()), __next(0), __cont(0) {__set_owner(__u.__cont);}
1444 _LIBCPP_INLINE_VISIBILITY ~__debug_iter() {__remove_owner();}
1445 _LIBCPP_INLINE_VISIBILITY reference operator*() const {assert(__is_deref()); return *__i;}
1446 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &(operator*());}
1447 _LIBCPP_INLINE_VISIBILITY __debug_iter& operator++() {assert(__can_increment()); ++__i; return *this;}
1448 _LIBCPP_INLINE_VISIBILITY __debug_iter operator++(int)
1449 {__debug_iter __tmp(*this); operator++(); return __tmp;}
1450 _LIBCPP_INLINE_VISIBILITY __debug_iter& operator--() {assert(__can_decrement()); --__i; return *this;}
1451 _LIBCPP_INLINE_VISIBILITY __debug_iter operator--(int)
1452 {__debug_iter __tmp(*this); operator--(); return __tmp;}
1453 _LIBCPP_INLINE_VISIBILITY __debug_iter operator+ (difference_type __n) const
1454 {__debug_iter __t(*this); __t += __n; return __t;}
1455 __debug_iter& operator+=(difference_type __n);
1456 _LIBCPP_INLINE_VISIBILITY __debug_iter operator- (difference_type __n) const
1457 {__debug_iter __t(*this); __t -= __n; return __t;}
1458 _LIBCPP_INLINE_VISIBILITY __debug_iter& operator-=(difference_type __n)
1459 {*this += -__n; return *this;}
1460 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
1461 {return *(*this + __n);}
1462
1463private:
1464 _LIBCPP_INLINE_VISIBILITY __debug_iter(const __container_type* __c, iterator_type __x)
1465 : __i(__x), __next(0), __cont(0) {__set_owner(__c);}
1466 _LIBCPP_INLINE_VISIBILITY iterator_type base() const {return __i;}
1467
1468 void __set_owner(const __container_type* __c);
1469 void __remove_owner();
1470 static void __remove_all(__container_type* __c);
1471 static void swap(__container_type* __x, __container_type* __y);
Howard Hinnant324bb032010-08-22 00:02:43 +00001472
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001473 _LIBCPP_INLINE_VISIBILITY bool __is_deref() const
1474 {return __is_deref(__is_random_access_iterator<iterator_type>());}
1475 bool __is_deref(false_type) const;
1476 bool __is_deref(true_type) const;
1477 _LIBCPP_INLINE_VISIBILITY bool __can_decrement() const
1478 {return __can_decrement(integral_constant<int, is_pointer<iterator_type>::value ? 2:
1479 __is_random_access_iterator<iterator_type>::value ? 1 : 0>());}
1480 bool __can_decrement(integral_constant<int, 0>) const;
1481 bool __can_decrement(integral_constant<int, 1>) const;
1482 bool __can_decrement(integral_constant<int, 2>) const;
1483 _LIBCPP_INLINE_VISIBILITY bool __can_increment() const
1484 {return __can_increment(integral_constant<int, is_pointer<iterator_type>::value ? 2:
1485 __is_random_access_iterator<iterator_type>::value ? 1 : 0>());}
1486 bool __can_increment(integral_constant<int, 0>) const;
1487 bool __can_increment(integral_constant<int, 1>) const;
1488 bool __can_increment(integral_constant<int, 2>) const;
1489
1490 _LIBCPP_INLINE_VISIBILITY bool __can_add(difference_type __n) const
1491 {return __can_add(__n, is_pointer<iterator_type>());}
1492 bool __can_add(difference_type __n, false_type) const;
1493 bool __can_add(difference_type __n, true_type) const;
1494
1495 template <class _Cp, class _Up> friend class __debug_iter;
1496 friend class _Container::__self;
1497
1498 template <class _Cp, class _Iter1, class _Iter2>
1499 friend
1500 bool
1501 operator==(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001502
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001503 template <class _Cp, class _Iter1, class _Iter2>
1504 friend
1505 bool
1506 operator<(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001507
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508 template <class _Cp, class _Iter1, class _Iter2>
1509 friend
1510 bool
1511 operator!=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001512
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513 template <class _Cp, class _Iter1, class _Iter2>
1514 friend
1515 bool
1516 operator>(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001517
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518 template <class _Cp, class _Iter1, class _Iter2>
1519 friend
1520 bool
1521 operator>=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001522
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001523 template <class _Cp, class _Iter1, class _Iter2>
1524 friend
1525 bool
1526 operator<=(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001527
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528 template <class _Cp, class _Iter1, class _Iter2>
1529 friend
1530 typename __debug_iter<_Cp, _Iter1>::difference_type
1531 operator-(const __debug_iter<_Cp, _Iter1>&, const __debug_iter<_Cp, _Iter2>&);
Howard Hinnant324bb032010-08-22 00:02:43 +00001532
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533 template <class _Cp, class _Iter1>
1534 friend
1535 __debug_iter<_Cp, _Iter1>
1536 operator+(typename __debug_iter<_Cp, _Iter1>::difference_type, const __debug_iter<_Cp, _Iter1>&);
1537};
1538
1539template <class _Container, class _Iter>
1540__debug_iter<_Container, _Iter>&
1541__debug_iter<_Container, _Iter>::operator=(const __debug_iter& __x)
1542{
1543 if (this != &__x)
1544 {
1545 __remove_owner();
1546 __i = __x.__i;
1547 __set_owner(__x.__cont);
1548 }
1549 return *this;
1550}
Howard Hinnant324bb032010-08-22 00:02:43 +00001551
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552template <class _Container, class _Iter>
1553void
1554__debug_iter<_Container, _Iter>::__set_owner(const __container_type* __c)
1555{
1556 __cont = const_cast<__container_type*>(__c);
1557 __debug_iter*& __head = __cont->__get_iterator_list(this);
1558 __next = __head;
1559 __head = this;
1560}
1561
1562template <class _Container, class _Iter>
1563void
1564__debug_iter<_Container, _Iter>::__remove_owner()
1565{
1566 if (__cont)
1567 {
1568 __debug_iter*& __head = __cont->__get_iterator_list(this);
1569 if (__head == this)
1570 __head = __next;
1571 else
1572 {
1573 __debug_iter* __prev = __head;
1574 for (__debug_iter* __p = __head->__next; __p != this; __p = __p->__next)
1575 __prev = __p;
1576 __prev->__next = __next;
1577 }
1578 __cont = 0;
1579 }
1580}
1581
1582template <class _Container, class _Iter>
1583void
1584__debug_iter<_Container, _Iter>::__remove_all(__container_type* __c)
1585{
1586 __debug_iter*& __head = __c->__get_iterator_list((__debug_iter*)0);
1587 __debug_iter* __p = __head;
1588 __head = 0;
1589 while (__p)
1590 {
1591 __p->__cont = 0;
1592 __debug_iter* __n = __p->__next;
1593 __p->__next = 0;
1594 __p = __n;
1595 }
1596}
1597
1598template <class _Container, class _Iter>
1599void
1600__debug_iter<_Container, _Iter>::swap(__container_type* __x, __container_type* __y)
1601{
1602 __debug_iter*& __head_x = __x->__get_iterator_list((__debug_iter*)0);
1603 __debug_iter*& __head_y = __y->__get_iterator_list((__debug_iter*)0);
1604 __debug_iter* __p = __head_x;
1605 __head_x = __head_y;
1606 __head_y = __p;
1607 for (__p = __head_x; __p; __p = __p->__next)
1608 __p->__cont = __x;
1609 for (__p = __head_y; __p; __p = __p->__next)
1610 __p->__cont = __y;
1611}
1612
1613template <class _Container, class _Iter>
1614bool
1615__debug_iter<_Container, _Iter>::__is_deref(false_type) const
1616{
1617 if (__cont == 0)
1618 return false;
1619 return __i != __cont->end().base();
1620}
1621
1622template <class _Container, class _Iter>
1623bool
1624__debug_iter<_Container, _Iter>::__is_deref(true_type) const
1625{
1626 if (__cont == 0)
1627 return false;
1628 return __i < __cont->end().base();
1629}
1630
1631template <class _Container, class _Iter>
1632bool
1633__debug_iter<_Container, _Iter>::__can_decrement(integral_constant<int, 0>) const
1634{
1635 if (__cont == 0)
1636 return false;
1637 return __i != __cont->begin().base();
1638}
1639
1640template <class _Container, class _Iter>
1641bool
1642__debug_iter<_Container, _Iter>::__can_decrement(integral_constant<int, 1>) const
1643{
1644 if (__cont == 0)
1645 return false;
1646 iterator_type __b = __cont->begin().base();
1647 return __b < __i && __i <= __b + __cont->size();
1648}
1649
1650template <class _Container, class _Iter>
1651bool
1652__debug_iter<_Container, _Iter>::__can_decrement(integral_constant<int, 2>) const
1653{
1654 if (__cont == 0)
1655 return false;
1656 iterator_type __b = __cont->begin().base();
1657 return __b < __i && __i <= __b + __cont->size();
1658}
1659
1660template <class _Container, class _Iter>
1661bool
1662__debug_iter<_Container, _Iter>::__can_increment(integral_constant<int, 0>) const
1663{
1664 if (__cont == 0)
1665 return false;
1666 return __i != __cont->end().base();
1667}
1668
1669template <class _Container, class _Iter>
1670bool
1671__debug_iter<_Container, _Iter>::__can_increment(integral_constant<int, 1>) const
1672{
1673 if (__cont == 0)
1674 return false;
1675 iterator_type __b = __cont->begin().base();
1676 return __b <= __i && __i < __b + __cont->size();
1677}
1678
1679template <class _Container, class _Iter>
1680bool
1681__debug_iter<_Container, _Iter>::__can_increment(integral_constant<int, 2>) const
1682{
1683 if (__cont == 0)
1684 return false;
1685 iterator_type __b = __cont->begin().base();
1686 return __b <= __i && __i < __b + __cont->size();
1687}
1688
1689template <class _Container, class _Iter>
1690bool
1691__debug_iter<_Container, _Iter>::__can_add(difference_type __n, false_type) const
1692{
1693 if (__cont == 0)
1694 return false;
1695 iterator_type __b = __cont->begin().base();
1696 iterator_type __j = __i + __n;
1697 return __b <= __j && __j <= __b + __cont->size();
1698}
1699
1700template <class _Container, class _Iter>
1701bool
1702__debug_iter<_Container, _Iter>::__can_add(difference_type __n, true_type) const
1703{
1704 if (__cont == 0)
1705 return false;
1706 iterator_type __b = __cont->begin().base();
1707 iterator_type __j = __i + __n;
1708 return __b <= __j && __j <= __b + __cont->size();
1709}
1710
1711template <class _Container, class _Iter>
1712__debug_iter<_Container, _Iter>&
1713__debug_iter<_Container, _Iter>::operator+=(difference_type __n)
1714{
1715 assert(__can_add(__n));
1716 __i += __n;
1717 return *this;
1718}
1719
1720template <class _Container, class _Iter1, class _Iter2>
1721inline _LIBCPP_INLINE_VISIBILITY
1722bool
1723operator==(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1724{
1725 assert(__x.__cont && __x.__cont == __y.__cont);
1726 return __x.base() == __y.base();
1727}
1728
1729template <class _Container, class _Iter1, class _Iter2>
1730inline _LIBCPP_INLINE_VISIBILITY
1731bool
1732operator!=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1733{
1734 return !(__x == __y);
1735}
1736
1737template <class _Container, class _Iter1, class _Iter2>
1738inline _LIBCPP_INLINE_VISIBILITY
1739bool
1740operator<(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1741{
1742 assert(__x.__cont && __x.__cont == __y.__cont);
1743 return __x.base() < __y.base();
1744}
1745
1746template <class _Container, class _Iter1, class _Iter2>
1747inline _LIBCPP_INLINE_VISIBILITY
1748bool
1749operator>(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1750{
1751 return __y < __x;
1752}
1753
1754template <class _Container, class _Iter1, class _Iter2>
1755inline _LIBCPP_INLINE_VISIBILITY
1756bool
1757operator>=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1758{
1759 return !(__x < __y);
1760}
1761
1762template <class _Container, class _Iter1, class _Iter2>
1763inline _LIBCPP_INLINE_VISIBILITY
1764bool
1765operator<=(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1766{
1767 return !(__y < __x);
1768}
1769
1770template <class _Container, class _Iter1, class _Iter2>
1771inline _LIBCPP_INLINE_VISIBILITY
1772typename __debug_iter<_Container, _Iter1>::difference_type
1773operator-(const __debug_iter<_Container, _Iter1>& __x, const __debug_iter<_Container, _Iter2>& __y)
1774{
1775 assert(__x.__cont && __x.__cont == __y.__cont);
1776 return __x.base() - __y.base();
1777}
1778
1779template <class _Container, class _Iter>
1780inline _LIBCPP_INLINE_VISIBILITY
1781__debug_iter<_Container, _Iter>
1782operator+(typename __debug_iter<_Container, _Iter>::difference_type __n,
1783 const __debug_iter<_Container, _Iter>& __x)
1784{
1785 return __x + __n;
1786}
1787
1788#endif // _LIBCPP_DEBUG
1789
Howard Hinnant726a76f2010-11-16 21:10:23 +00001790#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001791
Howard Hinnant99968442011-11-29 18:15:50 +00001792template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001793inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001794auto
Howard Hinnant99968442011-11-29 18:15:50 +00001795begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001796{
1797 return __c.begin();
1798}
1799
Howard Hinnant99968442011-11-29 18:15:50 +00001800template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001801inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001802auto
Howard Hinnant99968442011-11-29 18:15:50 +00001803begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804{
1805 return __c.begin();
1806}
1807
Howard Hinnant99968442011-11-29 18:15:50 +00001808template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001809inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810auto
Howard Hinnant99968442011-11-29 18:15:50 +00001811end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812{
1813 return __c.end();
1814}
1815
Howard Hinnant99968442011-11-29 18:15:50 +00001816template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001817inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818auto
Howard Hinnant99968442011-11-29 18:15:50 +00001819end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001820{
1821 return __c.end();
1822}
1823
Howard Hinnant726a76f2010-11-16 21:10:23 +00001824#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825
Howard Hinnant99968442011-11-29 18:15:50 +00001826template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001827inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001828typename _Cp::iterator
1829begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001830{
1831 return __c.begin();
1832}
1833
Howard Hinnant99968442011-11-29 18:15:50 +00001834template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001835inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001836typename _Cp::const_iterator
1837begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001838{
1839 return __c.begin();
1840}
1841
Howard Hinnant99968442011-11-29 18:15:50 +00001842template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001843inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001844typename _Cp::iterator
1845end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846{
1847 return __c.end();
1848}
1849
Howard Hinnant99968442011-11-29 18:15:50 +00001850template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001851inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001852typename _Cp::const_iterator
1853end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001854{
1855 return __c.end();
1856}
1857
Howard Hinnant726a76f2010-11-16 21:10:23 +00001858#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001859
Howard Hinnant99968442011-11-29 18:15:50 +00001860template <class _Tp, size_t _Np>
Howard Hinnant82894812010-09-22 16:48:34 +00001861inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001862_Tp*
1863begin(_Tp (&__array)[_Np])
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001864{
1865 return __array;
1866}
1867
Howard Hinnant99968442011-11-29 18:15:50 +00001868template <class _Tp, size_t _Np>
Howard Hinnant82894812010-09-22 16:48:34 +00001869inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001870_Tp*
1871end(_Tp (&__array)[_Np])
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872{
Howard Hinnant99968442011-11-29 18:15:50 +00001873 return __array + _Np;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874}
1875
1876_LIBCPP_END_NAMESPACE_STD
1877
1878#endif // _LIBCPP_ITERATOR