blob: 8d9b31101bdf95687e5e4b9264d9853345cdb889 [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>
346#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
Marshall Clowdf9db312016-01-13 21:54:34 +0000440template <class _Tp>
441struct __is_exactly_input_iterator
442 : public integral_constant<bool,
443 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
444 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
445
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446template<class _Category, class _Tp, class _Distance = ptrdiff_t,
447 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000448struct _LIBCPP_TYPE_VIS_ONLY iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449{
450 typedef _Tp value_type;
451 typedef _Distance difference_type;
452 typedef _Pointer pointer;
453 typedef _Reference reference;
454 typedef _Category iterator_category;
455};
456
457template <class _InputIter>
458inline _LIBCPP_INLINE_VISIBILITY
459void __advance(_InputIter& __i,
460 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
461{
462 for (; __n > 0; --__n)
463 ++__i;
464}
465
466template <class _BiDirIter>
467inline _LIBCPP_INLINE_VISIBILITY
468void __advance(_BiDirIter& __i,
469 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
470{
471 if (__n >= 0)
472 for (; __n > 0; --__n)
473 ++__i;
474 else
475 for (; __n < 0; ++__n)
476 --__i;
477}
478
479template <class _RandIter>
480inline _LIBCPP_INLINE_VISIBILITY
481void __advance(_RandIter& __i,
482 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
483{
484 __i += __n;
485}
486
487template <class _InputIter>
488inline _LIBCPP_INLINE_VISIBILITY
489void advance(_InputIter& __i,
490 typename iterator_traits<_InputIter>::difference_type __n)
491{
492 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
493}
494
495template <class _InputIter>
496inline _LIBCPP_INLINE_VISIBILITY
497typename iterator_traits<_InputIter>::difference_type
498__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
499{
500 typename iterator_traits<_InputIter>::difference_type __r(0);
501 for (; __first != __last; ++__first)
502 ++__r;
503 return __r;
504}
505
506template <class _RandIter>
507inline _LIBCPP_INLINE_VISIBILITY
508typename iterator_traits<_RandIter>::difference_type
509__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
510{
511 return __last - __first;
512}
513
514template <class _InputIter>
515inline _LIBCPP_INLINE_VISIBILITY
516typename iterator_traits<_InputIter>::difference_type
517distance(_InputIter __first, _InputIter __last)
518{
519 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
520}
521
Marshall Clowe9ef9882015-11-07 17:48:49 +0000522template <class _InputIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000523inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe9ef9882015-11-07 17:48:49 +0000524_InputIter
525next(_InputIter __x,
526 typename iterator_traits<_InputIter>::difference_type __n = 1,
527 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000529 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 return __x;
531}
532
533template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000534inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535_BidiretionalIter
536prev(_BidiretionalIter __x,
537 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
538 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
539{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000540 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541 return __x;
542}
543
544template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000545class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546 : public iterator<typename iterator_traits<_Iter>::iterator_category,
547 typename iterator_traits<_Iter>::value_type,
548 typename iterator_traits<_Iter>::difference_type,
549 typename iterator_traits<_Iter>::pointer,
550 typename iterator_traits<_Iter>::reference>
551{
Marshall Clow668a1d82014-03-11 22:05:31 +0000552private:
553 mutable _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000554protected:
555 _Iter current;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556public:
557 typedef _Iter iterator_type;
558 typedef typename iterator_traits<_Iter>::difference_type difference_type;
559 typedef typename iterator_traits<_Iter>::reference reference;
560 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000561
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000562 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
563 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000565 : __t(__u.base()), current(__u.base()) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
Marshall Clowb1ead682014-03-11 17:16:17 +0000567 _LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;}
Marshall Clow02ca8af2014-02-27 02:11:50 +0000568 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000569 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
570 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
571 {reverse_iterator __tmp(*this); --current; return __tmp;}
572 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
573 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
574 {reverse_iterator __tmp(*this); ++current; return __tmp;}
575 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
576 {return reverse_iterator(current - __n);}
577 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
578 {current -= __n; return *this;}
579 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
580 {return reverse_iterator(current + __n);}
581 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
582 {current += __n; return *this;}
583 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Marshall Clowad98e212015-03-05 16:07:37 +0000584 {return *(*this + __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585};
586
587template <class _Iter1, class _Iter2>
588inline _LIBCPP_INLINE_VISIBILITY
589bool
590operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
591{
592 return __x.base() == __y.base();
593}
594
595template <class _Iter1, class _Iter2>
596inline _LIBCPP_INLINE_VISIBILITY
597bool
598operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
599{
600 return __x.base() > __y.base();
601}
602
603template <class _Iter1, class _Iter2>
604inline _LIBCPP_INLINE_VISIBILITY
605bool
606operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
607{
608 return __x.base() != __y.base();
609}
610
611template <class _Iter1, class _Iter2>
612inline _LIBCPP_INLINE_VISIBILITY
613bool
614operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
615{
616 return __x.base() < __y.base();
617}
618
619template <class _Iter1, class _Iter2>
620inline _LIBCPP_INLINE_VISIBILITY
621bool
622operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
623{
624 return __x.base() <= __y.base();
625}
626
627template <class _Iter1, class _Iter2>
628inline _LIBCPP_INLINE_VISIBILITY
629bool
630operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
631{
632 return __x.base() >= __y.base();
633}
634
635template <class _Iter1, class _Iter2>
636inline _LIBCPP_INLINE_VISIBILITY
637typename reverse_iterator<_Iter1>::difference_type
638operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
639{
640 return __y.base() - __x.base();
641}
642
643template <class _Iter>
644inline _LIBCPP_INLINE_VISIBILITY
645reverse_iterator<_Iter>
646operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
647{
648 return reverse_iterator<_Iter>(__x.base() - __n);
649}
650
Marshall Clowff137e92014-03-03 01:24:04 +0000651#if _LIBCPP_STD_VER > 11
652template <class _Iter>
653inline _LIBCPP_INLINE_VISIBILITY
654reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
655{
656 return reverse_iterator<_Iter>(__i);
657}
658#endif
659
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000661class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662 : public iterator<output_iterator_tag,
663 void,
664 void,
665 void,
666 back_insert_iterator<_Container>&>
667{
668protected:
669 _Container* container;
670public:
671 typedef _Container container_type;
672
Marshall Clow53c0e722014-03-03 19:20:40 +0000673 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000674 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
675 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000676#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000677 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
678 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000679#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
681 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
682 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
683};
684
685template <class _Container>
686inline _LIBCPP_INLINE_VISIBILITY
687back_insert_iterator<_Container>
688back_inserter(_Container& __x)
689{
690 return back_insert_iterator<_Container>(__x);
691}
692
693template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000694class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 : public iterator<output_iterator_tag,
696 void,
697 void,
698 void,
699 front_insert_iterator<_Container>&>
700{
701protected:
702 _Container* container;
703public:
704 typedef _Container container_type;
705
Marshall Clow53c0e722014-03-03 19:20:40 +0000706 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000707 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
708 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000709#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000710 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
711 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000712#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
714 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
715 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
716};
717
718template <class _Container>
719inline _LIBCPP_INLINE_VISIBILITY
720front_insert_iterator<_Container>
721front_inserter(_Container& __x)
722{
723 return front_insert_iterator<_Container>(__x);
724}
725
726template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000727class _LIBCPP_TYPE_VIS_ONLY insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728 : public iterator<output_iterator_tag,
729 void,
730 void,
731 void,
732 insert_iterator<_Container>&>
733{
734protected:
735 _Container* container;
736 typename _Container::iterator iter;
737public:
738 typedef _Container container_type;
739
740 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clow53c0e722014-03-03 19:20:40 +0000741 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000742 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
743 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000744#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000745 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
746 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000747#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000748 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
749 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
750 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
751};
752
753template <class _Container>
754inline _LIBCPP_INLINE_VISIBILITY
755insert_iterator<_Container>
756inserter(_Container& __x, typename _Container::iterator __i)
757{
758 return insert_iterator<_Container>(__x, __i);
759}
760
761template <class _Tp, class _CharT = char,
762 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000763class _LIBCPP_TYPE_VIS_ONLY istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000764 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
765{
766public:
767 typedef _CharT char_type;
768 typedef _Traits traits_type;
769 typedef basic_istream<_CharT,_Traits> istream_type;
770private:
771 istream_type* __in_stream_;
772 _Tp __value_;
773public:
Marshall Clowe9d03062015-04-16 21:36:54 +0000774 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s)
776 {
777 if (!(*__in_stream_ >> __value_))
778 __in_stream_ = 0;
779 }
780
781 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
782 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());}
783 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
784 {
785 if (!(*__in_stream_ >> __value_))
786 __in_stream_ = 0;
787 return *this;
788 }
789 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
790 {istream_iterator __t(*this); ++(*this); return __t;}
791
792 friend _LIBCPP_INLINE_VISIBILITY
793 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
794 {return __x.__in_stream_ == __y.__in_stream_;}
795
796 friend _LIBCPP_INLINE_VISIBILITY
797 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
798 {return !(__x == __y);}
799};
800
801template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000802class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 : public iterator<output_iterator_tag, void, void, void, void>
804{
805public:
806 typedef _CharT char_type;
807 typedef _Traits traits_type;
808 typedef basic_ostream<_CharT,_Traits> ostream_type;
809private:
810 ostream_type* __out_stream_;
811 const char_type* __delim_;
812public:
813 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
814 : __out_stream_(&__s), __delim_(0) {}
815 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
816 : __out_stream_(&__s), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000817 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000819 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820 if (__delim_)
821 *__out_stream_ << __delim_;
822 return *this;
823 }
824
825 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
826 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
827 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
828};
829
830template<class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000831class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000832 : public iterator<input_iterator_tag, _CharT,
833 typename _Traits::off_type, _CharT*,
834 _CharT>
835{
836public:
837 typedef _CharT char_type;
838 typedef _Traits traits_type;
839 typedef typename _Traits::int_type int_type;
840 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
841 typedef basic_istream<_CharT,_Traits> istream_type;
842private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000843 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000844
845 class __proxy
846 {
847 char_type __keep_;
848 streambuf_type* __sbuf_;
849 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
850 : __keep_(__c), __sbuf_(__s) {}
851 friend class istreambuf_iterator;
852 public:
853 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
854 };
855
Howard Hinnant82894812010-09-22 16:48:34 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000857 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 {
859 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
860 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000861 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 }
863public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000864 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000865 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000866 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000867 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000868 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000869 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870 : __sbuf_(__p.__sbuf_) {}
871
Howard Hinnantec3773c2011-12-01 20:21:04 +0000872 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
873 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
875 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
876 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000877 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878 return *this;
879 }
880 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
881 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000882 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883 }
884
885 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000886 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000887};
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>
896inline _LIBCPP_INLINE_VISIBILITY
897bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
898 const istreambuf_iterator<_CharT,_Traits>& __b)
899 {return !__a.equal(__b);}
900
901template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000902class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 : public iterator<output_iterator_tag, void, void, void, void>
904{
905public:
906 typedef _CharT char_type;
907 typedef _Traits traits_type;
908 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
909 typedef basic_ostream<_CharT,_Traits> ostream_type;
910private:
911 streambuf_type* __sbuf_;
912public:
Howard Hinnantd06a6402012-07-20 19:36:34 +0000913 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000915 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916 : __sbuf_(__s) {}
917 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
918 {
919 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
920 __sbuf_ = 0;
921 return *this;
922 }
923 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
924 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
925 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000926 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +0000927
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000928#if !defined(__APPLE__) || \
929 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
930 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
931
Howard Hinnanta585de62012-09-19 19:14:15 +0000932 template <class _Ch, class _Tr>
933 friend
934 _LIBCPP_HIDDEN
935 ostreambuf_iterator<_Ch, _Tr>
936 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
937 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
938 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000939#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000940};
941
942template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000943class _LIBCPP_TYPE_VIS_ONLY move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000944{
945private:
946 _Iter __i;
947public:
948 typedef _Iter iterator_type;
949 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
950 typedef typename iterator_traits<iterator_type>::value_type value_type;
951 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
952 typedef typename iterator_traits<iterator_type>::pointer pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000953#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954 typedef value_type&& reference;
955#else
956 typedef typename iterator_traits<iterator_type>::reference reference;
957#endif
Howard Hinnant324bb032010-08-22 00:02:43 +0000958
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000959 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
960 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
961 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
962 : __i(__u.base()) {}
963 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +0000964 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
965 return static_cast<reference>(*__i);
966 }
967 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {
968 typename iterator_traits<iterator_type>::reference __ref = *__i;
969 return &__ref;
970 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
972 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
973 {move_iterator __tmp(*this); ++__i; return __tmp;}
974 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
975 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
976 {move_iterator __tmp(*this); --__i; return __tmp;}
977 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
978 {return move_iterator(__i + __n);}
979 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
980 {__i += __n; return *this;}
981 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
982 {return move_iterator(__i - __n);}
983 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
984 {__i -= __n; return *this;}
985 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +0000986 {
987 return static_cast<reference>(__i[__n]);
988 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989};
990
991template <class _Iter1, class _Iter2>
992inline _LIBCPP_INLINE_VISIBILITY
993bool
994operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
995{
996 return __x.base() == __y.base();
997}
998
999template <class _Iter1, class _Iter2>
1000inline _LIBCPP_INLINE_VISIBILITY
1001bool
1002operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1003{
1004 return __x.base() < __y.base();
1005}
1006
1007template <class _Iter1, class _Iter2>
1008inline _LIBCPP_INLINE_VISIBILITY
1009bool
1010operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1011{
1012 return __x.base() != __y.base();
1013}
1014
1015template <class _Iter1, class _Iter2>
1016inline _LIBCPP_INLINE_VISIBILITY
1017bool
1018operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1019{
1020 return __x.base() > __y.base();
1021}
1022
1023template <class _Iter1, class _Iter2>
1024inline _LIBCPP_INLINE_VISIBILITY
1025bool
1026operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1027{
1028 return __x.base() >= __y.base();
1029}
1030
1031template <class _Iter1, class _Iter2>
1032inline _LIBCPP_INLINE_VISIBILITY
1033bool
1034operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1035{
1036 return __x.base() <= __y.base();
1037}
1038
1039template <class _Iter1, class _Iter2>
1040inline _LIBCPP_INLINE_VISIBILITY
1041typename move_iterator<_Iter1>::difference_type
1042operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1043{
1044 return __x.base() - __y.base();
1045}
1046
1047template <class _Iter>
1048inline _LIBCPP_INLINE_VISIBILITY
1049move_iterator<_Iter>
1050operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1051{
1052 return move_iterator<_Iter>(__x.base() + __n);
1053}
1054
1055template <class _Iter>
1056inline _LIBCPP_INLINE_VISIBILITY
1057move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:03 +00001058make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059{
1060 return move_iterator<_Iter>(__i);
1061}
1062
1063// __wrap_iter
1064
1065template <class _Iter> class __wrap_iter;
1066
1067template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001068_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001070operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001071
1072template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001073_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001075operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076
1077template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001078_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001080operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081
1082template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001083_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001084bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001085operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086
1087template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001088_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001090operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091
1092template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001093_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001095operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096
1097template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001098_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001100operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101
1102template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001103_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001105operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106
Howard Hinnant33be35e2012-09-14 00:39:16 +00001107template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1108template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1109template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1110template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001111
1112template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001113_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114typename enable_if
1115<
Howard Hinnant1468b662010-11-19 22:17:28 +00001116 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117 _Tp*
1118>::type
1119__unwrap_iter(__wrap_iter<_Tp*>);
1120
1121template <class _Iter>
1122class __wrap_iter
1123{
1124public:
1125 typedef _Iter iterator_type;
1126 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1127 typedef typename iterator_traits<iterator_type>::value_type value_type;
1128 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1129 typedef typename iterator_traits<iterator_type>::pointer pointer;
1130 typedef typename iterator_traits<iterator_type>::reference reference;
1131private:
1132 iterator_type __i;
1133public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001134 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001135#if _LIBCPP_STD_VER > 11
1136 : __i{}
1137#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001138 {
1139#if _LIBCPP_DEBUG_LEVEL >= 2
1140 __get_db()->__insert_i(this);
1141#endif
1142 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001144 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001145 : __i(__u.base())
1146 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001147#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001148 __get_db()->__iterator_copy(this, &__u);
1149#endif
1150 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001151#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001152 _LIBCPP_INLINE_VISIBILITY
1153 __wrap_iter(const __wrap_iter& __x)
1154 : __i(__x.base())
1155 {
1156 __get_db()->__iterator_copy(this, &__x);
1157 }
1158 _LIBCPP_INLINE_VISIBILITY
1159 __wrap_iter& operator=(const __wrap_iter& __x)
1160 {
1161 if (this != &__x)
1162 {
1163 __get_db()->__iterator_copy(this, &__x);
1164 __i = __x.__i;
1165 }
1166 return *this;
1167 }
1168 _LIBCPP_INLINE_VISIBILITY
1169 ~__wrap_iter()
1170 {
1171 __get_db()->__erase_i(this);
1172 }
1173#endif
1174 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1175 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001176#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001177 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1178 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001179#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001180 return *__i;
1181 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001182 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1183 {
1184#if _LIBCPP_DEBUG_LEVEL >= 2
1185 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1186 "Attempted to dereference a non-dereferenceable iterator");
1187#endif
1188 return (pointer)&reinterpret_cast<const volatile char&>(*__i);
1189 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001190 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1191 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001192#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001193 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1194 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001195#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001196 ++__i;
1197 return *this;
1198 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001199 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001200 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1201 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1202 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001203#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001204 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1205 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001206#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001207 --__i;
1208 return *this;
1209 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001210 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001211 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001212 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001213 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001214 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001215 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001216#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001217 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1218 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001219#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001220 __i += __n;
1221 return *this;
1222 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001223 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001224 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001225 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001226 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001227 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001228 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001229#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001230 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1231 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001232#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001233 return __i[__n];
1234 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235
Howard Hinnanta6119a82011-05-29 19:57:12 +00001236 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001237
1238private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001239#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001240 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1241 {
1242 __get_db()->__insert_ic(this, __p);
1243 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001244#else
1245 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001246#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001247
1248 template <class _Up> friend class __wrap_iter;
1249 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Marshall Clow59f573f2015-02-18 19:28:35 +00001250 template <class _Tp, class _Alloc> friend class _LIBCPP_TYPE_VIS_ONLY vector;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001251
1252 template <class _Iter1, class _Iter2>
1253 friend
1254 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001255 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001256
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257 template <class _Iter1, class _Iter2>
1258 friend
1259 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001260 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001261
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262 template <class _Iter1, class _Iter2>
1263 friend
1264 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001265 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001266
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267 template <class _Iter1, class _Iter2>
1268 friend
1269 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001270 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001271
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272 template <class _Iter1, class _Iter2>
1273 friend
1274 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001275 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001276
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277 template <class _Iter1, class _Iter2>
1278 friend
1279 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001280 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001281
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001282 template <class _Iter1, class _Iter2>
1283 friend
1284 typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001285 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001286
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287 template <class _Iter1>
1288 friend
1289 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001290 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001291
Howard Hinnant99968442011-11-29 18:15:50 +00001292 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001293 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001294 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001295 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1296
1297 template <class _Tp>
1298 friend
1299 typename enable_if
1300 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001301 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001302 _Tp*
1303 >::type
1304 __unwrap_iter(__wrap_iter<_Tp*>);
1305};
1306
1307template <class _Iter1, class _Iter2>
1308inline _LIBCPP_INLINE_VISIBILITY
1309bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001310operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001311{
1312 return __x.base() == __y.base();
1313}
1314
1315template <class _Iter1, class _Iter2>
1316inline _LIBCPP_INLINE_VISIBILITY
1317bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001318operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319{
Howard Hinnantabe26282011-09-16 17:29:17 +00001320#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001321 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001322 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001323#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324 return __x.base() < __y.base();
1325}
1326
1327template <class _Iter1, class _Iter2>
1328inline _LIBCPP_INLINE_VISIBILITY
1329bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001330operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001332 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333}
1334
1335template <class _Iter1, class _Iter2>
1336inline _LIBCPP_INLINE_VISIBILITY
1337bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001338operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001339{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001340 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001341}
1342
1343template <class _Iter1, class _Iter2>
1344inline _LIBCPP_INLINE_VISIBILITY
1345bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001346operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001348 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349}
1350
1351template <class _Iter1, class _Iter2>
1352inline _LIBCPP_INLINE_VISIBILITY
1353bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001354operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001355{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001356 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001357}
1358
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001359template <class _Iter1>
1360inline _LIBCPP_INLINE_VISIBILITY
1361bool
1362operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1363{
1364 return !(__x == __y);
1365}
1366
1367template <class _Iter1>
1368inline _LIBCPP_INLINE_VISIBILITY
1369bool
1370operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1371{
1372 return __y < __x;
1373}
1374
1375template <class _Iter1>
1376inline _LIBCPP_INLINE_VISIBILITY
1377bool
1378operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1379{
1380 return !(__x < __y);
1381}
1382
1383template <class _Iter1>
1384inline _LIBCPP_INLINE_VISIBILITY
1385bool
1386operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1387{
1388 return !(__y < __x);
1389}
1390
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391template <class _Iter1, class _Iter2>
1392inline _LIBCPP_INLINE_VISIBILITY
1393typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001394operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001395{
Howard Hinnantabe26282011-09-16 17:29:17 +00001396#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001397 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001398 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001399#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400 return __x.base() - __y.base();
1401}
1402
1403template <class _Iter>
1404inline _LIBCPP_INLINE_VISIBILITY
1405__wrap_iter<_Iter>
1406operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001407 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001409 __x += __n;
1410 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411}
1412
Marshall Clowdf9db312016-01-13 21:54:34 +00001413template <class _Iter>
1414struct __libcpp_is_trivial_iterator
1415 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1416
1417template <class _Iter>
1418struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
1419 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1420
1421template <class _Iter>
1422struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
1423 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1424
1425template <class _Iter>
1426struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
1427 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1428
1429
Marshall Clow6daf5342013-12-02 03:24:33 +00001430template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001431inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001432_Tp*
1433begin(_Tp (&__array)[_Np])
1434{
1435 return __array;
1436}
1437
1438template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001439inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001440_Tp*
1441end(_Tp (&__array)[_Np])
1442{
1443 return __array + _Np;
1444}
1445
Marshall Clow1c398692013-12-11 19:32:32 +00001446#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1447
Howard Hinnant99968442011-11-29 18:15:50 +00001448template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001449inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001450auto
Howard Hinnant99968442011-11-29 18:15:50 +00001451begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452{
1453 return __c.begin();
1454}
1455
Howard Hinnant99968442011-11-29 18:15:50 +00001456template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001457inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458auto
Howard Hinnant99968442011-11-29 18:15:50 +00001459begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001460{
1461 return __c.begin();
1462}
1463
Howard Hinnant99968442011-11-29 18:15:50 +00001464template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001465inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001466auto
Howard Hinnant99968442011-11-29 18:15:50 +00001467end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001468{
1469 return __c.end();
1470}
1471
Howard Hinnant99968442011-11-29 18:15:50 +00001472template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001473inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001474auto
Howard Hinnant99968442011-11-29 18:15:50 +00001475end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001476{
1477 return __c.end();
1478}
1479
Marshall Clow09da3c02013-08-30 01:17:07 +00001480#if _LIBCPP_STD_VER > 11
1481
Marshall Clow6daf5342013-12-02 03:24:33 +00001482template <class _Tp, size_t _Np>
1483inline _LIBCPP_INLINE_VISIBILITY
1484reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1485{
1486 return reverse_iterator<_Tp*>(__array + _Np);
1487}
1488
1489template <class _Tp, size_t _Np>
1490inline _LIBCPP_INLINE_VISIBILITY
1491reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1492{
1493 return reverse_iterator<_Tp*>(__array);
1494}
1495
1496template <class _Ep>
1497inline _LIBCPP_INLINE_VISIBILITY
1498reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1499{
1500 return reverse_iterator<const _Ep*>(__il.end());
1501}
1502
1503template <class _Ep>
1504inline _LIBCPP_INLINE_VISIBILITY
1505reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1506{
1507 return reverse_iterator<const _Ep*>(__il.begin());
1508}
1509
Marshall Clow09da3c02013-08-30 01:17:07 +00001510template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001511inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001512auto cbegin(const _Cp& __c) -> decltype(begin(__c))
1513{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001514 return begin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001515}
1516
1517template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001518inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001519auto cend(const _Cp& __c) -> decltype(end(__c))
1520{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001521 return end(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001522}
1523
1524template <class _Cp>
1525inline _LIBCPP_INLINE_VISIBILITY
1526auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1527{
1528 return __c.rbegin();
1529}
1530
1531template <class _Cp>
1532inline _LIBCPP_INLINE_VISIBILITY
1533auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1534{
1535 return __c.rbegin();
1536}
1537
1538template <class _Cp>
1539inline _LIBCPP_INLINE_VISIBILITY
1540auto rend(_Cp& __c) -> decltype(__c.rend())
1541{
1542 return __c.rend();
1543}
1544
1545template <class _Cp>
1546inline _LIBCPP_INLINE_VISIBILITY
1547auto rend(const _Cp& __c) -> decltype(__c.rend())
1548{
1549 return __c.rend();
1550}
1551
1552template <class _Cp>
1553inline _LIBCPP_INLINE_VISIBILITY
1554auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
1555{
1556 return rbegin(__c);
1557}
1558
1559template <class _Cp>
1560inline _LIBCPP_INLINE_VISIBILITY
1561auto crend(const _Cp& __c) -> decltype(rend(__c))
1562{
1563 return rend(__c);
1564}
1565
1566#endif
1567
1568
Howard Hinnant726a76f2010-11-16 21:10:23 +00001569#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001570
Howard Hinnant99968442011-11-29 18:15:50 +00001571template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001572inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001573typename _Cp::iterator
1574begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001575{
1576 return __c.begin();
1577}
1578
Howard Hinnant99968442011-11-29 18:15:50 +00001579template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001580inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001581typename _Cp::const_iterator
1582begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583{
1584 return __c.begin();
1585}
1586
Howard Hinnant99968442011-11-29 18:15:50 +00001587template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001588inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001589typename _Cp::iterator
1590end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001591{
1592 return __c.end();
1593}
1594
Howard Hinnant99968442011-11-29 18:15:50 +00001595template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001596inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001597typename _Cp::const_iterator
1598end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001599{
1600 return __c.end();
1601}
1602
Howard Hinnant726a76f2010-11-16 21:10:23 +00001603#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604
Marshall Clow03c67912014-11-19 19:43:23 +00001605#if _LIBCPP_STD_VER > 14
Marshall Clow35e462d2015-02-11 16:14:01 +00001606template <class _Cont>
1607constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001608
Marshall Clow35e462d2015-02-11 16:14:01 +00001609template <class _Tp, size_t _Sz>
1610constexpr size_t size(const _Tp (&__array)[_Sz]) noexcept { return _Sz; }
Marshall Clow03c67912014-11-19 19:43:23 +00001611
Marshall Clow35e462d2015-02-11 16:14:01 +00001612template <class _Cont>
1613constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001614
Marshall Clow35e462d2015-02-11 16:14:01 +00001615template <class _Tp, size_t _Sz>
1616constexpr bool empty(const _Tp (&__array)[_Sz]) noexcept { return false; }
Marshall Clow03c67912014-11-19 19:43:23 +00001617
1618template <class _Ep>
1619constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1620
Marshall Clow35e462d2015-02-11 16:14:01 +00001621template <class _Cont> constexpr
1622auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001623
Marshall Clow35e462d2015-02-11 16:14:01 +00001624template <class _Cont> constexpr
1625auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001626
Marshall Clow35e462d2015-02-11 16:14:01 +00001627template <class _Tp, size_t _Sz>
1628constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clow03c67912014-11-19 19:43:23 +00001629
1630template <class _Ep>
1631constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1632#endif
1633
1634
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001635_LIBCPP_END_NAMESPACE_STD
1636
1637#endif // _LIBCPP_ITERATOR