blob: 2e30a922998486a291a64dbc4b0663fcb115e2ce [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>
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000134auto
135operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
136-> decltype(__y.base() - __x.base());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000137
138template <class Iterator>
139reverse_iterator<Iterator>
140operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x);
141
Marshall Clowff137e92014-03-03 01:24:04 +0000142template <class Iterator> reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14
143
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144template <class Container>
145class back_insert_iterator
146{
147protected:
148 Container* container;
149public:
150 typedef Container container_type;
151 typedef void value_type;
152 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50 +0000153 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000154 typedef void pointer;
155
156 explicit back_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000157 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000158 back_insert_iterator& operator*();
159 back_insert_iterator& operator++();
160 back_insert_iterator operator++(int);
161};
162
163template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
164
165template <class Container>
166class front_insert_iterator
167{
168protected:
169 Container* container;
170public:
171 typedef Container container_type;
172 typedef void value_type;
173 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50 +0000174 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000175 typedef void pointer;
176
177 explicit front_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000178 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000179 front_insert_iterator& operator*();
180 front_insert_iterator& operator++();
181 front_insert_iterator operator++(int);
182};
183
184template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
185
186template <class Container>
187class insert_iterator
188{
189protected:
190 Container* container;
191 typename Container::iterator iter;
192public:
193 typedef Container container_type;
194 typedef void value_type;
195 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50 +0000196 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000197 typedef void pointer;
198
199 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant45f57172010-09-14 20:26:27 +0000200 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201 insert_iterator& operator*();
202 insert_iterator& operator++();
203 insert_iterator& operator++(int);
204};
205
206template <class Container, class Iterator>
207insert_iterator<Container> inserter(Container& x, Iterator i);
208
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000209template <class Iterator>
210class move_iterator {
211public:
212 typedef Iterator iterator_type;
213 typedef typename iterator_traits<Iterator>::difference_type difference_type;
214 typedef Iterator pointer;
215 typedef typename iterator_traits<Iterator>::value_type value_type;
216 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
217 typedef value_type&& reference;
218
219 move_iterator();
220 explicit move_iterator(Iterator i);
221 template <class U> move_iterator(const move_iterator<U>& u);
222 template <class U> move_iterator& operator=(const move_iterator<U>& u);
223 iterator_type base() const;
224 reference operator*() const;
225 pointer operator->() const;
226 move_iterator& operator++();
227 move_iterator operator++(int);
228 move_iterator& operator--();
229 move_iterator operator--(int);
230 move_iterator operator+(difference_type n) const;
231 move_iterator& operator+=(difference_type n);
232 move_iterator operator-(difference_type n) const;
233 move_iterator& operator-=(difference_type n);
234 unspecified operator[](difference_type n) const;
235private:
236 Iterator current; // exposition only
237};
238
239template <class Iterator1, class Iterator2>
240bool
241operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
242
243template <class Iterator1, class Iterator2>
244bool
245operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
246
247template <class Iterator1, class Iterator2>
248bool
249operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
250
251template <class Iterator1, class Iterator2>
252bool
253operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
254
255template <class Iterator1, class Iterator2>
256bool
257operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
258
259template <class Iterator1, class Iterator2>
260bool
261operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
262
263template <class Iterator1, class Iterator2>
264auto
265operator-(const move_iterator<Iterator1>& x,
266 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
267
268template <class Iterator>
269move_iterator<Iterator> operator+(typename move_iterator<Iterator>::difference_type n,
270 const move_iterator<Iterator>& x);
271
272template <class Iterator>
273move_iterator<Iterator> make_move_iterator(const Iterator& i);
274
275
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
277class istream_iterator
278 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
279{
280public:
281 typedef charT char_type;
282 typedef traits traits_type;
283 typedef basic_istream<charT,traits> istream_type;
284
Marshall Clowe9d03062015-04-16 21:36:54 +0000285 constexpr istream_iterator();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286 istream_iterator(istream_type& s);
287 istream_iterator(const istream_iterator& x);
288 ~istream_iterator();
289
290 const T& operator*() const;
291 const T* operator->() const;
292 istream_iterator& operator++();
293 istream_iterator operator++(int);
294};
295
296template <class T, class charT, class traits, class Distance>
297bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
298 const istream_iterator<T,charT,traits,Distance>& y);
299template <class T, class charT, class traits, class Distance>
300bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
301 const istream_iterator<T,charT,traits,Distance>& y);
302
303template <class T, class charT = char, class traits = char_traits<charT> >
304class ostream_iterator
305 : public iterator<output_iterator_tag, void, void, void ,void>
306{
307public:
308 typedef charT char_type;
309 typedef traits traits_type;
310 typedef basic_ostream<charT,traits> ostream_type;
311
312 ostream_iterator(ostream_type& s);
313 ostream_iterator(ostream_type& s, const charT* delimiter);
314 ostream_iterator(const ostream_iterator& x);
315 ~ostream_iterator();
316 ostream_iterator& operator=(const T& value);
317
318 ostream_iterator& operator*();
319 ostream_iterator& operator++();
320 ostream_iterator& operator++(int);
321};
322
323template<class charT, class traits = char_traits<charT> >
324class istreambuf_iterator
325 : public iterator<input_iterator_tag, charT,
326 typename traits::off_type, unspecified,
327 charT>
328{
329public:
330 typedef charT char_type;
331 typedef traits traits_type;
332 typedef typename traits::int_type int_type;
333 typedef basic_streambuf<charT,traits> streambuf_type;
334 typedef basic_istream<charT,traits> istream_type;
335
Howard Hinnantd06a6402012-07-20 19:36:34 +0000336 istreambuf_iterator() noexcept;
337 istreambuf_iterator(istream_type& s) noexcept;
338 istreambuf_iterator(streambuf_type* s) noexcept;
339 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340
341 charT operator*() const;
342 pointer operator->() const;
343 istreambuf_iterator& operator++();
344 a-private-type operator++(int);
345
346 bool equal(const istreambuf_iterator& b) const;
347};
348
349template <class charT, class traits>
350bool operator==(const istreambuf_iterator<charT,traits>& a,
351 const istreambuf_iterator<charT,traits>& b);
352template <class charT, class traits>
353bool operator!=(const istreambuf_iterator<charT,traits>& a,
354 const istreambuf_iterator<charT,traits>& b);
355
356template <class charT, class traits = char_traits<charT> >
357class ostreambuf_iterator
358 : public iterator<output_iterator_tag, void, void, void, void>
359{
360public:
361 typedef charT char_type;
362 typedef traits traits_type;
363 typedef basic_streambuf<charT,traits> streambuf_type;
364 typedef basic_ostream<charT,traits> ostream_type;
365
Howard Hinnantd06a6402012-07-20 19:36:34 +0000366 ostreambuf_iterator(ostream_type& s) noexcept;
367 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368 ostreambuf_iterator& operator=(charT c);
369 ostreambuf_iterator& operator*();
370 ostreambuf_iterator& operator++();
371 ostreambuf_iterator& operator++(int);
Howard Hinnantd06a6402012-07-20 19:36:34 +0000372 bool failed() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373};
374
375template <class C> auto begin(C& c) -> decltype(c.begin());
376template <class C> auto begin(const C& c) -> decltype(c.begin());
377template <class C> auto end(C& c) -> decltype(c.end());
378template <class C> auto end(const C& c) -> decltype(c.end());
379template <class T, size_t N> T* begin(T (&array)[N]);
380template <class T, size_t N> T* end(T (&array)[N]);
381
Marshall Clow09da3c02013-08-30 01:17:07 +0000382template <class C> auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14
383template <class C> auto cend(const C& c) -> decltype(std::end(c)); // C++14
384template <class C> auto rbegin(C& c) -> decltype(c.rbegin()); // C++14
385template <class C> auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14
386template <class C> auto rend(C& c) -> decltype(c.rend()); // C++14
387template <class C> auto rend(const C& c) -> decltype(c.rend()); // C++14
388template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14
389template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); // C++14
390template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]); // C++14
391template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]); // C++14
392template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
393template <class C> auto crend(const C& c) -> decltype(std::rend(c)); // C++14
394
Marshall Clow03c67912014-11-19 19:43:23 +0000395// 24.8, container access:
396template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
397template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
398template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
399template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
400template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
401template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
402template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
403template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
404template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
405
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406} // std
407
408*/
409
410#include <__config>
Eric Fiselierb3792282016-02-20 00:19:45 +0000411#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow02ca8af2014-02-27 02:11:50 +0000412#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413#include <type_traits>
414#include <cstddef>
Marshall Clow09da3c02013-08-30 01:17:07 +0000415#include <initializer_list>
Marshall Clowdece7fe2013-03-18 17:45:34 +0000416#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000417#include <Availability.h>
418#endif
419
Eric Fiselierb9536102014-08-10 23:53:08 +0000420#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421
Howard Hinnant08e17472011-10-17 20:05:10 +0000422#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000424#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425
426_LIBCPP_BEGIN_NAMESPACE_STD
427
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000428struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
429struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
430struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
431struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
432struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433
434template <class _Tp>
435struct __has_iterator_category
436{
437private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000438 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 template <class _Up> static __two __test(...);
440 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
441public:
442 static const bool value = sizeof(__test<_Tp>(0)) == 1;
443};
444
Marshall Clowa71f9562014-01-03 22:55:49 +0000445template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446
447template <class _Iter>
Marshall Clowa71f9562014-01-03 22:55:49 +0000448struct __iterator_traits_impl<_Iter, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449{
450 typedef typename _Iter::difference_type difference_type;
451 typedef typename _Iter::value_type value_type;
452 typedef typename _Iter::pointer pointer;
453 typedef typename _Iter::reference reference;
454 typedef typename _Iter::iterator_category iterator_category;
455};
456
457template <class _Iter, bool> struct __iterator_traits {};
458
459template <class _Iter>
460struct __iterator_traits<_Iter, true>
Marshall Clowa71f9562014-01-03 22:55:49 +0000461 : __iterator_traits_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 <
463 _Iter,
464 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
465 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
466 >
467{};
468
469// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
470// exists. Else iterator_traits<Iterator> will be an empty class. This is a
471// conforming extension which allows some programs to compile and behave as
472// the client expects instead of failing at compile time.
473
474template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000475struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
477
478template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000479struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480{
481 typedef ptrdiff_t difference_type;
482 typedef typename remove_const<_Tp>::type value_type;
483 typedef _Tp* pointer;
484 typedef _Tp& reference;
485 typedef random_access_iterator_tag iterator_category;
486};
487
488template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
489struct __has_iterator_category_convertible_to
490 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
491{};
492
493template <class _Tp, class _Up>
494struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
495
496template <class _Tp>
497struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
498
499template <class _Tp>
500struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
501
502template <class _Tp>
503struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
504
505template <class _Tp>
506struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
507
Marshall Clowdf9db312016-01-13 21:54:34 +0000508template <class _Tp>
509struct __is_exactly_input_iterator
510 : public integral_constant<bool,
511 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
512 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
513
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514template<class _Category, class _Tp, class _Distance = ptrdiff_t,
515 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000516struct _LIBCPP_TYPE_VIS_ONLY iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517{
518 typedef _Tp value_type;
519 typedef _Distance difference_type;
520 typedef _Pointer pointer;
521 typedef _Reference reference;
522 typedef _Category iterator_category;
523};
524
525template <class _InputIter>
526inline _LIBCPP_INLINE_VISIBILITY
527void __advance(_InputIter& __i,
528 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
529{
530 for (; __n > 0; --__n)
531 ++__i;
532}
533
534template <class _BiDirIter>
535inline _LIBCPP_INLINE_VISIBILITY
536void __advance(_BiDirIter& __i,
537 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
538{
539 if (__n >= 0)
540 for (; __n > 0; --__n)
541 ++__i;
542 else
543 for (; __n < 0; ++__n)
544 --__i;
545}
546
547template <class _RandIter>
548inline _LIBCPP_INLINE_VISIBILITY
549void __advance(_RandIter& __i,
550 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
551{
552 __i += __n;
553}
554
555template <class _InputIter>
556inline _LIBCPP_INLINE_VISIBILITY
557void advance(_InputIter& __i,
558 typename iterator_traits<_InputIter>::difference_type __n)
559{
560 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
561}
562
563template <class _InputIter>
564inline _LIBCPP_INLINE_VISIBILITY
565typename iterator_traits<_InputIter>::difference_type
566__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
567{
568 typename iterator_traits<_InputIter>::difference_type __r(0);
569 for (; __first != __last; ++__first)
570 ++__r;
571 return __r;
572}
573
574template <class _RandIter>
575inline _LIBCPP_INLINE_VISIBILITY
576typename iterator_traits<_RandIter>::difference_type
577__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
578{
579 return __last - __first;
580}
581
582template <class _InputIter>
583inline _LIBCPP_INLINE_VISIBILITY
584typename iterator_traits<_InputIter>::difference_type
585distance(_InputIter __first, _InputIter __last)
586{
587 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
588}
589
Marshall Clowe9ef9882015-11-07 17:48:49 +0000590template <class _InputIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000591inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe9ef9882015-11-07 17:48:49 +0000592_InputIter
593next(_InputIter __x,
594 typename iterator_traits<_InputIter>::difference_type __n = 1,
595 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000596{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000597 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000598 return __x;
599}
600
601template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000602inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000603_BidiretionalIter
604prev(_BidiretionalIter __x,
605 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
606 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
607{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000608 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609 return __x;
610}
611
612template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000613class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000614 : public iterator<typename iterator_traits<_Iter>::iterator_category,
615 typename iterator_traits<_Iter>::value_type,
616 typename iterator_traits<_Iter>::difference_type,
617 typename iterator_traits<_Iter>::pointer,
618 typename iterator_traits<_Iter>::reference>
619{
Marshall Clow668a1d82014-03-11 22:05:31 +0000620private:
621 mutable _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000622protected:
623 _Iter current;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624public:
625 typedef _Iter iterator_type;
626 typedef typename iterator_traits<_Iter>::difference_type difference_type;
627 typedef typename iterator_traits<_Iter>::reference reference;
628 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000629
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000630 _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {}
631 _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632 template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u)
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000633 : __t(__u.base()), current(__u.base()) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;}
Marshall Clowb1ead682014-03-11 17:16:17 +0000635 _LIBCPP_INLINE_VISIBILITY reference operator*() const {_Iter __tmp = current; return *--__tmp;}
Marshall Clow02ca8af2014-02-27 02:11:50 +0000636 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;}
638 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int)
639 {reverse_iterator __tmp(*this); --current; return __tmp;}
640 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;}
641 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int)
642 {reverse_iterator __tmp(*this); ++current; return __tmp;}
643 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const
644 {return reverse_iterator(current - __n);}
645 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n)
646 {current -= __n; return *this;}
647 _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const
648 {return reverse_iterator(current + __n);}
649 _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n)
650 {current += __n; return *this;}
651 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Marshall Clowad98e212015-03-05 16:07:37 +0000652 {return *(*this + __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653};
654
655template <class _Iter1, class _Iter2>
656inline _LIBCPP_INLINE_VISIBILITY
657bool
658operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
659{
660 return __x.base() == __y.base();
661}
662
663template <class _Iter1, class _Iter2>
664inline _LIBCPP_INLINE_VISIBILITY
665bool
666operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
667{
668 return __x.base() > __y.base();
669}
670
671template <class _Iter1, class _Iter2>
672inline _LIBCPP_INLINE_VISIBILITY
673bool
674operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
675{
676 return __x.base() != __y.base();
677}
678
679template <class _Iter1, class _Iter2>
680inline _LIBCPP_INLINE_VISIBILITY
681bool
682operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
683{
684 return __x.base() < __y.base();
685}
686
687template <class _Iter1, class _Iter2>
688inline _LIBCPP_INLINE_VISIBILITY
689bool
690operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
691{
692 return __x.base() <= __y.base();
693}
694
695template <class _Iter1, class _Iter2>
696inline _LIBCPP_INLINE_VISIBILITY
697bool
698operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
699{
700 return __x.base() >= __y.base();
701}
702
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000703#if __cplusplus >= 201103L
704template <class _Iter1, class _Iter2>
705inline _LIBCPP_INLINE_VISIBILITY
706auto
707operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
708-> decltype(__y.base() - __x.base())
709{
710 return __y.base() - __x.base();
711}
712#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713template <class _Iter1, class _Iter2>
714inline _LIBCPP_INLINE_VISIBILITY
715typename reverse_iterator<_Iter1>::difference_type
716operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
717{
718 return __y.base() - __x.base();
719}
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000720#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721
722template <class _Iter>
723inline _LIBCPP_INLINE_VISIBILITY
724reverse_iterator<_Iter>
725operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
726{
727 return reverse_iterator<_Iter>(__x.base() - __n);
728}
729
Marshall Clowff137e92014-03-03 01:24:04 +0000730#if _LIBCPP_STD_VER > 11
731template <class _Iter>
732inline _LIBCPP_INLINE_VISIBILITY
733reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
734{
735 return reverse_iterator<_Iter>(__i);
736}
737#endif
738
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000740class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741 : public iterator<output_iterator_tag,
742 void,
743 void,
744 void,
Eric Fiselierc848cef2016-06-30 04:40:50 +0000745 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746{
747protected:
748 _Container* container;
749public:
750 typedef _Container container_type;
751
Marshall Clow53c0e722014-03-03 19:20:40 +0000752 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000753 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
754 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000755#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000756 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
757 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000758#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
760 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
761 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
762};
763
764template <class _Container>
765inline _LIBCPP_INLINE_VISIBILITY
766back_insert_iterator<_Container>
767back_inserter(_Container& __x)
768{
769 return back_insert_iterator<_Container>(__x);
770}
771
772template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000773class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774 : public iterator<output_iterator_tag,
775 void,
776 void,
777 void,
Eric Fiselierc848cef2016-06-30 04:40:50 +0000778 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779{
780protected:
781 _Container* container;
782public:
783 typedef _Container container_type;
784
Marshall Clow53c0e722014-03-03 19:20:40 +0000785 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000786 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
787 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000788#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000789 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
790 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000791#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
793 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
794 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
795};
796
797template <class _Container>
798inline _LIBCPP_INLINE_VISIBILITY
799front_insert_iterator<_Container>
800front_inserter(_Container& __x)
801{
802 return front_insert_iterator<_Container>(__x);
803}
804
805template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000806class _LIBCPP_TYPE_VIS_ONLY insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 : public iterator<output_iterator_tag,
808 void,
809 void,
810 void,
Eric Fiselierc848cef2016-06-30 04:40:50 +0000811 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812{
813protected:
814 _Container* container;
815 typename _Container::iterator iter;
816public:
817 typedef _Container container_type;
818
819 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clow53c0e722014-03-03 19:20:40 +0000820 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000821 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
822 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000823#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000824 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
825 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000826#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
828 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
829 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
830};
831
832template <class _Container>
833inline _LIBCPP_INLINE_VISIBILITY
834insert_iterator<_Container>
835inserter(_Container& __x, typename _Container::iterator __i)
836{
837 return insert_iterator<_Container>(__x, __i);
838}
839
840template <class _Tp, class _CharT = char,
841 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000842class _LIBCPP_TYPE_VIS_ONLY istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000843 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
844{
845public:
846 typedef _CharT char_type;
847 typedef _Traits traits_type;
848 typedef basic_istream<_CharT,_Traits> istream_type;
849private:
850 istream_type* __in_stream_;
851 _Tp __value_;
852public:
Marshall Clowe9d03062015-04-16 21:36:54 +0000853 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000854 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855 {
856 if (!(*__in_stream_ >> __value_))
857 __in_stream_ = 0;
858 }
859
860 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000861 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
863 {
864 if (!(*__in_stream_ >> __value_))
865 __in_stream_ = 0;
866 return *this;
867 }
868 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
869 {istream_iterator __t(*this); ++(*this); return __t;}
870
871 friend _LIBCPP_INLINE_VISIBILITY
872 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
873 {return __x.__in_stream_ == __y.__in_stream_;}
874
875 friend _LIBCPP_INLINE_VISIBILITY
876 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
877 {return !(__x == __y);}
878};
879
880template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000881class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000882 : public iterator<output_iterator_tag, void, void, void, void>
883{
884public:
885 typedef _CharT char_type;
886 typedef _Traits traits_type;
887 typedef basic_ostream<_CharT,_Traits> ostream_type;
888private:
889 ostream_type* __out_stream_;
890 const char_type* __delim_;
891public:
892 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s)
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000893 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000895 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000896 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000898 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 if (__delim_)
900 *__out_stream_ << __delim_;
901 return *this;
902 }
903
904 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
905 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
906 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
907};
908
909template<class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000910class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911 : public iterator<input_iterator_tag, _CharT,
912 typename _Traits::off_type, _CharT*,
913 _CharT>
914{
915public:
916 typedef _CharT char_type;
917 typedef _Traits traits_type;
918 typedef typename _Traits::int_type int_type;
919 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
920 typedef basic_istream<_CharT,_Traits> istream_type;
921private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000922 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923
924 class __proxy
925 {
926 char_type __keep_;
927 streambuf_type* __sbuf_;
928 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
929 : __keep_(__c), __sbuf_(__s) {}
930 friend class istreambuf_iterator;
931 public:
932 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
933 };
934
Howard Hinnant82894812010-09-22 16:48:34 +0000935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000936 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000937 {
938 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
939 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000940 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941 }
942public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000943 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000944 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000945 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000946 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000947 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000948 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949 : __sbuf_(__p.__sbuf_) {}
950
Howard Hinnantec3773c2011-12-01 20:21:04 +0000951 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
952 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000953 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
954 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
955 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000956 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957 return *this;
958 }
959 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
960 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000961 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000962 }
963
964 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000965 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966};
967
968template <class _CharT, class _Traits>
969inline _LIBCPP_INLINE_VISIBILITY
970bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
971 const istreambuf_iterator<_CharT,_Traits>& __b)
972 {return __a.equal(__b);}
973
974template <class _CharT, class _Traits>
975inline _LIBCPP_INLINE_VISIBILITY
976bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
977 const istreambuf_iterator<_CharT,_Traits>& __b)
978 {return !__a.equal(__b);}
979
980template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000981class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982 : public iterator<output_iterator_tag, void, void, void, void>
983{
984public:
985 typedef _CharT char_type;
986 typedef _Traits traits_type;
987 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
988 typedef basic_ostream<_CharT,_Traits> ostream_type;
989private:
990 streambuf_type* __sbuf_;
991public:
Howard Hinnantd06a6402012-07-20 19:36:34 +0000992 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000994 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995 : __sbuf_(__s) {}
996 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
997 {
998 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
999 __sbuf_ = 0;
1000 return *this;
1001 }
1002 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1003 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1004 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +00001005 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +00001006
Howard Hinnant537b2fa2012-11-14 21:17:15 +00001007#if !defined(__APPLE__) || \
1008 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1009 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1010
Howard Hinnanta585de62012-09-19 19:14:15 +00001011 template <class _Ch, class _Tr>
1012 friend
1013 _LIBCPP_HIDDEN
1014 ostreambuf_iterator<_Ch, _Tr>
1015 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1016 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1017 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +00001018#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001019};
1020
1021template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001022class _LIBCPP_TYPE_VIS_ONLY move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001023{
1024private:
1025 _Iter __i;
1026public:
1027 typedef _Iter iterator_type;
1028 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1029 typedef typename iterator_traits<iterator_type>::value_type value_type;
1030 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowdca800c2016-04-11 03:54:53 +00001031 typedef iterator_type pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +00001032#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Eric Fiselierdf46b782016-04-22 00:49:12 +00001033 typedef typename iterator_traits<iterator_type>::reference __reference;
1034 typedef typename conditional<
1035 is_reference<__reference>::value,
1036 typename remove_reference<__reference>::type&&,
1037 __reference
1038 >::type reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001039#else
1040 typedef typename iterator_traits<iterator_type>::reference reference;
1041#endif
Howard Hinnant324bb032010-08-22 00:02:43 +00001042
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
1044 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
1045 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
1046 : __i(__u.base()) {}
1047 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +00001048 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
1049 return static_cast<reference>(*__i);
1050 }
Marshall Clowdca800c2016-04-11 03:54:53 +00001051 _LIBCPP_INLINE_VISIBILITY pointer operator->() const { return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
1053 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
1054 {move_iterator __tmp(*this); ++__i; return __tmp;}
1055 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
1056 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
1057 {move_iterator __tmp(*this); --__i; return __tmp;}
1058 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
1059 {return move_iterator(__i + __n);}
1060 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
1061 {__i += __n; return *this;}
1062 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
1063 {return move_iterator(__i - __n);}
1064 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
1065 {__i -= __n; return *this;}
1066 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +00001067 {
1068 return static_cast<reference>(__i[__n]);
1069 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070};
1071
1072template <class _Iter1, class _Iter2>
1073inline _LIBCPP_INLINE_VISIBILITY
1074bool
1075operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1076{
1077 return __x.base() == __y.base();
1078}
1079
1080template <class _Iter1, class _Iter2>
1081inline _LIBCPP_INLINE_VISIBILITY
1082bool
1083operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1084{
1085 return __x.base() < __y.base();
1086}
1087
1088template <class _Iter1, class _Iter2>
1089inline _LIBCPP_INLINE_VISIBILITY
1090bool
1091operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1092{
1093 return __x.base() != __y.base();
1094}
1095
1096template <class _Iter1, class _Iter2>
1097inline _LIBCPP_INLINE_VISIBILITY
1098bool
1099operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1100{
1101 return __x.base() > __y.base();
1102}
1103
1104template <class _Iter1, class _Iter2>
1105inline _LIBCPP_INLINE_VISIBILITY
1106bool
1107operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1108{
1109 return __x.base() >= __y.base();
1110}
1111
1112template <class _Iter1, class _Iter2>
1113inline _LIBCPP_INLINE_VISIBILITY
1114bool
1115operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1116{
1117 return __x.base() <= __y.base();
1118}
1119
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001120#if __cplusplus >= 201103L
1121template <class _Iter1, class _Iter2>
1122inline _LIBCPP_INLINE_VISIBILITY
1123auto
1124operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1125-> decltype(__x.base() - __y.base())
1126{
1127 return __x.base() - __y.base();
1128}
1129#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001130template <class _Iter1, class _Iter2>
1131inline _LIBCPP_INLINE_VISIBILITY
1132typename move_iterator<_Iter1>::difference_type
1133operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1134{
1135 return __x.base() - __y.base();
1136}
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001137#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138
1139template <class _Iter>
1140inline _LIBCPP_INLINE_VISIBILITY
1141move_iterator<_Iter>
1142operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1143{
1144 return move_iterator<_Iter>(__x.base() + __n);
1145}
1146
1147template <class _Iter>
1148inline _LIBCPP_INLINE_VISIBILITY
1149move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:03 +00001150make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151{
1152 return move_iterator<_Iter>(__i);
1153}
1154
1155// __wrap_iter
1156
1157template <class _Iter> class __wrap_iter;
1158
1159template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001160_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001162operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163
1164template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001165_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001167operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168
1169template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001170_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001172operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001173
1174template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001175_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001176bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001177operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001178
1179template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001180_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001181bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001182operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183
1184template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001185_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001187operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001188
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001189#if __cplusplus >= 201103L
1190template <class _Iter1, class _Iter2>
1191_LIBCPP_INLINE_VISIBILITY
1192auto
1193operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1194-> decltype(__x.base() - __y.base());
1195#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001196template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001197_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001199operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001200#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201
1202template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001203_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001204__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001205operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206
Howard Hinnant33be35e2012-09-14 00:39:16 +00001207template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1208template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1209template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1210template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211
1212template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001213_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001214typename enable_if
1215<
Howard Hinnant1468b662010-11-19 22:17:28 +00001216 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217 _Tp*
1218>::type
1219__unwrap_iter(__wrap_iter<_Tp*>);
1220
1221template <class _Iter>
1222class __wrap_iter
1223{
1224public:
1225 typedef _Iter iterator_type;
1226 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1227 typedef typename iterator_traits<iterator_type>::value_type value_type;
1228 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1229 typedef typename iterator_traits<iterator_type>::pointer pointer;
1230 typedef typename iterator_traits<iterator_type>::reference reference;
1231private:
1232 iterator_type __i;
1233public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001234 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001235#if _LIBCPP_STD_VER > 11
1236 : __i{}
1237#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001238 {
1239#if _LIBCPP_DEBUG_LEVEL >= 2
1240 __get_db()->__insert_i(this);
1241#endif
1242 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001244 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001245 : __i(__u.base())
1246 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001247#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001248 __get_db()->__iterator_copy(this, &__u);
1249#endif
1250 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001251#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001252 _LIBCPP_INLINE_VISIBILITY
1253 __wrap_iter(const __wrap_iter& __x)
1254 : __i(__x.base())
1255 {
1256 __get_db()->__iterator_copy(this, &__x);
1257 }
1258 _LIBCPP_INLINE_VISIBILITY
1259 __wrap_iter& operator=(const __wrap_iter& __x)
1260 {
1261 if (this != &__x)
1262 {
1263 __get_db()->__iterator_copy(this, &__x);
1264 __i = __x.__i;
1265 }
1266 return *this;
1267 }
1268 _LIBCPP_INLINE_VISIBILITY
1269 ~__wrap_iter()
1270 {
1271 __get_db()->__erase_i(this);
1272 }
1273#endif
1274 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1275 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001276#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001277 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1278 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001279#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001280 return *__i;
1281 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001282 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1283 {
1284#if _LIBCPP_DEBUG_LEVEL >= 2
1285 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1286 "Attempted to dereference a non-dereferenceable iterator");
1287#endif
Marshall Clowdca800c2016-04-11 03:54:53 +00001288 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001289 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001290 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1291 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001292#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001293 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1294 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001295#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001296 ++__i;
1297 return *this;
1298 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001299 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001300 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1301 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1302 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001303#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001304 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1305 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001306#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001307 --__i;
1308 return *this;
1309 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001310 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001311 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001312 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001313 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001314 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001315 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001316#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001317 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1318 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001319#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001320 __i += __n;
1321 return *this;
1322 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001323 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001324 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001325 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001326 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001327 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001328 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001329#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001330 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1331 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001332#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001333 return __i[__n];
1334 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335
Howard Hinnanta6119a82011-05-29 19:57:12 +00001336 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337
1338private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001339#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001340 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1341 {
1342 __get_db()->__insert_ic(this, __p);
1343 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001344#else
1345 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001346#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347
1348 template <class _Up> friend class __wrap_iter;
1349 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Marshall Clow59f573f2015-02-18 19:28:35 +00001350 template <class _Tp, class _Alloc> friend class _LIBCPP_TYPE_VIS_ONLY vector;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351
1352 template <class _Iter1, class _Iter2>
1353 friend
1354 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001355 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001356
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001357 template <class _Iter1, class _Iter2>
1358 friend
1359 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001360 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001361
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362 template <class _Iter1, class _Iter2>
1363 friend
1364 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001365 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001366
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367 template <class _Iter1, class _Iter2>
1368 friend
1369 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001370 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001371
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001372 template <class _Iter1, class _Iter2>
1373 friend
1374 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001375 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001376
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001377 template <class _Iter1, class _Iter2>
1378 friend
1379 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001380 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001381
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001382#if __cplusplus >= 201103L
1383 template <class _Iter1, class _Iter2>
1384 friend
1385 auto
1386 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1387 -> decltype(__x.base() - __y.base());
1388#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389 template <class _Iter1, class _Iter2>
1390 friend
1391 typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001392 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001393#endif
Howard Hinnant324bb032010-08-22 00:02:43 +00001394
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001395 template <class _Iter1>
1396 friend
1397 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001398 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399
Howard Hinnant99968442011-11-29 18:15:50 +00001400 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001402 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1404
1405 template <class _Tp>
1406 friend
1407 typename enable_if
1408 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001409 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410 _Tp*
1411 >::type
1412 __unwrap_iter(__wrap_iter<_Tp*>);
1413};
1414
1415template <class _Iter1, class _Iter2>
1416inline _LIBCPP_INLINE_VISIBILITY
1417bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001418operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419{
1420 return __x.base() == __y.base();
1421}
1422
1423template <class _Iter1, class _Iter2>
1424inline _LIBCPP_INLINE_VISIBILITY
1425bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001426operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427{
Howard Hinnantabe26282011-09-16 17:29:17 +00001428#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001429 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001430 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001431#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432 return __x.base() < __y.base();
1433}
1434
1435template <class _Iter1, class _Iter2>
1436inline _LIBCPP_INLINE_VISIBILITY
1437bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001438operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001440 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001441}
1442
1443template <class _Iter1, class _Iter2>
1444inline _LIBCPP_INLINE_VISIBILITY
1445bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001446operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001448 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001449}
1450
1451template <class _Iter1, class _Iter2>
1452inline _LIBCPP_INLINE_VISIBILITY
1453bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001454operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001456 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457}
1458
1459template <class _Iter1, class _Iter2>
1460inline _LIBCPP_INLINE_VISIBILITY
1461bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001462operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001463{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001464 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465}
1466
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001467template <class _Iter1>
1468inline _LIBCPP_INLINE_VISIBILITY
1469bool
1470operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1471{
1472 return !(__x == __y);
1473}
1474
1475template <class _Iter1>
1476inline _LIBCPP_INLINE_VISIBILITY
1477bool
1478operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1479{
1480 return __y < __x;
1481}
1482
1483template <class _Iter1>
1484inline _LIBCPP_INLINE_VISIBILITY
1485bool
1486operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1487{
1488 return !(__x < __y);
1489}
1490
1491template <class _Iter1>
1492inline _LIBCPP_INLINE_VISIBILITY
1493bool
1494operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1495{
1496 return !(__y < __x);
1497}
1498
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001499#if __cplusplus >= 201103L
1500template <class _Iter1, class _Iter2>
1501inline _LIBCPP_INLINE_VISIBILITY
1502auto
1503operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1504-> decltype(__x.base() - __y.base())
1505{
1506#if _LIBCPP_DEBUG_LEVEL >= 2
1507 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1508 "Attempted to subtract incompatible iterators");
1509#endif
1510 return __x.base() - __y.base();
1511}
1512#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513template <class _Iter1, class _Iter2>
1514inline _LIBCPP_INLINE_VISIBILITY
1515typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001516operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517{
Howard Hinnantabe26282011-09-16 17:29:17 +00001518#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001519 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001520 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001521#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522 return __x.base() - __y.base();
1523}
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001524#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525
1526template <class _Iter>
1527inline _LIBCPP_INLINE_VISIBILITY
1528__wrap_iter<_Iter>
1529operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001530 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001532 __x += __n;
1533 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534}
1535
Marshall Clowdf9db312016-01-13 21:54:34 +00001536template <class _Iter>
1537struct __libcpp_is_trivial_iterator
1538 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1539
1540template <class _Iter>
1541struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
1542 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1543
1544template <class _Iter>
1545struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
1546 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1547
1548template <class _Iter>
1549struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
1550 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1551
1552
Marshall Clow6daf5342013-12-02 03:24:33 +00001553template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001554inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001555_Tp*
1556begin(_Tp (&__array)[_Np])
1557{
1558 return __array;
1559}
1560
1561template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001562inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001563_Tp*
1564end(_Tp (&__array)[_Np])
1565{
1566 return __array + _Np;
1567}
1568
Marshall Clow1c398692013-12-11 19:32:32 +00001569#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
1570
Howard Hinnant99968442011-11-29 18:15:50 +00001571template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001572inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001573auto
Howard Hinnant99968442011-11-29 18:15:50 +00001574begin(_Cp& __c) -> decltype(__c.begin())
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 Hinnantbc8d3f92010-05-11 19:42:16 +00001581auto
Howard Hinnant99968442011-11-29 18:15:50 +00001582begin(const _Cp& __c) -> decltype(__c.begin())
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 Hinnantbc8d3f92010-05-11 19:42:16 +00001589auto
Howard Hinnant99968442011-11-29 18:15:50 +00001590end(_Cp& __c) -> decltype(__c.end())
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 Hinnantbc8d3f92010-05-11 19:42:16 +00001597auto
Howard Hinnant99968442011-11-29 18:15:50 +00001598end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001599{
1600 return __c.end();
1601}
1602
Marshall Clow09da3c02013-08-30 01:17:07 +00001603#if _LIBCPP_STD_VER > 11
1604
Marshall Clow6daf5342013-12-02 03:24:33 +00001605template <class _Tp, size_t _Np>
1606inline _LIBCPP_INLINE_VISIBILITY
1607reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1608{
1609 return reverse_iterator<_Tp*>(__array + _Np);
1610}
1611
1612template <class _Tp, size_t _Np>
1613inline _LIBCPP_INLINE_VISIBILITY
1614reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1615{
1616 return reverse_iterator<_Tp*>(__array);
1617}
1618
1619template <class _Ep>
1620inline _LIBCPP_INLINE_VISIBILITY
1621reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1622{
1623 return reverse_iterator<const _Ep*>(__il.end());
1624}
1625
1626template <class _Ep>
1627inline _LIBCPP_INLINE_VISIBILITY
1628reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1629{
1630 return reverse_iterator<const _Ep*>(__il.begin());
1631}
1632
Marshall Clow09da3c02013-08-30 01:17:07 +00001633template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001634inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001635auto cbegin(const _Cp& __c) -> decltype(begin(__c))
1636{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001637 return begin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001638}
1639
1640template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001641inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow09da3c02013-08-30 01:17:07 +00001642auto cend(const _Cp& __c) -> decltype(end(__c))
1643{
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001644 return end(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001645}
1646
1647template <class _Cp>
1648inline _LIBCPP_INLINE_VISIBILITY
1649auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1650{
1651 return __c.rbegin();
1652}
1653
1654template <class _Cp>
1655inline _LIBCPP_INLINE_VISIBILITY
1656auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1657{
1658 return __c.rbegin();
1659}
1660
1661template <class _Cp>
1662inline _LIBCPP_INLINE_VISIBILITY
1663auto rend(_Cp& __c) -> decltype(__c.rend())
1664{
1665 return __c.rend();
1666}
1667
1668template <class _Cp>
1669inline _LIBCPP_INLINE_VISIBILITY
1670auto rend(const _Cp& __c) -> decltype(__c.rend())
1671{
1672 return __c.rend();
1673}
1674
1675template <class _Cp>
1676inline _LIBCPP_INLINE_VISIBILITY
1677auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
1678{
1679 return rbegin(__c);
1680}
1681
1682template <class _Cp>
1683inline _LIBCPP_INLINE_VISIBILITY
1684auto crend(const _Cp& __c) -> decltype(rend(__c))
1685{
1686 return rend(__c);
1687}
1688
1689#endif
1690
1691
Howard Hinnant726a76f2010-11-16 21:10:23 +00001692#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001693
Howard Hinnant99968442011-11-29 18:15:50 +00001694template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001695inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001696typename _Cp::iterator
1697begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698{
1699 return __c.begin();
1700}
1701
Howard Hinnant99968442011-11-29 18:15:50 +00001702template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001703inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001704typename _Cp::const_iterator
1705begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001706{
1707 return __c.begin();
1708}
1709
Howard Hinnant99968442011-11-29 18:15:50 +00001710template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001711inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001712typename _Cp::iterator
1713end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001714{
1715 return __c.end();
1716}
1717
Howard Hinnant99968442011-11-29 18:15:50 +00001718template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001719inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001720typename _Cp::const_iterator
1721end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722{
1723 return __c.end();
1724}
1725
Howard Hinnant726a76f2010-11-16 21:10:23 +00001726#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001727
Marshall Clow03c67912014-11-19 19:43:23 +00001728#if _LIBCPP_STD_VER > 14
Marshall Clow35e462d2015-02-11 16:14:01 +00001729template <class _Cont>
1730constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001731
Marshall Clow35e462d2015-02-11 16:14:01 +00001732template <class _Tp, size_t _Sz>
1733constexpr size_t size(const _Tp (&__array)[_Sz]) noexcept { return _Sz; }
Marshall Clow03c67912014-11-19 19:43:23 +00001734
Marshall Clow35e462d2015-02-11 16:14:01 +00001735template <class _Cont>
1736constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001737
Marshall Clow35e462d2015-02-11 16:14:01 +00001738template <class _Tp, size_t _Sz>
1739constexpr bool empty(const _Tp (&__array)[_Sz]) noexcept { return false; }
Marshall Clow03c67912014-11-19 19:43:23 +00001740
1741template <class _Ep>
1742constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1743
Marshall Clow35e462d2015-02-11 16:14:01 +00001744template <class _Cont> constexpr
1745auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001746
Marshall Clow35e462d2015-02-11 16:14:01 +00001747template <class _Cont> constexpr
1748auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001749
Marshall Clow35e462d2015-02-11 16:14:01 +00001750template <class _Tp, size_t _Sz>
1751constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clow03c67912014-11-19 19:43:23 +00001752
1753template <class _Ep>
1754constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1755#endif
1756
1757
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001758_LIBCPP_END_NAMESPACE_STD
1759
1760#endif // _LIBCPP_ITERATOR