blob: 731791b995f0cd77b058ab025d14ca4a36f82837 [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
Marshall Clow4414a6a2016-10-19 15:12:50 +000092 constexpr reverse_iterator();
93 constexpr explicit reverse_iterator(Iterator x);
94 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
95 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
96 constexpr Iterator base() const;
97 constexpr reference operator*() const;
98 constexpr pointer operator->() const;
99 constexpr reverse_iterator& operator++();
100 constexpr reverse_iterator operator++(int);
101 constexpr reverse_iterator& operator--();
102 constexpr reverse_iterator operator--(int);
103 constexpr reverse_iterator operator+ (difference_type n) const;
104 constexpr reverse_iterator& operator+=(difference_type n);
105 constexpr reverse_iterator operator- (difference_type n) const;
106 constexpr reverse_iterator& operator-=(difference_type n);
107 constexpr reference operator[](difference_type n) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000108};
109
110template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000111constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000112operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
113
114template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000115constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000116operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
117
118template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000119constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
121
122template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000123constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000124operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
125
126template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000127constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
129
130template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000131constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000132operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
133
134template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000135constexpr auto
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000136operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow4414a6a2016-10-19 15:12:50 +0000137-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138
139template <class Iterator>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000140constexpr reverse_iterator<Iterator>
141operator+(typename reverse_iterator<Iterator>::difference_type n,
142 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000143
Marshall Clow4414a6a2016-10-19 15:12:50 +0000144template <class Iterator>
145constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clowff137e92014-03-03 01:24:04 +0000146
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000147template <class Container>
148class back_insert_iterator
149{
150protected:
151 Container* container;
152public:
153 typedef Container container_type;
154 typedef void value_type;
155 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50 +0000156 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000157 typedef void pointer;
158
159 explicit back_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000160 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000161 back_insert_iterator& operator*();
162 back_insert_iterator& operator++();
163 back_insert_iterator operator++(int);
164};
165
166template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
167
168template <class Container>
169class front_insert_iterator
170{
171protected:
172 Container* container;
173public:
174 typedef Container container_type;
175 typedef void value_type;
176 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50 +0000177 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178 typedef void pointer;
179
180 explicit front_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000181 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000182 front_insert_iterator& operator*();
183 front_insert_iterator& operator++();
184 front_insert_iterator operator++(int);
185};
186
187template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
188
189template <class Container>
190class insert_iterator
191{
192protected:
193 Container* container;
194 typename Container::iterator iter;
195public:
196 typedef Container container_type;
197 typedef void value_type;
198 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50 +0000199 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000200 typedef void pointer;
201
202 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant45f57172010-09-14 20:26:27 +0000203 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204 insert_iterator& operator*();
205 insert_iterator& operator++();
206 insert_iterator& operator++(int);
207};
208
209template <class Container, class Iterator>
210insert_iterator<Container> inserter(Container& x, Iterator i);
211
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000212template <class Iterator>
213class move_iterator {
214public:
215 typedef Iterator iterator_type;
216 typedef typename iterator_traits<Iterator>::difference_type difference_type;
217 typedef Iterator pointer;
218 typedef typename iterator_traits<Iterator>::value_type value_type;
219 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
220 typedef value_type&& reference;
221
222 move_iterator();
223 explicit move_iterator(Iterator i);
224 template <class U> move_iterator(const move_iterator<U>& u);
225 template <class U> move_iterator& operator=(const move_iterator<U>& u);
226 iterator_type base() const;
227 reference operator*() const;
228 pointer operator->() const;
229 move_iterator& operator++();
230 move_iterator operator++(int);
231 move_iterator& operator--();
232 move_iterator operator--(int);
233 move_iterator operator+(difference_type n) const;
234 move_iterator& operator+=(difference_type n);
235 move_iterator operator-(difference_type n) const;
236 move_iterator& operator-=(difference_type n);
237 unspecified operator[](difference_type n) const;
238private:
239 Iterator current; // exposition only
240};
241
242template <class Iterator1, class Iterator2>
243bool
244operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
245
246template <class Iterator1, class Iterator2>
247bool
248operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
249
250template <class Iterator1, class Iterator2>
251bool
252operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
253
254template <class Iterator1, class Iterator2>
255bool
256operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
257
258template <class Iterator1, class Iterator2>
259bool
260operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
261
262template <class Iterator1, class Iterator2>
263bool
264operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
265
266template <class Iterator1, class Iterator2>
267auto
268operator-(const move_iterator<Iterator1>& x,
269 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
270
271template <class Iterator>
272move_iterator<Iterator> operator+(typename move_iterator<Iterator>::difference_type n,
273 const move_iterator<Iterator>& x);
274
275template <class Iterator>
276move_iterator<Iterator> make_move_iterator(const Iterator& i);
277
278
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
280class istream_iterator
281 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
282{
283public:
284 typedef charT char_type;
285 typedef traits traits_type;
286 typedef basic_istream<charT,traits> istream_type;
287
Marshall Clowe9d03062015-04-16 21:36:54 +0000288 constexpr istream_iterator();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289 istream_iterator(istream_type& s);
290 istream_iterator(const istream_iterator& x);
291 ~istream_iterator();
292
293 const T& operator*() const;
294 const T* operator->() const;
295 istream_iterator& operator++();
296 istream_iterator operator++(int);
297};
298
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);
302template <class T, class charT, class traits, class Distance>
303bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
304 const istream_iterator<T,charT,traits,Distance>& y);
305
306template <class T, class charT = char, class traits = char_traits<charT> >
307class ostream_iterator
308 : public iterator<output_iterator_tag, void, void, void ,void>
309{
310public:
311 typedef charT char_type;
312 typedef traits traits_type;
313 typedef basic_ostream<charT,traits> ostream_type;
314
315 ostream_iterator(ostream_type& s);
316 ostream_iterator(ostream_type& s, const charT* delimiter);
317 ostream_iterator(const ostream_iterator& x);
318 ~ostream_iterator();
319 ostream_iterator& operator=(const T& value);
320
321 ostream_iterator& operator*();
322 ostream_iterator& operator++();
323 ostream_iterator& operator++(int);
324};
325
326template<class charT, class traits = char_traits<charT> >
327class istreambuf_iterator
328 : public iterator<input_iterator_tag, charT,
329 typename traits::off_type, unspecified,
330 charT>
331{
332public:
333 typedef charT char_type;
334 typedef traits traits_type;
335 typedef typename traits::int_type int_type;
336 typedef basic_streambuf<charT,traits> streambuf_type;
337 typedef basic_istream<charT,traits> istream_type;
338
Howard Hinnantd06a6402012-07-20 19:36:34 +0000339 istreambuf_iterator() noexcept;
340 istreambuf_iterator(istream_type& s) noexcept;
341 istreambuf_iterator(streambuf_type* s) noexcept;
342 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343
344 charT operator*() const;
345 pointer operator->() const;
346 istreambuf_iterator& operator++();
347 a-private-type operator++(int);
348
349 bool equal(const istreambuf_iterator& b) const;
350};
351
352template <class charT, class traits>
353bool operator==(const istreambuf_iterator<charT,traits>& a,
354 const istreambuf_iterator<charT,traits>& b);
355template <class charT, class traits>
356bool operator!=(const istreambuf_iterator<charT,traits>& a,
357 const istreambuf_iterator<charT,traits>& b);
358
359template <class charT, class traits = char_traits<charT> >
360class ostreambuf_iterator
361 : public iterator<output_iterator_tag, void, void, void, void>
362{
363public:
364 typedef charT char_type;
365 typedef traits traits_type;
366 typedef basic_streambuf<charT,traits> streambuf_type;
367 typedef basic_ostream<charT,traits> ostream_type;
368
Howard Hinnantd06a6402012-07-20 19:36:34 +0000369 ostreambuf_iterator(ostream_type& s) noexcept;
370 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371 ostreambuf_iterator& operator=(charT c);
372 ostreambuf_iterator& operator*();
373 ostreambuf_iterator& operator++();
374 ostreambuf_iterator& operator++(int);
Howard Hinnantd06a6402012-07-20 19:36:34 +0000375 bool failed() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376};
377
378template <class C> auto begin(C& c) -> decltype(c.begin());
379template <class C> auto begin(const C& c) -> decltype(c.begin());
380template <class C> auto end(C& c) -> decltype(c.end());
381template <class C> auto end(const C& c) -> decltype(c.end());
382template <class T, size_t N> T* begin(T (&array)[N]);
383template <class T, size_t N> T* end(T (&array)[N]);
384
Marshall Clow09da3c02013-08-30 01:17:07 +0000385template <class C> auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14
386template <class C> auto cend(const C& c) -> decltype(std::end(c)); // C++14
387template <class C> auto rbegin(C& c) -> decltype(c.rbegin()); // C++14
388template <class C> auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14
389template <class C> auto rend(C& c) -> decltype(c.rend()); // C++14
390template <class C> auto rend(const C& c) -> decltype(c.rend()); // C++14
391template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14
392template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); // C++14
393template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]); // C++14
394template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]); // C++14
395template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
396template <class C> auto crend(const C& c) -> decltype(std::rend(c)); // C++14
397
Marshall Clow03c67912014-11-19 19:43:23 +0000398// 24.8, container access:
399template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
400template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
401template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
402template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
403template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
404template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
405template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
406template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
407template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
408
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000409} // std
410
411*/
412
413#include <__config>
Eric Fiselierb3792282016-02-20 00:19:45 +0000414#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow02ca8af2014-02-27 02:11:50 +0000415#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416#include <type_traits>
417#include <cstddef>
Marshall Clow09da3c02013-08-30 01:17:07 +0000418#include <initializer_list>
Marshall Clowdece7fe2013-03-18 17:45:34 +0000419#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000420#include <Availability.h>
421#endif
422
Eric Fiselierb9536102014-08-10 23:53:08 +0000423#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424
Howard Hinnant08e17472011-10-17 20:05:10 +0000425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000427#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428
429_LIBCPP_BEGIN_NAMESPACE_STD
430
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000431struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {};
432struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {};
433struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {};
434struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {};
435struct _LIBCPP_TYPE_VIS_ONLY random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436
437template <class _Tp>
438struct __has_iterator_category
439{
440private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000441 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442 template <class _Up> static __two __test(...);
443 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
444public:
445 static const bool value = sizeof(__test<_Tp>(0)) == 1;
446};
447
Marshall Clowa71f9562014-01-03 22:55:49 +0000448template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449
450template <class _Iter>
Marshall Clowa71f9562014-01-03 22:55:49 +0000451struct __iterator_traits_impl<_Iter, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452{
453 typedef typename _Iter::difference_type difference_type;
454 typedef typename _Iter::value_type value_type;
455 typedef typename _Iter::pointer pointer;
456 typedef typename _Iter::reference reference;
457 typedef typename _Iter::iterator_category iterator_category;
458};
459
460template <class _Iter, bool> struct __iterator_traits {};
461
462template <class _Iter>
463struct __iterator_traits<_Iter, true>
Marshall Clowa71f9562014-01-03 22:55:49 +0000464 : __iterator_traits_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465 <
466 _Iter,
467 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
468 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
469 >
470{};
471
472// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
473// exists. Else iterator_traits<Iterator> will be an empty class. This is a
474// conforming extension which allows some programs to compile and behave as
475// the client expects instead of failing at compile time.
476
477template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000478struct _LIBCPP_TYPE_VIS_ONLY iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000479 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
480
481template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000482struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483{
484 typedef ptrdiff_t difference_type;
485 typedef typename remove_const<_Tp>::type value_type;
486 typedef _Tp* pointer;
487 typedef _Tp& reference;
488 typedef random_access_iterator_tag iterator_category;
489};
490
491template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
492struct __has_iterator_category_convertible_to
493 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
494{};
495
496template <class _Tp, class _Up>
497struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
498
499template <class _Tp>
500struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
501
502template <class _Tp>
503struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
504
505template <class _Tp>
506struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
507
508template <class _Tp>
509struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
510
Marshall Clowdf9db312016-01-13 21:54:34 +0000511template <class _Tp>
512struct __is_exactly_input_iterator
513 : public integral_constant<bool,
514 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
515 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
516
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517template<class _Category, class _Tp, class _Distance = ptrdiff_t,
518 class _Pointer = _Tp*, class _Reference = _Tp&>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000519struct _LIBCPP_TYPE_VIS_ONLY iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520{
521 typedef _Tp value_type;
522 typedef _Distance difference_type;
523 typedef _Pointer pointer;
524 typedef _Reference reference;
525 typedef _Category iterator_category;
526};
527
528template <class _InputIter>
529inline _LIBCPP_INLINE_VISIBILITY
530void __advance(_InputIter& __i,
531 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
532{
533 for (; __n > 0; --__n)
534 ++__i;
535}
536
537template <class _BiDirIter>
538inline _LIBCPP_INLINE_VISIBILITY
539void __advance(_BiDirIter& __i,
540 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
541{
542 if (__n >= 0)
543 for (; __n > 0; --__n)
544 ++__i;
545 else
546 for (; __n < 0; ++__n)
547 --__i;
548}
549
550template <class _RandIter>
551inline _LIBCPP_INLINE_VISIBILITY
552void __advance(_RandIter& __i,
553 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
554{
555 __i += __n;
556}
557
558template <class _InputIter>
559inline _LIBCPP_INLINE_VISIBILITY
560void advance(_InputIter& __i,
561 typename iterator_traits<_InputIter>::difference_type __n)
562{
563 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
564}
565
566template <class _InputIter>
567inline _LIBCPP_INLINE_VISIBILITY
568typename iterator_traits<_InputIter>::difference_type
569__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
570{
571 typename iterator_traits<_InputIter>::difference_type __r(0);
572 for (; __first != __last; ++__first)
573 ++__r;
574 return __r;
575}
576
577template <class _RandIter>
578inline _LIBCPP_INLINE_VISIBILITY
579typename iterator_traits<_RandIter>::difference_type
580__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
581{
582 return __last - __first;
583}
584
585template <class _InputIter>
586inline _LIBCPP_INLINE_VISIBILITY
587typename iterator_traits<_InputIter>::difference_type
588distance(_InputIter __first, _InputIter __last)
589{
590 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
591}
592
Marshall Clowe9ef9882015-11-07 17:48:49 +0000593template <class _InputIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000594inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe9ef9882015-11-07 17:48:49 +0000595_InputIter
596next(_InputIter __x,
597 typename iterator_traits<_InputIter>::difference_type __n = 1,
598 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000600 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601 return __x;
602}
603
604template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34 +0000605inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606_BidiretionalIter
607prev(_BidiretionalIter __x,
608 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
609 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
610{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000611 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000612 return __x;
613}
614
615template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000616class _LIBCPP_TYPE_VIS_ONLY reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617 : public iterator<typename iterator_traits<_Iter>::iterator_category,
618 typename iterator_traits<_Iter>::value_type,
619 typename iterator_traits<_Iter>::difference_type,
620 typename iterator_traits<_Iter>::pointer,
621 typename iterator_traits<_Iter>::reference>
622{
Marshall Clow668a1d82014-03-11 22:05:31 +0000623private:
Marshall Clow4414a6a2016-10-19 15:12:50 +0000624 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000625protected:
626 _Iter current;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627public:
628 typedef _Iter iterator_type;
629 typedef typename iterator_traits<_Iter>::difference_type difference_type;
630 typedef typename iterator_traits<_Iter>::reference reference;
631 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000632
Marshall Clow4414a6a2016-10-19 15:12:50 +0000633 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
634 reverse_iterator() : __t(), current() {}
635 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
636 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
637 template <class _Up>
638 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
639 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
640 template <class _Up>
641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
642 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
643 { __t = current = __u.base(); return *this; }
644 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
645 _Iter base() const {return current;}
646 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
647 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
648 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
649 pointer operator->() const {return _VSTD::addressof(operator*());}
650 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
651 reverse_iterator& operator++() {--current; return *this;}
652 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
653 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
654 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
655 reverse_iterator& operator--() {++current; return *this;}
656 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
657 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
658 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
659 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
661 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
663 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
664 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
665 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
667 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668};
669
670template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000671inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672bool
673operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
674{
675 return __x.base() == __y.base();
676}
677
678template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000679inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680bool
681operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
682{
683 return __x.base() > __y.base();
684}
685
686template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000687inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688bool
689operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
690{
691 return __x.base() != __y.base();
692}
693
694template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000695inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696bool
697operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
698{
699 return __x.base() < __y.base();
700}
701
702template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000703inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704bool
705operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
706{
707 return __x.base() <= __y.base();
708}
709
710template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000711inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712bool
713operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
714{
715 return __x.base() >= __y.base();
716}
717
Marshall Clow3f013892016-07-18 13:19:00 +0000718#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000719template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000720inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000721auto
722operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
723-> decltype(__y.base() - __x.base())
724{
725 return __y.base() - __x.base();
726}
727#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728template <class _Iter1, class _Iter2>
729inline _LIBCPP_INLINE_VISIBILITY
730typename reverse_iterator<_Iter1>::difference_type
731operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
732{
733 return __y.base() - __x.base();
734}
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000735#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736
737template <class _Iter>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000738inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739reverse_iterator<_Iter>
740operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
741{
742 return reverse_iterator<_Iter>(__x.base() - __n);
743}
744
Marshall Clowff137e92014-03-03 01:24:04 +0000745#if _LIBCPP_STD_VER > 11
746template <class _Iter>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000747inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowff137e92014-03-03 01:24:04 +0000748reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
749{
750 return reverse_iterator<_Iter>(__i);
751}
752#endif
753
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000755class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756 : public iterator<output_iterator_tag,
757 void,
758 void,
759 void,
Eric Fiselierc848cef2016-06-30 04:40:50 +0000760 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761{
762protected:
763 _Container* container;
764public:
765 typedef _Container container_type;
766
Marshall Clow53c0e722014-03-03 19:20:40 +0000767 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000768 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
769 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000770#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000771 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
772 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000773#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
775 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
776 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
777};
778
779template <class _Container>
780inline _LIBCPP_INLINE_VISIBILITY
781back_insert_iterator<_Container>
782back_inserter(_Container& __x)
783{
784 return back_insert_iterator<_Container>(__x);
785}
786
787template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000788class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000789 : public iterator<output_iterator_tag,
790 void,
791 void,
792 void,
Eric Fiselierc848cef2016-06-30 04:40:50 +0000793 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794{
795protected:
796 _Container* container;
797public:
798 typedef _Container container_type;
799
Marshall Clow53c0e722014-03-03 19:20:40 +0000800 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000801 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
802 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000803#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000804 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
805 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000806#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
808 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
809 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
810};
811
812template <class _Container>
813inline _LIBCPP_INLINE_VISIBILITY
814front_insert_iterator<_Container>
815front_inserter(_Container& __x)
816{
817 return front_insert_iterator<_Container>(__x);
818}
819
820template <class _Container>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000821class _LIBCPP_TYPE_VIS_ONLY insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822 : public iterator<output_iterator_tag,
823 void,
824 void,
825 void,
Eric Fiselierc848cef2016-06-30 04:40:50 +0000826 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827{
828protected:
829 _Container* container;
830 typename _Container::iterator iter;
831public:
832 typedef _Container container_type;
833
834 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clow53c0e722014-03-03 19:20:40 +0000835 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000836 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
837 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000838#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45 +0000839 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
840 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000841#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
843 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
844 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
845};
846
847template <class _Container>
848inline _LIBCPP_INLINE_VISIBILITY
849insert_iterator<_Container>
850inserter(_Container& __x, typename _Container::iterator __i)
851{
852 return insert_iterator<_Container>(__x, __i);
853}
854
855template <class _Tp, class _CharT = char,
856 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000857class _LIBCPP_TYPE_VIS_ONLY istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
859{
860public:
861 typedef _CharT char_type;
862 typedef _Traits traits_type;
863 typedef basic_istream<_CharT,_Traits> istream_type;
864private:
865 istream_type* __in_stream_;
866 _Tp __value_;
867public:
Marshall Clowe9d03062015-04-16 21:36:54 +0000868 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000869 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870 {
871 if (!(*__in_stream_ >> __value_))
872 __in_stream_ = 0;
873 }
874
875 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000876 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
878 {
879 if (!(*__in_stream_ >> __value_))
880 __in_stream_ = 0;
881 return *this;
882 }
883 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
884 {istream_iterator __t(*this); ++(*this); return __t;}
885
886 friend _LIBCPP_INLINE_VISIBILITY
887 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
888 {return __x.__in_stream_ == __y.__in_stream_;}
889
890 friend _LIBCPP_INLINE_VISIBILITY
891 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
892 {return !(__x == __y);}
893};
894
895template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000896class _LIBCPP_TYPE_VIS_ONLY ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 : public iterator<output_iterator_tag, void, void, void, void>
898{
899public:
900 typedef _CharT char_type;
901 typedef _Traits traits_type;
902 typedef basic_ostream<_CharT,_Traits> ostream_type;
903private:
904 ostream_type* __out_stream_;
905 const char_type* __delim_;
906public:
Marshall Clowb6361282016-10-12 16:13:48 +0000907 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000908 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
Marshall Clowb6361282016-10-12 16:13:48 +0000909 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000910 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000911 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912 {
Howard Hinnant78b68282011-10-22 20:59:45 +0000913 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 if (__delim_)
915 *__out_stream_ << __delim_;
916 return *this;
917 }
918
919 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
920 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
921 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
922};
923
924template<class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000925class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000926 : public iterator<input_iterator_tag, _CharT,
927 typename _Traits::off_type, _CharT*,
928 _CharT>
929{
930public:
931 typedef _CharT char_type;
932 typedef _Traits traits_type;
933 typedef typename _Traits::int_type int_type;
934 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
935 typedef basic_istream<_CharT,_Traits> istream_type;
936private:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000937 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938
939 class __proxy
940 {
941 char_type __keep_;
942 streambuf_type* __sbuf_;
943 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
944 : __keep_(__c), __sbuf_(__s) {}
945 friend class istreambuf_iterator;
946 public:
947 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
948 };
949
Howard Hinnant82894812010-09-22 16:48:34 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +0000951 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000952 {
953 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
954 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +0000955 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956 }
957public:
Howard Hinnant984f10f2012-11-16 22:17:23 +0000958 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000959 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000960 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000961 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +0000962 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +0000963 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964 : __sbuf_(__p.__sbuf_) {}
965
Howard Hinnantec3773c2011-12-01 20:21:04 +0000966 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
967 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000968 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
969 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
970 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000971 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972 return *this;
973 }
974 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
975 {
Howard Hinnant984f10f2012-11-16 22:17:23 +0000976 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000977 }
978
979 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +0000980 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981};
982
983template <class _CharT, class _Traits>
984inline _LIBCPP_INLINE_VISIBILITY
985bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
986 const istreambuf_iterator<_CharT,_Traits>& __b)
987 {return __a.equal(__b);}
988
989template <class _CharT, class _Traits>
990inline _LIBCPP_INLINE_VISIBILITY
991bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
992 const istreambuf_iterator<_CharT,_Traits>& __b)
993 {return !__a.equal(__b);}
994
995template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000996class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997 : public iterator<output_iterator_tag, void, void, void, void>
998{
999public:
1000 typedef _CharT char_type;
1001 typedef _Traits traits_type;
1002 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1003 typedef basic_ostream<_CharT,_Traits> ostream_type;
1004private:
1005 streambuf_type* __sbuf_;
1006public:
Howard Hinnantd06a6402012-07-20 19:36:34 +00001007 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001008 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +00001009 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 : __sbuf_(__s) {}
1011 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1012 {
1013 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1014 __sbuf_ = 0;
1015 return *this;
1016 }
1017 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1018 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1019 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +00001020 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +00001021
Howard Hinnant537b2fa2012-11-14 21:17:15 +00001022#if !defined(__APPLE__) || \
1023 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1024 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1025
Howard Hinnanta585de62012-09-19 19:14:15 +00001026 template <class _Ch, class _Tr>
1027 friend
1028 _LIBCPP_HIDDEN
1029 ostreambuf_iterator<_Ch, _Tr>
1030 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1031 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1032 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:15 +00001033#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001034};
1035
1036template <class _Iter>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001037class _LIBCPP_TYPE_VIS_ONLY move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038{
1039private:
1040 _Iter __i;
1041public:
1042 typedef _Iter iterator_type;
1043 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1044 typedef typename iterator_traits<iterator_type>::value_type value_type;
1045 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowdca800c2016-04-11 03:54:53 +00001046 typedef iterator_type pointer;
Howard Hinnant73d21a42010-09-04 23:28:19 +00001047#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Eric Fiselierdf46b782016-04-22 00:49:12 +00001048 typedef typename iterator_traits<iterator_type>::reference __reference;
1049 typedef typename conditional<
1050 is_reference<__reference>::value,
1051 typename remove_reference<__reference>::type&&,
1052 __reference
1053 >::type reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054#else
1055 typedef typename iterator_traits<iterator_type>::reference reference;
1056#endif
Howard Hinnant324bb032010-08-22 00:02:43 +00001057
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058 _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {}
1059 _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {}
1060 template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u)
1061 : __i(__u.base()) {}
1062 _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;}
Douglas Gregoraab015a2011-01-26 00:12:48 +00001063 _LIBCPP_INLINE_VISIBILITY reference operator*() const {
1064 return static_cast<reference>(*__i);
1065 }
Marshall Clowdca800c2016-04-11 03:54:53 +00001066 _LIBCPP_INLINE_VISIBILITY pointer operator->() const { return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067 _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;}
1068 _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int)
1069 {move_iterator __tmp(*this); ++__i; return __tmp;}
1070 _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;}
1071 _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int)
1072 {move_iterator __tmp(*this); --__i; return __tmp;}
1073 _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const
1074 {return move_iterator(__i + __n);}
1075 _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n)
1076 {__i += __n; return *this;}
1077 _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const
1078 {return move_iterator(__i - __n);}
1079 _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n)
1080 {__i -= __n; return *this;}
1081 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
Douglas Gregoraab015a2011-01-26 00:12:48 +00001082 {
1083 return static_cast<reference>(__i[__n]);
1084 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085};
1086
1087template <class _Iter1, class _Iter2>
1088inline _LIBCPP_INLINE_VISIBILITY
1089bool
1090operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1091{
1092 return __x.base() == __y.base();
1093}
1094
1095template <class _Iter1, class _Iter2>
1096inline _LIBCPP_INLINE_VISIBILITY
1097bool
1098operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1099{
1100 return __x.base() < __y.base();
1101}
1102
1103template <class _Iter1, class _Iter2>
1104inline _LIBCPP_INLINE_VISIBILITY
1105bool
1106operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1107{
1108 return __x.base() != __y.base();
1109}
1110
1111template <class _Iter1, class _Iter2>
1112inline _LIBCPP_INLINE_VISIBILITY
1113bool
1114operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1115{
1116 return __x.base() > __y.base();
1117}
1118
1119template <class _Iter1, class _Iter2>
1120inline _LIBCPP_INLINE_VISIBILITY
1121bool
1122operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1123{
1124 return __x.base() >= __y.base();
1125}
1126
1127template <class _Iter1, class _Iter2>
1128inline _LIBCPP_INLINE_VISIBILITY
1129bool
1130operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1131{
1132 return __x.base() <= __y.base();
1133}
1134
Marshall Clow3f013892016-07-18 13:19:00 +00001135#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001136template <class _Iter1, class _Iter2>
1137inline _LIBCPP_INLINE_VISIBILITY
1138auto
1139operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1140-> decltype(__x.base() - __y.base())
1141{
1142 return __x.base() - __y.base();
1143}
1144#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145template <class _Iter1, class _Iter2>
1146inline _LIBCPP_INLINE_VISIBILITY
1147typename move_iterator<_Iter1>::difference_type
1148operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1149{
1150 return __x.base() - __y.base();
1151}
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001152#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153
1154template <class _Iter>
1155inline _LIBCPP_INLINE_VISIBILITY
1156move_iterator<_Iter>
1157operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1158{
1159 return move_iterator<_Iter>(__x.base() + __n);
1160}
1161
1162template <class _Iter>
1163inline _LIBCPP_INLINE_VISIBILITY
1164move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:03 +00001165make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166{
1167 return move_iterator<_Iter>(__i);
1168}
1169
1170// __wrap_iter
1171
1172template <class _Iter> class __wrap_iter;
1173
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
1189template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001190_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001192operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193
1194template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001195_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001196bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001197operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198
1199template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001200_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001202operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203
Marshall Clow3f013892016-07-18 13:19:00 +00001204#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001205template <class _Iter1, class _Iter2>
1206_LIBCPP_INLINE_VISIBILITY
1207auto
1208operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1209-> decltype(__x.base() - __y.base());
1210#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001212_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001213typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001214operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001215#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001216
1217template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001218_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001219__wrap_iter<_Iter>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001220operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221
Howard Hinnant33be35e2012-09-14 00:39:16 +00001222template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1223template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1224template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1225template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001226
1227template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001228_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001229typename enable_if
1230<
Howard Hinnant1468b662010-11-19 22:17:28 +00001231 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232 _Tp*
1233>::type
1234__unwrap_iter(__wrap_iter<_Tp*>);
1235
1236template <class _Iter>
1237class __wrap_iter
1238{
1239public:
1240 typedef _Iter iterator_type;
1241 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1242 typedef typename iterator_traits<iterator_type>::value_type value_type;
1243 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1244 typedef typename iterator_traits<iterator_type>::pointer pointer;
1245 typedef typename iterator_traits<iterator_type>::reference reference;
1246private:
1247 iterator_type __i;
1248public:
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001249 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001250#if _LIBCPP_STD_VER > 11
1251 : __i{}
1252#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001253 {
1254#if _LIBCPP_DEBUG_LEVEL >= 2
1255 __get_db()->__insert_i(this);
1256#endif
1257 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Howard Hinnanta6119a82011-05-29 19:57:12 +00001259 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001260 : __i(__u.base())
1261 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001262#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001263 __get_db()->__iterator_copy(this, &__u);
1264#endif
1265 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001266#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001267 _LIBCPP_INLINE_VISIBILITY
1268 __wrap_iter(const __wrap_iter& __x)
1269 : __i(__x.base())
1270 {
1271 __get_db()->__iterator_copy(this, &__x);
1272 }
1273 _LIBCPP_INLINE_VISIBILITY
1274 __wrap_iter& operator=(const __wrap_iter& __x)
1275 {
1276 if (this != &__x)
1277 {
1278 __get_db()->__iterator_copy(this, &__x);
1279 __i = __x.__i;
1280 }
1281 return *this;
1282 }
1283 _LIBCPP_INLINE_VISIBILITY
1284 ~__wrap_iter()
1285 {
1286 __get_db()->__erase_i(this);
1287 }
1288#endif
1289 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
1290 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001291#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001292 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1293 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001294#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001295 return *__i;
1296 }
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001297 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT
1298 {
1299#if _LIBCPP_DEBUG_LEVEL >= 2
1300 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1301 "Attempted to dereference a non-dereferenceable iterator");
1302#endif
Marshall Clowdca800c2016-04-11 03:54:53 +00001303 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001304 }
Howard Hinnant7a563db2011-09-14 18:33:51 +00001305 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
1306 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001307#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001308 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1309 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001310#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001311 ++__i;
1312 return *this;
1313 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001314 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001315 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
1316 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
1317 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001318#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001319 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1320 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001321#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001322 --__i;
1323 return *this;
1324 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001325 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001326 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001327 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001328 {__wrap_iter __w(*this); __w += __n; return __w;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001329 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001330 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001331#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001332 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1333 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001334#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001335 __i += __n;
1336 return *this;
1337 }
Howard Hinnanta6119a82011-05-29 19:57:12 +00001338 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001339 {return *this + (-__n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001340 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001341 {*this += -__n; return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001342 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001343 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001344#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001345 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1346 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001347#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001348 return __i[__n];
1349 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001350
Howard Hinnanta6119a82011-05-29 19:57:12 +00001351 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352
1353private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001354#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001355 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1356 {
1357 __get_db()->__insert_ic(this, __p);
1358 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001359#else
1360 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001361#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362
1363 template <class _Up> friend class __wrap_iter;
1364 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Marshall Clow59f573f2015-02-18 19:28:35 +00001365 template <class _Tp, class _Alloc> friend class _LIBCPP_TYPE_VIS_ONLY vector;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366
1367 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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382 template <class _Iter1, class _Iter2>
1383 friend
1384 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001385 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001386
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387 template <class _Iter1, class _Iter2>
1388 friend
1389 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001390 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001391
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001392 template <class _Iter1, class _Iter2>
1393 friend
1394 bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001395 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001396
Marshall Clow3f013892016-07-18 13:19:00 +00001397#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001398 template <class _Iter1, class _Iter2>
1399 friend
1400 auto
1401 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1402 -> decltype(__x.base() - __y.base());
1403#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404 template <class _Iter1, class _Iter2>
1405 friend
1406 typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001407 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001408#endif
Howard Hinnant324bb032010-08-22 00:02:43 +00001409
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410 template <class _Iter1>
1411 friend
1412 __wrap_iter<_Iter1>
Howard Hinnant2baccd82011-10-11 21:28:38 +00001413 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414
Howard Hinnant99968442011-11-29 18:15:50 +00001415 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001417 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1419
1420 template <class _Tp>
1421 friend
1422 typename enable_if
1423 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001424 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425 _Tp*
1426 >::type
1427 __unwrap_iter(__wrap_iter<_Tp*>);
1428};
1429
1430template <class _Iter1, class _Iter2>
1431inline _LIBCPP_INLINE_VISIBILITY
1432bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001433operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434{
1435 return __x.base() == __y.base();
1436}
1437
1438template <class _Iter1, class _Iter2>
1439inline _LIBCPP_INLINE_VISIBILITY
1440bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001441operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442{
Howard Hinnantabe26282011-09-16 17:29:17 +00001443#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001444 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001445 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001446#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447 return __x.base() < __y.base();
1448}
1449
1450template <class _Iter1, class _Iter2>
1451inline _LIBCPP_INLINE_VISIBILITY
1452bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001453operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001454{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001455 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001456}
1457
1458template <class _Iter1, class _Iter2>
1459inline _LIBCPP_INLINE_VISIBILITY
1460bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001461operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001463 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001464}
1465
1466template <class _Iter1, class _Iter2>
1467inline _LIBCPP_INLINE_VISIBILITY
1468bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001469operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001470{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001471 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472}
1473
1474template <class _Iter1, class _Iter2>
1475inline _LIBCPP_INLINE_VISIBILITY
1476bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00001477operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001478{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001479 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001480}
1481
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001482template <class _Iter1>
1483inline _LIBCPP_INLINE_VISIBILITY
1484bool
1485operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1486{
1487 return !(__x == __y);
1488}
1489
1490template <class _Iter1>
1491inline _LIBCPP_INLINE_VISIBILITY
1492bool
1493operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1494{
1495 return __y < __x;
1496}
1497
1498template <class _Iter1>
1499inline _LIBCPP_INLINE_VISIBILITY
1500bool
1501operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1502{
1503 return !(__x < __y);
1504}
1505
1506template <class _Iter1>
1507inline _LIBCPP_INLINE_VISIBILITY
1508bool
1509operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
1510{
1511 return !(__y < __x);
1512}
1513
Marshall Clow3f013892016-07-18 13:19:00 +00001514#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001515template <class _Iter1, class _Iter2>
1516inline _LIBCPP_INLINE_VISIBILITY
1517auto
1518operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1519-> decltype(__x.base() - __y.base())
1520{
1521#if _LIBCPP_DEBUG_LEVEL >= 2
1522 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1523 "Attempted to subtract incompatible iterators");
1524#endif
1525 return __x.base() - __y.base();
1526}
1527#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528template <class _Iter1, class _Iter2>
1529inline _LIBCPP_INLINE_VISIBILITY
1530typename __wrap_iter<_Iter1>::difference_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00001531operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532{
Howard Hinnantabe26282011-09-16 17:29:17 +00001533#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001534 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001535 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001536#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001537 return __x.base() - __y.base();
1538}
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001539#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001540
1541template <class _Iter>
1542inline _LIBCPP_INLINE_VISIBILITY
1543__wrap_iter<_Iter>
1544operator+(typename __wrap_iter<_Iter>::difference_type __n,
Howard Hinnant7a563db2011-09-14 18:33:51 +00001545 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001546{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001547 __x += __n;
1548 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001549}
1550
Marshall Clowdf9db312016-01-13 21:54:34 +00001551template <class _Iter>
1552struct __libcpp_is_trivial_iterator
1553 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1554
1555template <class _Iter>
1556struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
1557 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1558
1559template <class _Iter>
1560struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
1561 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1562
1563template <class _Iter>
1564struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
1565 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
1566
1567
Marshall Clow6daf5342013-12-02 03:24:33 +00001568template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001569inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001570_Tp*
1571begin(_Tp (&__array)[_Np])
1572{
1573 return __array;
1574}
1575
1576template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001577inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001578_Tp*
1579end(_Tp (&__array)[_Np])
1580{
1581 return __array + _Np;
1582}
1583
Eric Fiselier4e3e15a2016-09-25 03:34:28 +00001584#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow1c398692013-12-11 19:32:32 +00001585
Howard Hinnant99968442011-11-29 18:15:50 +00001586template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001587inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588auto
Howard Hinnant99968442011-11-29 18:15:50 +00001589begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590{
1591 return __c.begin();
1592}
1593
Howard Hinnant99968442011-11-29 18:15:50 +00001594template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001595inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001596auto
Howard Hinnant99968442011-11-29 18:15:50 +00001597begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598{
1599 return __c.begin();
1600}
1601
Howard Hinnant99968442011-11-29 18:15:50 +00001602template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604auto
Howard Hinnant99968442011-11-29 18:15:50 +00001605end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606{
1607 return __c.end();
1608}
1609
Howard Hinnant99968442011-11-29 18:15:50 +00001610template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001611inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612auto
Howard Hinnant99968442011-11-29 18:15:50 +00001613end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614{
1615 return __c.end();
1616}
1617
Marshall Clow09da3c02013-08-30 01:17:07 +00001618#if _LIBCPP_STD_VER > 11
1619
Marshall Clow6daf5342013-12-02 03:24:33 +00001620template <class _Tp, size_t _Np>
1621inline _LIBCPP_INLINE_VISIBILITY
1622reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1623{
1624 return reverse_iterator<_Tp*>(__array + _Np);
1625}
1626
1627template <class _Tp, size_t _Np>
1628inline _LIBCPP_INLINE_VISIBILITY
1629reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1630{
1631 return reverse_iterator<_Tp*>(__array);
1632}
1633
1634template <class _Ep>
1635inline _LIBCPP_INLINE_VISIBILITY
1636reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1637{
1638 return reverse_iterator<const _Ep*>(__il.end());
1639}
1640
1641template <class _Ep>
1642inline _LIBCPP_INLINE_VISIBILITY
1643reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1644{
1645 return reverse_iterator<const _Ep*>(__il.begin());
1646}
1647
Marshall Clow09da3c02013-08-30 01:17:07 +00001648template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001649inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow02e94f82016-08-10 20:04:46 +00001650auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clow09da3c02013-08-30 01:17:07 +00001651{
Marshall Clow02e94f82016-08-10 20:04:46 +00001652 return _VSTD::begin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001653}
1654
1655template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:30 +00001656inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow02e94f82016-08-10 20:04:46 +00001657auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clow09da3c02013-08-30 01:17:07 +00001658{
Marshall Clow02e94f82016-08-10 20:04:46 +00001659 return _VSTD::end(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001660}
1661
1662template <class _Cp>
1663inline _LIBCPP_INLINE_VISIBILITY
1664auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1665{
1666 return __c.rbegin();
1667}
1668
1669template <class _Cp>
1670inline _LIBCPP_INLINE_VISIBILITY
1671auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1672{
1673 return __c.rbegin();
1674}
1675
1676template <class _Cp>
1677inline _LIBCPP_INLINE_VISIBILITY
1678auto rend(_Cp& __c) -> decltype(__c.rend())
1679{
1680 return __c.rend();
1681}
1682
1683template <class _Cp>
1684inline _LIBCPP_INLINE_VISIBILITY
1685auto rend(const _Cp& __c) -> decltype(__c.rend())
1686{
1687 return __c.rend();
1688}
1689
1690template <class _Cp>
1691inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow02e94f82016-08-10 20:04:46 +00001692auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clow09da3c02013-08-30 01:17:07 +00001693{
Marshall Clow02e94f82016-08-10 20:04:46 +00001694 return _VSTD::rbegin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001695}
1696
1697template <class _Cp>
1698inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow02e94f82016-08-10 20:04:46 +00001699auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clow09da3c02013-08-30 01:17:07 +00001700{
Marshall Clow02e94f82016-08-10 20:04:46 +00001701 return _VSTD::rend(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001702}
1703
1704#endif
1705
1706
Eric Fiselier4e3e15a2016-09-25 03:34:28 +00001707#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001708
Howard Hinnant99968442011-11-29 18:15:50 +00001709template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001710inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001711typename _Cp::iterator
1712begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713{
1714 return __c.begin();
1715}
1716
Howard Hinnant99968442011-11-29 18:15:50 +00001717template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001718inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001719typename _Cp::const_iterator
1720begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721{
1722 return __c.begin();
1723}
1724
Howard Hinnant99968442011-11-29 18:15:50 +00001725template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001726inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001727typename _Cp::iterator
1728end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001729{
1730 return __c.end();
1731}
1732
Howard Hinnant99968442011-11-29 18:15:50 +00001733template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:34 +00001734inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001735typename _Cp::const_iterator
1736end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737{
1738 return __c.end();
1739}
1740
Eric Fiselier4e3e15a2016-09-25 03:34:28 +00001741#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742
Marshall Clow03c67912014-11-19 19:43:23 +00001743#if _LIBCPP_STD_VER > 14
Marshall Clow35e462d2015-02-11 16:14:01 +00001744template <class _Cont>
1745constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001746
Marshall Clow35e462d2015-02-11 16:14:01 +00001747template <class _Tp, size_t _Sz>
1748constexpr size_t size(const _Tp (&__array)[_Sz]) noexcept { return _Sz; }
Marshall Clow03c67912014-11-19 19:43:23 +00001749
Marshall Clow35e462d2015-02-11 16:14:01 +00001750template <class _Cont>
1751constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001752
Marshall Clow35e462d2015-02-11 16:14:01 +00001753template <class _Tp, size_t _Sz>
1754constexpr bool empty(const _Tp (&__array)[_Sz]) noexcept { return false; }
Marshall Clow03c67912014-11-19 19:43:23 +00001755
1756template <class _Ep>
1757constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1758
Marshall Clow35e462d2015-02-11 16:14:01 +00001759template <class _Cont> constexpr
1760auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001761
Marshall Clow35e462d2015-02-11 16:14:01 +00001762template <class _Cont> constexpr
1763auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001764
Marshall Clow35e462d2015-02-11 16:14:01 +00001765template <class _Tp, size_t _Sz>
1766constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clow03c67912014-11-19 19:43:23 +00001767
1768template <class _Ep>
1769constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1770#endif
1771
1772
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001773_LIBCPP_END_NAMESPACE_STD
1774
1775#endif // _LIBCPP_ITERATOR