blob: 9ac4351518e79dd7987c54a7b4ec7d54b0e3922f [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_ITERATOR
12#define _LIBCPP_ITERATOR
13
14/*
15 iterator synopsis
16
17namespace std
18{
19
20template<class Iterator>
21struct iterator_traits
22{
23 typedef typename Iterator::difference_type difference_type;
24 typedef typename Iterator::value_type value_type;
25 typedef typename Iterator::pointer pointer;
26 typedef typename Iterator::reference reference;
27 typedef typename Iterator::iterator_category iterator_category;
28};
29
30template<class T>
31struct iterator_traits<T*>
32{
33 typedef ptrdiff_t difference_type;
34 typedef T value_type;
35 typedef T* pointer;
36 typedef T& reference;
37 typedef random_access_iterator_tag iterator_category;
38};
39
40template<class T>
41struct iterator_traits<const T*>
42{
43 typedef ptrdiff_t difference_type;
44 typedef T value_type;
45 typedef const T* pointer;
46 typedef const T& reference;
47 typedef random_access_iterator_tag iterator_category;
48};
49
50template<class Category, class T, class Distance = ptrdiff_t,
51 class Pointer = T*, class Reference = T&>
52struct iterator
53{
54 typedef T value_type;
55 typedef Distance difference_type;
56 typedef Pointer pointer;
57 typedef Reference reference;
58 typedef Category iterator_category;
59};
60
61struct input_iterator_tag {};
62struct output_iterator_tag {};
63struct forward_iterator_tag : public input_iterator_tag {};
64struct bidirectional_iterator_tag : public forward_iterator_tag {};
65struct random_access_iterator_tag : public bidirectional_iterator_tag {};
66
67// extension: second argument not conforming to C++03
68template <class InputIterator>
69void advance(InputIterator& i,
70 typename iterator_traits<InputIterator>::difference_type n);
71
72template <class InputIterator>
73typename iterator_traits<InputIterator>::difference_type
74distance(InputIterator first, InputIterator last);
75
76template <class Iterator>
77class reverse_iterator
78 : public iterator<typename iterator_traits<Iterator>::iterator_category,
79 typename iterator_traits<Iterator>::value_type,
80 typename iterator_traits<Iterator>::difference_type,
81 typename iterator_traits<Iterator>::pointer,
82 typename iterator_traits<Iterator>::reference>
83{
84protected:
85 Iterator current;
86public:
87 typedef Iterator iterator_type;
88 typedef typename iterator_traits<Iterator>::difference_type difference_type;
89 typedef typename iterator_traits<Iterator>::reference reference;
90 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +000091
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092 reverse_iterator();
93 explicit reverse_iterator(Iterator x);
94 template <class U> reverse_iterator(const reverse_iterator<U>& u);
95 Iterator base() const;
96 reference operator*() const;
97 pointer operator->() const;
98 reverse_iterator& operator++();
99 reverse_iterator operator++(int);
100 reverse_iterator& operator--();
101 reverse_iterator operator--(int);
102 reverse_iterator operator+ (difference_type n) const;
103 reverse_iterator& operator+=(difference_type n);
104 reverse_iterator operator- (difference_type n) const;
105 reverse_iterator& operator-=(difference_type n);
106 reference operator[](difference_type n) const;
107};
108
109template <class Iterator1, class Iterator2>
110bool
111operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
112
113template <class Iterator1, class Iterator2>
114bool
115operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
116
117template <class Iterator1, class Iterator2>
118bool
119operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
120
121template <class Iterator1, class Iterator2>
122bool
123operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
124
125template <class Iterator1, class Iterator2>
126bool
127operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
128
129template <class Iterator1, class Iterator2>
130bool
131operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
132
133template <class Iterator1, class Iterator2>
134typename reverse_iterator<Iterator1>::difference_type
135operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
136
137template <class Iterator>
138reverse_iterator<Iterator>
139operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x);
140
Marshall Clowff137e92014-03-03 01:24:04 +0000141template <class Iterator> reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14
142
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143template <class Container>
144class back_insert_iterator
145{
146protected:
147 Container* container;
148public:
149 typedef Container container_type;
150 typedef void value_type;
151 typedef void difference_type;
152 typedef back_insert_iterator<Cont>& reference;
153 typedef void pointer;
154
155 explicit back_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000156 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000157 back_insert_iterator& operator*();
158 back_insert_iterator& operator++();
159 back_insert_iterator operator++(int);
160};
161
162template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
163
164template <class Container>
165class front_insert_iterator
166{
167protected:
168 Container* container;
169public:
170 typedef Container container_type;
171 typedef void value_type;
172 typedef void difference_type;
173 typedef front_insert_iterator<Cont>& reference;
174 typedef void pointer;
175
176 explicit front_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000177 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178 front_insert_iterator& operator*();
179 front_insert_iterator& operator++();
180 front_insert_iterator operator++(int);
181};
182
183template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
184
185template <class Container>
186class insert_iterator
187{
188protected:
189 Container* container;
190 typename Container::iterator iter;
191public:
192 typedef Container container_type;
193 typedef void value_type;
194 typedef void difference_type;
195 typedef insert_iterator<Cont>& reference;
196 typedef void pointer;
197
198 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant45f57172010-09-14 20:26:27 +0000199 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000200 insert_iterator& operator*();
201 insert_iterator& operator++();
202 insert_iterator& operator++(int);
203};
204
205template <class Container, class Iterator>
206insert_iterator<Container> inserter(Container& x, Iterator i);
207
208template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
209class istream_iterator
210 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
211{
212public:
213 typedef charT char_type;
214 typedef traits traits_type;
215 typedef basic_istream<charT,traits> istream_type;
216
Marshall Clowe9d03062015-04-16 21:36:54 +0000217 constexpr istream_iterator();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218 istream_iterator(istream_type& s);
219 istream_iterator(const istream_iterator& x);
220 ~istream_iterator();
221
222 const T& operator*() const;
223 const T* operator->() const;
224 istream_iterator& operator++();
225 istream_iterator operator++(int);
226};
227
228template <class T, class charT, class traits, class Distance>
229bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
230 const istream_iterator<T,charT,traits,Distance>& y);
231template <class T, class charT, class traits, class Distance>
232bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
233 const istream_iterator<T,charT,traits,Distance>& y);
234
235template <class T, class charT = char, class traits = char_traits<charT> >
236class ostream_iterator
237 : public iterator<output_iterator_tag, void, void, void ,void>
238{
239public:
240 typedef charT char_type;
241 typedef traits traits_type;
242 typedef basic_ostream<charT,traits> ostream_type;
243
244 ostream_iterator(ostream_type& s);
245 ostream_iterator(ostream_type& s, const charT* delimiter);
246 ostream_iterator(const ostream_iterator& x);
247 ~ostream_iterator();
248 ostream_iterator& operator=(const T& value);
249
250 ostream_iterator& operator*();
251 ostream_iterator& operator++();
252 ostream_iterator& operator++(int);
253};
254
255template<class charT, class traits = char_traits<charT> >
256class istreambuf_iterator
257 : public iterator<input_iterator_tag, charT,
258 typename traits::off_type, unspecified,
259 charT>
260{
261public:
262 typedef charT char_type;
263 typedef traits traits_type;
264 typedef typename traits::int_type int_type;
265 typedef basic_streambuf<charT,traits> streambuf_type;
266 typedef basic_istream<charT,traits> istream_type;
267
Howard Hinnantd06a6402012-07-20 19:36:34 +0000268 istreambuf_iterator() noexcept;
269 istreambuf_iterator(istream_type& s) noexcept;
270 istreambuf_iterator(streambuf_type* s) noexcept;
271 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272
273 charT operator*() const;
274 pointer operator->() const;
275 istreambuf_iterator& operator++();
276 a-private-type operator++(int);
277
278 bool equal(const istreambuf_iterator& b) const;
279};
280
281template <class charT, class traits>
282bool operator==(const istreambuf_iterator<charT,traits>& a,
283 const istreambuf_iterator<charT,traits>& b);
284template <class charT, class traits>
285bool operator!=(const istreambuf_iterator<charT,traits>& a,
286 const istreambuf_iterator<charT,traits>& b);
287
288template <class charT, class traits = char_traits<charT> >
289class ostreambuf_iterator
290 : public iterator<output_iterator_tag, void, void, void, void>
291{
292public:
293 typedef charT char_type;
294 typedef traits traits_type;
295 typedef basic_streambuf<charT,traits> streambuf_type;
296 typedef basic_ostream<charT,traits> ostream_type;
297
Howard Hinnantd06a6402012-07-20 19:36:34 +0000298 ostreambuf_iterator(ostream_type& s) noexcept;
299 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000300 ostreambuf_iterator& operator=(charT c);
301 ostreambuf_iterator& operator*();
302 ostreambuf_iterator& operator++();
303 ostreambuf_iterator& operator++(int);
Howard Hinnantd06a6402012-07-20 19:36:34 +0000304 bool failed() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305};
306
307template <class C> auto begin(C& c) -> decltype(c.begin());
308template <class C> auto begin(const C& c) -> decltype(c.begin());
309template <class C> auto end(C& c) -> decltype(c.end());
310template <class C> auto end(const C& c) -> decltype(c.end());
311template <class T, size_t N> T* begin(T (&array)[N]);
312template <class T, size_t N> T* end(T (&array)[N]);
313
Marshall Clow09da3c02013-08-30 01:17:07 +0000314template <class C> auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14
315template <class C> auto cend(const C& c) -> decltype(std::end(c)); // C++14
316template <class C> auto rbegin(C& c) -> decltype(c.rbegin()); // C++14
317template <class C> auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14
318template <class C> auto rend(C& c) -> decltype(c.rend()); // C++14
319template <class C> auto rend(const C& c) -> decltype(c.rend()); // C++14
320template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14
321template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); // C++14
322template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]); // C++14
323template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]); // C++14
324template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
325template <class C> auto crend(const C& c) -> decltype(std::rend(c)); // C++14
326
Marshall Clow03c67912014-11-19 19:43:23 +0000327// 24.8, container access:
328template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
329template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
330template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
331template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
332template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
333template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
334template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
335template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
336template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
337
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000338} // std
339
340*/
341
342#include <__config>
Marshall Clow02ca8af2014-02-27 02:11:50 +0000343#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000344#include <type_traits>
345#include <cstddef>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700346#include <iosfwd>
Marshall Clow09da3c02013-08-30 01:17:07 +0000347#include <initializer_list>
Marshall Clowdece7fe2013-03-18 17:45:34 +0000348#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000349#include <Availability.h>
350#endif
351
Eric Fiselierb9536102014-08-10 23:53:08 +0000352#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353
Howard Hinnant08e17472011-10-17 20:05:10 +0000354#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000356#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357
358_LIBCPP_BEGIN_NAMESPACE_STD
359
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000360struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
361struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
362struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
363struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
364struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365
366template <class _Tp>
367struct __has_iterator_category
368{
369private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000370 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371 template <class _Up> static __two __test(...);
372 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
373public:
374 static const bool value = sizeof(__test<_Tp>(0)) == 1;
375};
376
Marshall Clowa71f9562014-01-03 22:55:49 +0000377template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378
379template <class _Iter>
Marshall Clowa71f9562014-01-03 22:55:49 +0000380struct __iterator_traits_impl<_Iter, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381{
382 typedef typename _Iter::difference_type difference_type;
383 typedef typename _Iter::value_type value_type;
384 typedef typename _Iter::pointer pointer;
385 typedef typename _Iter::reference reference;
386 typedef typename _Iter::iterator_category iterator_category;
387};
388
389template <class _Iter, bool> struct __iterator_traits {};
390
391template <class _Iter>
392struct __iterator_traits<_Iter, true>
Marshall Clowa71f9562014-01-03 22:55:49 +0000393 : __iterator_traits_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394 <
395 _Iter,
396 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
397 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
398 >
399{};
400
401// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
402// exists. Else iterator_traits<Iterator> will be an empty class. This is a
403// conforming extension which allows some programs to compile and behave as
404// the client expects instead of failing at compile time.
405
406template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000407struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
409
410template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000411struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412{
413 typedef ptrdiff_t difference_type;
414 typedef typename remove_const<_Tp>::type value_type;
415 typedef _Tp* pointer;
416 typedef _Tp& reference;
417 typedef random_access_iterator_tag iterator_category;
418};
419
420template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
421struct __has_iterator_category_convertible_to
422 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
423{};
424
425template <class _Tp, class _Up>
426struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
427
428template <class _Tp>
429struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
430
431template <class _Tp>
432struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
433
434template <class _Tp>
435struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
436
437template <class _Tp>
438struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
439
440template<class _Category, class _Tp, class _Distance = ptrdiff_t,
441 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000442struct _LIBCPP_TYPE_VIS_ONLY iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443{
444 typedef _Tp value_type;
445 typedef _Distance difference_type;
446 typedef _Pointer pointer;
447 typedef _Reference reference;
448 typedef _Category iterator_category;
449};
450
451template <class _InputIter>
452inline _LIBCPP_INLINE_VISIBILITY
453void __advance(_InputIter& __i,
454 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
455{
456 for (; __n > 0; --__n)
457 ++__i;
458}
459
460template <class _BiDirIter>
461inline _LIBCPP_INLINE_VISIBILITY
462void __advance(_BiDirIter& __i,
463 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
464{
465 if (__n >= 0)
466 for (; __n > 0; --__n)
467 ++__i;
468 else
469 for (; __n < 0; ++__n)
470 --__i;
471}
472
473template <class _RandIter>
474inline _LIBCPP_INLINE_VISIBILITY
475void __advance(_RandIter& __i,
476 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
477{
478 __i += __n;
479}
480
481template <class _InputIter>
482inline _LIBCPP_INLINE_VISIBILITY
483void advance(_InputIter& __i,
484 typename iterator_traits<_InputIter>::difference_type __n)
485{
486 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
487}
488
489template <class _InputIter>
490inline _LIBCPP_INLINE_VISIBILITY
491typename iterator_traits<_InputIter>::difference_type
492__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
493{
494 typename iterator_traits<_InputIter>::difference_type __r(0);
495 for (; __first != __last; ++__first)
496 ++__r;
497 return __r;
498}
499
500template <class _RandIter>
501inline _LIBCPP_INLINE_VISIBILITY
502typename iterator_traits<_RandIter>::difference_type
503__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
504{
505 return __last - __first;
506}
507
508template <class _InputIter>
509inline _LIBCPP_INLINE_VISIBILITY
510typename iterator_traits<_InputIter>::difference_type
511distance(_InputIter __first, _InputIter __last)
512{
513 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
514}
515
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700516template <class _ForwardIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000517inline _LIBCPP_INLINE_VISIBILITY
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700518_ForwardIter
519next(_ForwardIter __x,
520 typename iterator_traits<_ForwardIter>::difference_type __n = 1,
521 typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000523 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 return __x;
525}
526
527template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000528inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529_BidiretionalIter
530prev(_BidiretionalIter __x,
531 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
532 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
533{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000534 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535 return __x;
536}
537
538template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000539class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540 : public iterator<typename iterator_traits<_Iter>::iterator_category,
541 typename iterator_traits<_Iter>::value_type,
542 typename iterator_traits<_Iter>::difference_type,
543 typename iterator_traits<_Iter>::pointer,
544 typename iterator_traits<_Iter>::reference>
545{
Marshall Clow668a1d82014-03-11 22:05:31 +0000546private:
547 mutable _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000548protected:
549 _Iter current;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550public:
551 typedef _Iter iterator_type;
552 typedef typename iterator_traits<_Iter>::difference_type difference_type;
553 typedef typename iterator_traits<_Iter>::reference reference;
554 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000555
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000556 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
557 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000559 : __t(__u.base()), current(__u.base()) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
Marshall Clowb1ead682014-03-11 17:16:17 +0000561 _LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;}
Marshall Clow02ca8af2014-02-27 02:11:50 +0000562 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
564 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
565 {reverse_iterator __tmp(*this); --current; return __tmp;}
566 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
567 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
568 {reverse_iterator __tmp(*this); ++current; return __tmp;}
569 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
570 {return reverse_iterator(current - __n);}
571 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
572 {current -= __n; return *this;}
573 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
574 {return reverse_iterator(current + __n);}
575 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
576 {current += __n; return *this;}
577 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Marshall Clowad98e212015-03-05 16:07:37 +0000578 {return *(*this + __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579};
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
607bool
608operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
609{
610 return __x.base() < __y.base();
611}
612
613template <class _Iter1, class _Iter2>
614inline _LIBCPP_INLINE_VISIBILITY
615bool
616operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
617{
618 return __x.base() <= __y.base();
619}
620
621template <class _Iter1, class _Iter2>
622inline _LIBCPP_INLINE_VISIBILITY
623bool
624operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
625{
626 return __x.base() >= __y.base();
627}
628
629template <class _Iter1, class _Iter2>
630inline _LIBCPP_INLINE_VISIBILITY
631typename reverse_iterator<_Iter1>::difference_type
632operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
633{
634 return __y.base() - __x.base();
635}
636
637template <class _Iter>
638inline _LIBCPP_INLINE_VISIBILITY
639reverse_iterator<_Iter>
640operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
641{
642 return reverse_iterator<_Iter>(__x.base() - __n);
643}
644
Marshall Clowff137e92014-03-03 01:24:04 +0000645#if _LIBCPP_STD_VER > 11
646template <class _Iter>
647inline _LIBCPP_INLINE_VISIBILITY
648reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
649{
650 return reverse_iterator<_Iter>(__i);
651}
652#endif
653
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000655class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656 : public iterator<output_iterator_tag,
657 void,
658 void,
659 void,
660 back_insert_iterator<_Container>&>
661{
662protected:
663 _Container* container;
664public:
665 typedef _Container container_type;
666
Marshall Clow53c0e722014-03-03 19:20:40 +0000667 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000668 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
669 {container->push_back(__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 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
672 {container->push_back(_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 back_insert_iterator& operator*() {return *this;}
675 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
676 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
677};
678
679template <class _Container>
680inline _LIBCPP_INLINE_VISIBILITY
681back_insert_iterator<_Container>
682back_inserter(_Container& __x)
683{
684 return back_insert_iterator<_Container>(__x);
685}
686
687template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000688class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 : public iterator<output_iterator_tag,
690 void,
691 void,
692 void,
693 front_insert_iterator<_Container>&>
694{
695protected:
696 _Container* container;
697public:
698 typedef _Container container_type;
699
Marshall Clow53c0e722014-03-03 19:20:40 +0000700 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000701 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
702 {container->push_front(__value_); 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 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
705 {container->push_front(_VSTD::move(__value_)); 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 front_insert_iterator& operator*() {return *this;}
708 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
709 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
710};
711
712template <class _Container>
713inline _LIBCPP_INLINE_VISIBILITY
714front_insert_iterator<_Container>
715front_inserter(_Container& __x)
716{
717 return front_insert_iterator<_Container>(__x);
718}
719
720template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000721class _LIBCPP_TYPE_VIS_ONLY insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722 : public iterator<output_iterator_tag,
723 void,
724 void,
725 void,
726 insert_iterator<_Container>&>
727{
728protected:
729 _Container* container;
730 typename _Container::iterator iter;
731public:
732 typedef _Container container_type;
733
734 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clow53c0e722014-03-03 19:20:40 +0000735 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000736 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
737 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000738#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000739 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
740 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000741#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
743 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
744 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
745};
746
747template <class _Container>
748inline _LIBCPP_INLINE_VISIBILITY
749insert_iterator<_Container>
750inserter(_Container& __x, typename _Container::iterator __i)
751{
752 return insert_iterator<_Container>(__x, __i);
753}
754
755template <class _Tp, class _CharT = char,
756 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000757class _LIBCPP_TYPE_VIS_ONLY istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
759{
760public:
761 typedef _CharT char_type;
762 typedef _Traits traits_type;
763 typedef basic_istream<_CharT,_Traits> istream_type;
764private:
765 istream_type* __in_stream_;
766 _Tp __value_;
767public:
Marshall Clowe9d03062015-04-16 21:36:54 +0000768 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700769 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770 {
771 if (!(*__in_stream_ >> __value_))
772 __in_stream_ = 0;
773 }
774
775 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700776 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
778 {
779 if (!(*__in_stream_ >> __value_))
780 __in_stream_ = 0;
781 return *this;
782 }
783 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
784 {istream_iterator __t(*this); ++(*this); return __t;}
785
786 friend _LIBCPP_INLINE_VISIBILITY
787 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
788 {return __x.__in_stream_ == __y.__in_stream_;}
789
790 friend _LIBCPP_INLINE_VISIBILITY
791 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
792 {return !(__x == __y);}
793};
794
795template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000796class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000797 : public iterator<output_iterator_tag, void, void, void, void>
798{
799public:
800 typedef _CharT char_type;
801 typedef _Traits traits_type;
802 typedef basic_ostream<_CharT,_Traits> ostream_type;
803private:
804 ostream_type* __out_stream_;
805 const char_type* __delim_;
806public:
807 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700808 : __out_stream_(&__s), __delim_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700810 : __out_stream_(&__s), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000811 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000813 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814 if (__delim_)
815 *__out_stream_ << __delim_;
816 return *this;
817 }
818
819 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
820 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
821 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
822};
823
824template<class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000825class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826 : public iterator<input_iterator_tag, _CharT,
827 typename _Traits::off_type, _CharT*,
828 _CharT>
829{
830public:
831 typedef _CharT char_type;
832 typedef _Traits traits_type;
833 typedef typename _Traits::int_type int_type;
834 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
835 typedef basic_istream<_CharT,_Traits> istream_type;
836private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000837 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838
839 class __proxy
840 {
841 char_type __keep_;
842 streambuf_type* __sbuf_;
843 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
844 : __keep_(__c), __sbuf_(__s) {}
845 friend class istreambuf_iterator;
846 public:
847 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
848 };
849
Howard Hinnant82894812010-09-22 16:48:34 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000851 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852 {
853 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
854 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000855 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856 }
857public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000858 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000859 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000860 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000861 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000862 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000863 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864 : __sbuf_(__p.__sbuf_) {}
865
Howard Hinnantec3773c2011-12-01 20:21:04 +0000866 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
867 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
869 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
870 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000871 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000872 return *this;
873 }
874 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
875 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000876 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877 }
878
879 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000880 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881};
882
883template <class _CharT, class _Traits>
884inline _LIBCPP_INLINE_VISIBILITY
885bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
886 const istreambuf_iterator<_CharT,_Traits>& __b)
887 {return __a.equal(__b);}
888
889template <class _CharT, class _Traits>
890inline _LIBCPP_INLINE_VISIBILITY
891bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
892 const istreambuf_iterator<_CharT,_Traits>& __b)
893 {return !__a.equal(__b);}
894
895template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000896class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 : public iterator<output_iterator_tag, void, void, void, void>
898{
899public:
900 typedef _CharT char_type;
901 typedef _Traits traits_type;
902 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
903 typedef basic_ostream<_CharT,_Traits> ostream_type;
904private:
905 streambuf_type* __sbuf_;
906public:
Howard Hinnantd06a6402012-07-20 19:36:34 +0000907 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000909 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000910 : __sbuf_(__s) {}
911 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
912 {
913 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
914 __sbuf_ = 0;
915 return *this;
916 }
917 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
918 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
919 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000920 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +0000921
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000922#if !defined(__APPLE__) || \
923 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
924 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
925
Howard Hinnanta585de62012-09-19 19:14:15 +0000926 template <class _Ch, class _Tr>
927 friend
928 _LIBCPP_HIDDEN
929 ostreambuf_iterator<_Ch, _Tr>
930 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
931 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
932 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000933#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934};
935
936template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000937class _LIBCPP_TYPE_VIS_ONLY move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938{
939private:
940 _Iter __i;
941public:
942 typedef _Iter iterator_type;
943 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
944 typedef typename iterator_traits<iterator_type>::value_type value_type;
945 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700946 typedef typename iterator_traits<iterator_type>::pointer pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000947#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700948 typedef value_type&& reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949#else
950 typedef typename iterator_traits<iterator_type>::reference reference;
951#endif
Howard Hinnant324bb032010-08-22 00:02:43 +0000952
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000953 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
954 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
955 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
956 : __i(__u.base()) {}
957 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +0000958 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
959 return static_cast<reference>(*__i);
960 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700961 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
962 typename iterator_traits<iterator_type>::reference __ref = *__i;
963 return &__ref;
964 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
966 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
967 {move_iterator __tmp(*this); ++__i; return __tmp;}
968 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
969 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
970 {move_iterator __tmp(*this); --__i; return __tmp;}
971 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
972 {return move_iterator(__i + __n);}
973 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
974 {__i += __n; return *this;}
975 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
976 {return move_iterator(__i - __n);}
977 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
978 {__i -= __n; return *this;}
979 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +0000980 {
981 return static_cast<reference>(__i[__n]);
982 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983};
984
985template <class _Iter1, class _Iter2>
986inline _LIBCPP_INLINE_VISIBILITY
987bool
988operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
989{
990 return __x.base() == __y.base();
991}
992
993template <class _Iter1, class _Iter2>
994inline _LIBCPP_INLINE_VISIBILITY
995bool
996operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
997{
998 return __x.base() < __y.base();
999}
1000
1001template <class _Iter1, class _Iter2>
1002inline _LIBCPP_INLINE_VISIBILITY
1003bool
1004operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1005{
1006 return __x.base() != __y.base();
1007}
1008
1009template <class _Iter1, class _Iter2>
1010inline _LIBCPP_INLINE_VISIBILITY
1011bool
1012operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1013{
1014 return __x.base() > __y.base();
1015}
1016
1017template <class _Iter1, class _Iter2>
1018inline _LIBCPP_INLINE_VISIBILITY
1019bool
1020operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1021{
1022 return __x.base() >= __y.base();
1023}
1024
1025template <class _Iter1, class _Iter2>
1026inline _LIBCPP_INLINE_VISIBILITY
1027bool
1028operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1029{
1030 return __x.base() <= __y.base();
1031}
1032
1033template <class _Iter1, class _Iter2>
1034inline _LIBCPP_INLINE_VISIBILITY
1035typename move_iterator<_Iter1>::difference_type
1036operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1037{
1038 return __x.base() - __y.base();
1039}
1040
1041template <class _Iter>
1042inline _LIBCPP_INLINE_VISIBILITY
1043move_iterator<_Iter>
1044operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1045{
1046 return move_iterator<_Iter>(__x.base() + __n);
1047}
1048
1049template <class _Iter>
1050inline _LIBCPP_INLINE_VISIBILITY
1051move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:03 +00001052make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053{
1054 return move_iterator<_Iter>(__i);
1055}
1056
1057// __wrap_iter
1058
1059template <class _Iter> class __wrap_iter;
1060
1061template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001062_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001064operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065
1066template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001067_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001068bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001069operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070
1071template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001072_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001074operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075
1076template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001077_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001079operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080
1081template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001082_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001084operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085
1086template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001087_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001089operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090
1091template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001092_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001093typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001094operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095
1096template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001097_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001099operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100
Howard Hinnant33be35e2012-09-14 00:39:16 +00001101template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1102template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1103template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1104template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105
1106template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001107_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001108typename enable_if
1109<
Howard Hinnant1468b662010-11-19 22:17:28 +00001110 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001111 _Tp*
1112>::type
1113__unwrap_iter(__wrap_iter<_Tp*>);
1114
Dan Albert99ca8202015-03-04 14:08:24 -08001115template <class _Tp, class _Alloc> class _LIBCPP_TYPE_VIS_ONLY vector;
1116
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117template <class _Iter>
1118class __wrap_iter
1119{
1120public:
1121 typedef _Iter iterator_type;
1122 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1123 typedef typename iterator_traits<iterator_type>::value_type value_type;
1124 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1125 typedef typename iterator_traits<iterator_type>::pointer pointer;
1126 typedef typename iterator_traits<iterator_type>::reference reference;
1127private:
1128 iterator_type __i;
1129public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001130 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001131#if _LIBCPP_STD_VER > 11
1132 : __i{}
1133#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001134 {
1135#if _LIBCPP_DEBUG_LEVEL >= 2
1136 __get_db()->__insert_i(this);
1137#endif
1138 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001140 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001141 : __i(__u.base())
1142 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001143#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001144 __get_db()->__iterator_copy(this, &__u);
1145#endif
1146 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001147#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001148 _LIBCPP_INLINE_VISIBILITY
1149 __wrap_iter(const __wrap_iter& __x)
1150 : __i(__x.base())
1151 {
1152 __get_db()->__iterator_copy(this, &__x);
1153 }
1154 _LIBCPP_INLINE_VISIBILITY
1155 __wrap_iter& operator=(const __wrap_iter& __x)
1156 {
1157 if (this != &__x)
1158 {
1159 __get_db()->__iterator_copy(this, &__x);
1160 __i = __x.__i;
1161 }
1162 return *this;
1163 }
1164 _LIBCPP_INLINE_VISIBILITY
1165 ~__wrap_iter()
1166 {
1167 __get_db()->__erase_i(this);
1168 }
1169#endif
1170 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1171 {
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()->__dereferenceable(this),
1174 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001175#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001176 return *__i;
1177 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001178 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1179 {
1180#if _LIBCPP_DEBUG_LEVEL >= 2
1181 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1182 "Attempted to dereference a non-dereferenceable iterator");
1183#endif
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001184 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001185 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001186 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1187 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001188#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001189 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1190 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001191#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001192 ++__i;
1193 return *this;
1194 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001195 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001196 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1197 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1198 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001199#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001200 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1201 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001202#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001203 --__i;
1204 return *this;
1205 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001206 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001207 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001208 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001209 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001210 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001211 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001212#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001213 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1214 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001215#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001216 __i += __n;
1217 return *this;
1218 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001219 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001220 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001221 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001222 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001223 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001224 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001225#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001226 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1227 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001228#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001229 return __i[__n];
1230 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001231
Howard Hinnanta6119a82011-05-29 19:57:12 +00001232 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233
1234private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001235#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001236 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1237 {
1238 __get_db()->__insert_ic(this, __p);
1239 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001240#else
1241 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001242#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243
1244 template <class _Up> friend class __wrap_iter;
1245 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Dan Albert99ca8202015-03-04 14:08:24 -08001246 template <class _Tp, class _Alloc> friend class vector;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001247
1248 template <class _Iter1, class _Iter2>
1249 friend
1250 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001251 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001252
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001253 template <class _Iter1, class _Iter2>
1254 friend
1255 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001256 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001257
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258 template <class _Iter1, class _Iter2>
1259 friend
1260 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001261 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001262
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263 template <class _Iter1, class _Iter2>
1264 friend
1265 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001266 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001267
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268 template <class _Iter1, class _Iter2>
1269 friend
1270 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001271 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001272
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273 template <class _Iter1, class _Iter2>
1274 friend
1275 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001276 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001277
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278 template <class _Iter1, class _Iter2>
1279 friend
1280 typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001281 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001282
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283 template <class _Iter1>
1284 friend
1285 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001286 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287
Howard Hinnant99968442011-11-29 18:15:50 +00001288 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001290 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001291 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1292
1293 template <class _Tp>
1294 friend
1295 typename enable_if
1296 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001297 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298 _Tp*
1299 >::type
1300 __unwrap_iter(__wrap_iter<_Tp*>);
1301};
1302
1303template <class _Iter1, class _Iter2>
1304inline _LIBCPP_INLINE_VISIBILITY
1305bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001306operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307{
1308 return __x.base() == __y.base();
1309}
1310
1311template <class _Iter1, class _Iter2>
1312inline _LIBCPP_INLINE_VISIBILITY
1313bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001314operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001315{
Howard Hinnantabe26282011-09-16 17:29:17 +00001316#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001317 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001318 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001319#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320 return __x.base() < __y.base();
1321}
1322
1323template <class _Iter1, class _Iter2>
1324inline _LIBCPP_INLINE_VISIBILITY
1325bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001326operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001328 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001329}
1330
1331template <class _Iter1, class _Iter2>
1332inline _LIBCPP_INLINE_VISIBILITY
1333bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001334operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001336 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337}
1338
1339template <class _Iter1, class _Iter2>
1340inline _LIBCPP_INLINE_VISIBILITY
1341bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001342operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001344 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345}
1346
1347template <class _Iter1, class _Iter2>
1348inline _LIBCPP_INLINE_VISIBILITY
1349bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001350operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001352 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353}
1354
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001355template <class _Iter1>
1356inline _LIBCPP_INLINE_VISIBILITY
1357bool
1358operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1359{
1360 return !(__x == __y);
1361}
1362
1363template <class _Iter1>
1364inline _LIBCPP_INLINE_VISIBILITY
1365bool
1366operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1367{
1368 return __y < __x;
1369}
1370
1371template <class _Iter1>
1372inline _LIBCPP_INLINE_VISIBILITY
1373bool
1374operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1375{
1376 return !(__x < __y);
1377}
1378
1379template <class _Iter1>
1380inline _LIBCPP_INLINE_VISIBILITY
1381bool
1382operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1383{
1384 return !(__y < __x);
1385}
1386
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387template <class _Iter1, class _Iter2>
1388inline _LIBCPP_INLINE_VISIBILITY
1389typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001390operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391{
Howard Hinnantabe26282011-09-16 17:29:17 +00001392#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001393 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001394 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001395#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396 return __x.base() - __y.base();
1397}
1398
1399template <class _Iter>
1400inline _LIBCPP_INLINE_VISIBILITY
1401__wrap_iter<_Iter>
1402operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001403 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001405 __x += __n;
1406 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001407}
1408
Marshall Clow6daf5342013-12-02 03:24:33 +00001409template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001410inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001411_Tp*
1412begin(_Tp (&__array)[_Np])
1413{
1414 return __array;
1415}
1416
1417template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001418inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001419_Tp*
1420end(_Tp (&__array)[_Np])
1421{
1422 return __array + _Np;
1423}
1424
Marshall Clow1c398692013-12-11 19:32:32 +00001425#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1426
Howard Hinnant99968442011-11-29 18:15:50 +00001427template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001428inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001429auto
Howard Hinnant99968442011-11-29 18:15:50 +00001430begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431{
1432 return __c.begin();
1433}
1434
Howard Hinnant99968442011-11-29 18:15:50 +00001435template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001436inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437auto
Howard Hinnant99968442011-11-29 18:15:50 +00001438begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439{
1440 return __c.begin();
1441}
1442
Howard Hinnant99968442011-11-29 18:15:50 +00001443template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001444inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001445auto
Howard Hinnant99968442011-11-29 18:15:50 +00001446end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447{
1448 return __c.end();
1449}
1450
Howard Hinnant99968442011-11-29 18:15:50 +00001451template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001452inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453auto
Howard Hinnant99968442011-11-29 18:15:50 +00001454end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455{
1456 return __c.end();
1457}
1458
Marshall Clow09da3c02013-08-30 01:17:07 +00001459#if _LIBCPP_STD_VER > 11
1460
Marshall Clow6daf5342013-12-02 03:24:33 +00001461template <class _Tp, size_t _Np>
1462inline _LIBCPP_INLINE_VISIBILITY
1463reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1464{
1465 return reverse_iterator<_Tp*>(__array + _Np);
1466}
1467
1468template <class _Tp, size_t _Np>
1469inline _LIBCPP_INLINE_VISIBILITY
1470reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1471{
1472 return reverse_iterator<_Tp*>(__array);
1473}
1474
1475template <class _Ep>
1476inline _LIBCPP_INLINE_VISIBILITY
1477reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1478{
1479 return reverse_iterator<const _Ep*>(__il.end());
1480}
1481
1482template <class _Ep>
1483inline _LIBCPP_INLINE_VISIBILITY
1484reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1485{
1486 return reverse_iterator<const _Ep*>(__il.begin());
1487}
1488
Marshall Clow09da3c02013-08-30 01:17:07 +00001489template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001490inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001491auto cbegin(const _Cp& __c) -> decltype(begin(__c))
1492{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001493 return begin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001494}
1495
1496template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001497inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001498auto cend(const _Cp& __c) -> decltype(end(__c))
1499{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001500 return end(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001501}
1502
1503template <class _Cp>
1504inline _LIBCPP_INLINE_VISIBILITY
1505auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1506{
1507 return __c.rbegin();
1508}
1509
1510template <class _Cp>
1511inline _LIBCPP_INLINE_VISIBILITY
1512auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1513{
1514 return __c.rbegin();
1515}
1516
1517template <class _Cp>
1518inline _LIBCPP_INLINE_VISIBILITY
1519auto rend(_Cp& __c) -> decltype(__c.rend())
1520{
1521 return __c.rend();
1522}
1523
1524template <class _Cp>
1525inline _LIBCPP_INLINE_VISIBILITY
1526auto rend(const _Cp& __c) -> decltype(__c.rend())
1527{
1528 return __c.rend();
1529}
1530
1531template <class _Cp>
1532inline _LIBCPP_INLINE_VISIBILITY
1533auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
1534{
1535 return rbegin(__c);
1536}
1537
1538template <class _Cp>
1539inline _LIBCPP_INLINE_VISIBILITY
1540auto crend(const _Cp& __c) -> decltype(rend(__c))
1541{
1542 return rend(__c);
1543}
1544
1545#endif
1546
1547
Howard Hinnant726a76f2010-11-16 21:10:23 +00001548#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001549
Howard Hinnant99968442011-11-29 18:15:50 +00001550template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001551inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001552typename _Cp::iterator
1553begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554{
1555 return __c.begin();
1556}
1557
Howard Hinnant99968442011-11-29 18:15:50 +00001558template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001559inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001560typename _Cp::const_iterator
1561begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001562{
1563 return __c.begin();
1564}
1565
Howard Hinnant99968442011-11-29 18:15:50 +00001566template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001567inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001568typename _Cp::iterator
1569end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001570{
1571 return __c.end();
1572}
1573
Howard Hinnant99968442011-11-29 18:15:50 +00001574template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001575inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001576typename _Cp::const_iterator
1577end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578{
1579 return __c.end();
1580}
1581
Howard Hinnant726a76f2010-11-16 21:10:23 +00001582#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583
Marshall Clow03c67912014-11-19 19:43:23 +00001584#if _LIBCPP_STD_VER > 14
Marshall Clow35e462d2015-02-11 16:14:01 +00001585template <class _Cont>
1586constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001587
Marshall Clow35e462d2015-02-11 16:14:01 +00001588template <class _Tp, size_t _Sz>
1589constexpr size_t size(const _Tp (&__array)[_Sz]) noexcept { return _Sz; }
Marshall Clow03c67912014-11-19 19:43:23 +00001590
Marshall Clow35e462d2015-02-11 16:14:01 +00001591template <class _Cont>
1592constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001593
Marshall Clow35e462d2015-02-11 16:14:01 +00001594template <class _Tp, size_t _Sz>
1595constexpr bool empty(const _Tp (&__array)[_Sz]) noexcept { return false; }
Marshall Clow03c67912014-11-19 19:43:23 +00001596
1597template <class _Ep>
1598constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1599
Marshall Clow35e462d2015-02-11 16:14:01 +00001600template <class _Cont> constexpr
1601auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001602
Marshall Clow35e462d2015-02-11 16:14:01 +00001603template <class _Cont> constexpr
1604auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001605
Marshall Clow35e462d2015-02-11 16:14:01 +00001606template <class _Tp, size_t _Sz>
1607constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clow03c67912014-11-19 19:43:23 +00001608
1609template <class _Ep>
1610constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1611#endif
1612
1613
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614_LIBCPP_END_NAMESPACE_STD
1615
1616#endif // _LIBCPP_ITERATOR