blob: 66d1a310d22fb24e30a899b30612523cc73794d8 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// 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:168//
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:4391
Marshall Clow4414a6a2016-10-19 15:12:5092 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:16108};
109
110template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50111constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16112operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
113
114template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50115constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16116operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
117
118template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50119constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16120operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
121
122template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50123constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16124operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
125
126template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50127constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16128operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
129
130template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50131constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16132operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
133
134template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50135constexpr auto
Marshall Clowdf4a22d2016-07-08 16:54:47136operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow4414a6a2016-10-19 15:12:50137-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16138
139template <class Iterator>
Marshall Clow4414a6a2016-10-19 15:12:50140constexpr 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:16143
Marshall Clow4414a6a2016-10-19 15:12:50144template <class Iterator>
145constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clowff137e92014-03-03 01:24:04146
Howard Hinnantbc8d3f92010-05-11 19:42:16147template <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:50156 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16157 typedef void pointer;
158
159 explicit back_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27160 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16161 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:50177 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16178 typedef void pointer;
179
180 explicit front_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27181 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16182 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:50199 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16200 typedef void pointer;
201
202 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant45f57172010-09-14 20:26:27203 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16204 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:47212template <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
Marshall Clowf333bee2016-11-02 15:30:26222 constexpr move_iterator(); // all the constexprs are in C++17
223 constexpr explicit move_iterator(Iterator i);
224 template <class U>
225 constexpr move_iterator(const move_iterator<U>& u);
226 template <class U>
227 constexpr move_iterator& operator=(const move_iterator<U>& u);
228 constexpr iterator_type base() const;
229 constexpr reference operator*() const;
230 constexpr pointer operator->() const;
231 constexpr move_iterator& operator++();
232 constexpr move_iterator operator++(int);
233 constexpr move_iterator& operator--();
234 constexpr move_iterator operator--(int);
235 constexpr move_iterator operator+(difference_type n) const;
236 constexpr move_iterator& operator+=(difference_type n);
237 constexpr move_iterator operator-(difference_type n) const;
238 constexpr move_iterator& operator-=(difference_type n);
239 constexpr unspecified operator[](difference_type n) const;
Marshall Clowdf4a22d2016-07-08 16:54:47240private:
241 Iterator current; // exposition only
242};
243
244template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26245constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47246operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
247
248template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26249constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47250operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
251
252template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26253constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47254operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
255
256template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26257constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47258operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
259
260template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26261constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47262operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
263
264template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26265constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47266operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
267
268template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26269constexpr auto // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47270operator-(const move_iterator<Iterator1>& x,
271 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
272
273template <class Iterator>
Marshall Clowf333bee2016-11-02 15:30:26274constexpr move_iterator<Iterator> operator+( // constexpr in C++17
275 typename move_iterator<Iterator>::difference_type n,
276 const move_iterator<Iterator>& x);
Marshall Clowdf4a22d2016-07-08 16:54:47277
Marshall Clowf333bee2016-11-02 15:30:26278template <class Iterator> // constexpr in C++17
279constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowdf4a22d2016-07-08 16:54:47280
281
Howard Hinnantbc8d3f92010-05-11 19:42:16282template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
283class istream_iterator
284 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
285{
286public:
287 typedef charT char_type;
288 typedef traits traits_type;
289 typedef basic_istream<charT,traits> istream_type;
290
Marshall Clowe9d03062015-04-16 21:36:54291 constexpr istream_iterator();
Howard Hinnantbc8d3f92010-05-11 19:42:16292 istream_iterator(istream_type& s);
293 istream_iterator(const istream_iterator& x);
294 ~istream_iterator();
295
296 const T& operator*() const;
297 const T* operator->() const;
298 istream_iterator& operator++();
299 istream_iterator operator++(int);
300};
301
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);
305template <class T, class charT, class traits, class Distance>
306bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
307 const istream_iterator<T,charT,traits,Distance>& y);
308
309template <class T, class charT = char, class traits = char_traits<charT> >
310class ostream_iterator
311 : public iterator<output_iterator_tag, void, void, void ,void>
312{
313public:
314 typedef charT char_type;
315 typedef traits traits_type;
316 typedef basic_ostream<charT,traits> ostream_type;
317
318 ostream_iterator(ostream_type& s);
319 ostream_iterator(ostream_type& s, const charT* delimiter);
320 ostream_iterator(const ostream_iterator& x);
321 ~ostream_iterator();
322 ostream_iterator& operator=(const T& value);
323
324 ostream_iterator& operator*();
325 ostream_iterator& operator++();
326 ostream_iterator& operator++(int);
327};
328
329template<class charT, class traits = char_traits<charT> >
330class istreambuf_iterator
331 : public iterator<input_iterator_tag, charT,
332 typename traits::off_type, unspecified,
333 charT>
334{
335public:
336 typedef charT char_type;
337 typedef traits traits_type;
338 typedef typename traits::int_type int_type;
339 typedef basic_streambuf<charT,traits> streambuf_type;
340 typedef basic_istream<charT,traits> istream_type;
341
Howard Hinnantd06a6402012-07-20 19:36:34342 istreambuf_iterator() noexcept;
343 istreambuf_iterator(istream_type& s) noexcept;
344 istreambuf_iterator(streambuf_type* s) noexcept;
345 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16346
347 charT operator*() const;
348 pointer operator->() const;
349 istreambuf_iterator& operator++();
350 a-private-type operator++(int);
351
352 bool equal(const istreambuf_iterator& b) const;
353};
354
355template <class charT, class traits>
356bool operator==(const istreambuf_iterator<charT,traits>& a,
357 const istreambuf_iterator<charT,traits>& b);
358template <class charT, class traits>
359bool operator!=(const istreambuf_iterator<charT,traits>& a,
360 const istreambuf_iterator<charT,traits>& b);
361
362template <class charT, class traits = char_traits<charT> >
363class ostreambuf_iterator
364 : public iterator<output_iterator_tag, void, void, void, void>
365{
366public:
367 typedef charT char_type;
368 typedef traits traits_type;
369 typedef basic_streambuf<charT,traits> streambuf_type;
370 typedef basic_ostream<charT,traits> ostream_type;
371
Howard Hinnantd06a6402012-07-20 19:36:34372 ostreambuf_iterator(ostream_type& s) noexcept;
373 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16374 ostreambuf_iterator& operator=(charT c);
375 ostreambuf_iterator& operator*();
376 ostreambuf_iterator& operator++();
377 ostreambuf_iterator& operator++(int);
Howard Hinnantd06a6402012-07-20 19:36:34378 bool failed() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16379};
380
Marshall Clowe22af6b2017-01-04 17:58:17381template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
382template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
383template <class C> constexpr auto end(C& c) -> decltype(c.end());
384template <class C> constexpr auto end(const C& c) -> decltype(c.end());
385template <class T, size_t N> constexpr T* begin(T (&array)[N]);
386template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantbc8d3f92010-05-11 19:42:16387
Marshall Clowe22af6b2017-01-04 17:58:17388template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
389template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
390template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
391template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
392template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
393template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
394template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
395template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
396template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
397template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
398template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
399template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clow09da3c02013-08-30 01:17:07400
Marshall Clow03c67912014-11-19 19:43:23401// 24.8, container access:
402template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
403template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
404template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
405template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
406template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
407template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
408template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
409template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
410template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
411
Howard Hinnantbc8d3f92010-05-11 19:42:16412} // std
413
414*/
415
416#include <__config>
Eric Fiselierb3792282016-02-20 00:19:45417#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow02ca8af2014-02-27 02:11:50418#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16419#include <type_traits>
420#include <cstddef>
Marshall Clow09da3c02013-08-30 01:17:07421#include <initializer_list>
Marshall Clowdece7fe2013-03-18 17:45:34422#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15423#include <Availability.h>
424#endif
425
Eric Fiselierb9536102014-08-10 23:53:08426#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16427
Howard Hinnant08e17472011-10-17 20:05:10428#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16429#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10430#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16431
432_LIBCPP_BEGIN_NAMESPACE_STD
433
Eric Fiselierc3589a82017-01-04 23:56:00434struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
435struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
436struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
437struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
438struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16439
440template <class _Tp>
441struct __has_iterator_category
442{
443private:
Howard Hinnant9c0df142012-10-30 19:06:59444 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16445 template <class _Up> static __two __test(...);
446 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
447public:
448 static const bool value = sizeof(__test<_Tp>(0)) == 1;
449};
450
Marshall Clowa71f9562014-01-03 22:55:49451template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantbc8d3f92010-05-11 19:42:16452
453template <class _Iter>
Marshall Clowa71f9562014-01-03 22:55:49454struct __iterator_traits_impl<_Iter, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16455{
456 typedef typename _Iter::difference_type difference_type;
457 typedef typename _Iter::value_type value_type;
458 typedef typename _Iter::pointer pointer;
459 typedef typename _Iter::reference reference;
460 typedef typename _Iter::iterator_category iterator_category;
461};
462
463template <class _Iter, bool> struct __iterator_traits {};
464
465template <class _Iter>
466struct __iterator_traits<_Iter, true>
Marshall Clowa71f9562014-01-03 22:55:49467 : __iterator_traits_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16468 <
469 _Iter,
470 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
471 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
472 >
473{};
474
475// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
476// exists. Else iterator_traits<Iterator> will be an empty class. This is a
477// conforming extension which allows some programs to compile and behave as
478// the client expects instead of failing at compile time.
479
480template <class _Iter>
Eric Fiselierc3589a82017-01-04 23:56:00481struct _LIBCPP_TEMPLATE_VIS iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16482 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
483
484template<class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00485struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16486{
487 typedef ptrdiff_t difference_type;
488 typedef typename remove_const<_Tp>::type value_type;
489 typedef _Tp* pointer;
490 typedef _Tp& reference;
491 typedef random_access_iterator_tag iterator_category;
492};
493
494template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
495struct __has_iterator_category_convertible_to
496 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
497{};
498
499template <class _Tp, class _Up>
500struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
501
502template <class _Tp>
503struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
504
505template <class _Tp>
506struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
507
508template <class _Tp>
509struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
510
511template <class _Tp>
512struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
513
Marshall Clowdf9db312016-01-13 21:54:34514template <class _Tp>
515struct __is_exactly_input_iterator
516 : public integral_constant<bool,
Marshall Clowf333bee2016-11-02 15:30:26517 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
518 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
Marshall Clowdf9db312016-01-13 21:54:34519
Howard Hinnantbc8d3f92010-05-11 19:42:16520template<class _Category, class _Tp, class _Distance = ptrdiff_t,
521 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierc3589a82017-01-04 23:56:00522struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16523{
524 typedef _Tp value_type;
525 typedef _Distance difference_type;
526 typedef _Pointer pointer;
527 typedef _Reference reference;
528 typedef _Category iterator_category;
529};
530
531template <class _InputIter>
532inline _LIBCPP_INLINE_VISIBILITY
533void __advance(_InputIter& __i,
534 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
535{
536 for (; __n > 0; --__n)
537 ++__i;
538}
539
540template <class _BiDirIter>
541inline _LIBCPP_INLINE_VISIBILITY
542void __advance(_BiDirIter& __i,
543 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
544{
545 if (__n >= 0)
546 for (; __n > 0; --__n)
547 ++__i;
548 else
549 for (; __n < 0; ++__n)
550 --__i;
551}
552
553template <class _RandIter>
554inline _LIBCPP_INLINE_VISIBILITY
555void __advance(_RandIter& __i,
556 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
557{
558 __i += __n;
559}
560
561template <class _InputIter>
562inline _LIBCPP_INLINE_VISIBILITY
563void advance(_InputIter& __i,
564 typename iterator_traits<_InputIter>::difference_type __n)
565{
566 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
567}
568
569template <class _InputIter>
570inline _LIBCPP_INLINE_VISIBILITY
571typename iterator_traits<_InputIter>::difference_type
572__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
573{
574 typename iterator_traits<_InputIter>::difference_type __r(0);
575 for (; __first != __last; ++__first)
576 ++__r;
577 return __r;
578}
579
580template <class _RandIter>
581inline _LIBCPP_INLINE_VISIBILITY
582typename iterator_traits<_RandIter>::difference_type
583__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
584{
585 return __last - __first;
586}
587
588template <class _InputIter>
589inline _LIBCPP_INLINE_VISIBILITY
590typename iterator_traits<_InputIter>::difference_type
591distance(_InputIter __first, _InputIter __last)
592{
593 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
594}
595
Marshall Clowe9ef9882015-11-07 17:48:49596template <class _InputIter>
Howard Hinnant82894812010-09-22 16:48:34597inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe9ef9882015-11-07 17:48:49598_InputIter
599next(_InputIter __x,
600 typename iterator_traits<_InputIter>::difference_type __n = 1,
601 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16602{
Howard Hinnant0949eed2011-06-30 21:18:19603 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16604 return __x;
605}
606
607template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34608inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16609_BidiretionalIter
610prev(_BidiretionalIter __x,
611 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
612 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
613{
Howard Hinnant0949eed2011-06-30 21:18:19614 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16615 return __x;
616}
617
Eric Fiselier706e2c72017-04-13 02:54:13618
619template <class _Tp, class = void>
620struct __is_stashing_iterator : false_type {};
621
622template <class _Tp>
623struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
624 : true_type {};
625
Howard Hinnantbc8d3f92010-05-11 19:42:16626template <class _Iter>
Eric Fiselierc3589a82017-01-04 23:56:00627class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16628 : public iterator<typename iterator_traits<_Iter>::iterator_category,
629 typename iterator_traits<_Iter>::value_type,
630 typename iterator_traits<_Iter>::difference_type,
631 typename iterator_traits<_Iter>::pointer,
632 typename iterator_traits<_Iter>::reference>
633{
Marshall Clow668a1d82014-03-11 22:05:31634private:
Marshall Clow4414a6a2016-10-19 15:12:50635 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier706e2c72017-04-13 02:54:13636
637 static_assert(!__is_stashing_iterator<_Iter>::value,
638 "The specified iterator type cannot be used with reverse_iterator; "
639 "Using stashing iterators with reverse_iterator causes undefined behavior");
640
Marshall Clow5a8e27b2014-03-12 01:19:36641protected:
642 _Iter current;
Howard Hinnantbc8d3f92010-05-11 19:42:16643public:
644 typedef _Iter iterator_type;
645 typedef typename iterator_traits<_Iter>::difference_type difference_type;
646 typedef typename iterator_traits<_Iter>::reference reference;
647 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43648
Marshall Clow4414a6a2016-10-19 15:12:50649 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
650 reverse_iterator() : __t(), current() {}
651 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
652 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
653 template <class _Up>
654 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
655 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
656 template <class _Up>
657 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
658 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
659 { __t = current = __u.base(); return *this; }
660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
661 _Iter base() const {return current;}
662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
663 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
664 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
665 pointer operator->() const {return _VSTD::addressof(operator*());}
666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
667 reverse_iterator& operator++() {--current; return *this;}
668 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
669 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
670 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
671 reverse_iterator& operator--() {++current; return *this;}
672 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
673 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
674 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
675 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
676 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
677 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
678 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
679 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
681 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
682 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
683 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16684};
685
686template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50687inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16688bool
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:50695inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16696bool
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:50703inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16704bool
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:50711inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16712bool
713operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
714{
715 return __x.base() < __y.base();
716}
717
718template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50719inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16720bool
721operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
722{
723 return __x.base() <= __y.base();
724}
725
726template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50727inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16728bool
729operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
730{
731 return __x.base() >= __y.base();
732}
733
Marshall Clow3f013892016-07-18 13:19:00734#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47735template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50736inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowdf4a22d2016-07-08 16:54:47737auto
738operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
739-> decltype(__y.base() - __x.base())
740{
741 return __y.base() - __x.base();
742}
743#else
Howard Hinnantbc8d3f92010-05-11 19:42:16744template <class _Iter1, class _Iter2>
745inline _LIBCPP_INLINE_VISIBILITY
746typename reverse_iterator<_Iter1>::difference_type
747operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
748{
749 return __y.base() - __x.base();
750}
Marshall Clowdf4a22d2016-07-08 16:54:47751#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16752
753template <class _Iter>
Marshall Clow4414a6a2016-10-19 15:12:50754inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16755reverse_iterator<_Iter>
756operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
757{
758 return reverse_iterator<_Iter>(__x.base() - __n);
759}
760
Marshall Clowff137e92014-03-03 01:24:04761#if _LIBCPP_STD_VER > 11
762template <class _Iter>
Marshall Clow4414a6a2016-10-19 15:12:50763inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowff137e92014-03-03 01:24:04764reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
765{
766 return reverse_iterator<_Iter>(__i);
767}
768#endif
769
Howard Hinnantbc8d3f92010-05-11 19:42:16770template <class _Container>
Eric Fiselierc3589a82017-01-04 23:56:00771class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16772 : public iterator<output_iterator_tag,
773 void,
774 void,
775 void,
Eric Fiselierc848cef2016-06-30 04:40:50776 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16777{
778protected:
779 _Container* container;
780public:
781 typedef _Container container_type;
782
Marshall Clow53c0e722014-03-03 19:20:40783 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45784 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
785 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19786#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45787 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
788 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19789#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16790 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
791 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
792 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
793};
794
795template <class _Container>
796inline _LIBCPP_INLINE_VISIBILITY
797back_insert_iterator<_Container>
798back_inserter(_Container& __x)
799{
800 return back_insert_iterator<_Container>(__x);
801}
802
803template <class _Container>
Eric Fiselierc3589a82017-01-04 23:56:00804class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16805 : public iterator<output_iterator_tag,
806 void,
807 void,
808 void,
Eric Fiselierc848cef2016-06-30 04:40:50809 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16810{
811protected:
812 _Container* container;
813public:
814 typedef _Container container_type;
815
Marshall Clow53c0e722014-03-03 19:20:40816 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45817 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
818 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19819#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45820 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
821 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19822#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16823 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
824 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
825 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
826};
827
828template <class _Container>
829inline _LIBCPP_INLINE_VISIBILITY
830front_insert_iterator<_Container>
831front_inserter(_Container& __x)
832{
833 return front_insert_iterator<_Container>(__x);
834}
835
836template <class _Container>
Eric Fiselierc3589a82017-01-04 23:56:00837class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16838 : public iterator<output_iterator_tag,
839 void,
840 void,
841 void,
Eric Fiselierc848cef2016-06-30 04:40:50842 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16843{
844protected:
845 _Container* container;
846 typename _Container::iterator iter;
847public:
848 typedef _Container container_type;
849
850 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clow53c0e722014-03-03 19:20:40851 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45852 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
853 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19854#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45855 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
856 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19857#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16858 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
859 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
860 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
861};
862
863template <class _Container>
864inline _LIBCPP_INLINE_VISIBILITY
865insert_iterator<_Container>
866inserter(_Container& __x, typename _Container::iterator __i)
867{
868 return insert_iterator<_Container>(__x, __i);
869}
870
871template <class _Tp, class _CharT = char,
872 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierc3589a82017-01-04 23:56:00873class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16874 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
875{
876public:
877 typedef _CharT char_type;
878 typedef _Traits traits_type;
879 typedef basic_istream<_CharT,_Traits> istream_type;
880private:
881 istream_type* __in_stream_;
882 _Tp __value_;
883public:
Marshall Clowe9d03062015-04-16 21:36:54884 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
Marshall Clowd8fc1ec2016-05-17 17:44:40885 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantbc8d3f92010-05-11 19:42:16886 {
887 if (!(*__in_stream_ >> __value_))
888 __in_stream_ = 0;
889 }
890
891 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowd8fc1ec2016-05-17 17:44:40892 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantbc8d3f92010-05-11 19:42:16893 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
894 {
895 if (!(*__in_stream_ >> __value_))
896 __in_stream_ = 0;
897 return *this;
898 }
899 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
900 {istream_iterator __t(*this); ++(*this); return __t;}
901
902 friend _LIBCPP_INLINE_VISIBILITY
903 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
904 {return __x.__in_stream_ == __y.__in_stream_;}
905
906 friend _LIBCPP_INLINE_VISIBILITY
907 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
908 {return !(__x == __y);}
909};
910
911template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierc3589a82017-01-04 23:56:00912class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16913 : public iterator<output_iterator_tag, void, void, void, void>
914{
915public:
916 typedef _CharT char_type;
917 typedef _Traits traits_type;
918 typedef basic_ostream<_CharT,_Traits> ostream_type;
919private:
920 ostream_type* __out_stream_;
921 const char_type* __delim_;
922public:
Marshall Clowb6361282016-10-12 16:13:48923 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Marshall Clowd8fc1ec2016-05-17 17:44:40924 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
Marshall Clowb6361282016-10-12 16:13:48925 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowd8fc1ec2016-05-17 17:44:40926 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45927 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16928 {
Howard Hinnant78b68282011-10-22 20:59:45929 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16930 if (__delim_)
931 *__out_stream_ << __delim_;
932 return *this;
933 }
934
935 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
936 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
937 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
938};
939
940template<class _CharT, class _Traits>
Eric Fiselierc3589a82017-01-04 23:56:00941class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16942 : public iterator<input_iterator_tag, _CharT,
943 typename _Traits::off_type, _CharT*,
944 _CharT>
945{
946public:
947 typedef _CharT char_type;
948 typedef _Traits traits_type;
949 typedef typename _Traits::int_type int_type;
950 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
951 typedef basic_istream<_CharT,_Traits> istream_type;
952private:
Howard Hinnant984f10f2012-11-16 22:17:23953 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16954
955 class __proxy
956 {
957 char_type __keep_;
958 streambuf_type* __sbuf_;
959 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
960 : __keep_(__c), __sbuf_(__s) {}
961 friend class istreambuf_iterator;
962 public:
963 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
964 };
965
Howard Hinnant82894812010-09-22 16:48:34966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23967 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16968 {
969 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
970 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23971 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16972 }
973public:
Howard Hinnant984f10f2012-11-16 22:17:23974 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34975 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42976 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34977 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42978 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34979 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16980 : __sbuf_(__p.__sbuf_) {}
981
Howard Hinnantec3773c2011-12-01 20:21:04982 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
983 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16984 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
985 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
986 {
Howard Hinnant984f10f2012-11-16 22:17:23987 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16988 return *this;
989 }
990 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
991 {
Howard Hinnant984f10f2012-11-16 22:17:23992 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16993 }
994
995 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23996 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16997};
998
999template <class _CharT, class _Traits>
1000inline _LIBCPP_INLINE_VISIBILITY
1001bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1002 const istreambuf_iterator<_CharT,_Traits>& __b)
1003 {return __a.equal(__b);}
1004
1005template <class _CharT, class _Traits>
1006inline _LIBCPP_INLINE_VISIBILITY
1007bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1008 const istreambuf_iterator<_CharT,_Traits>& __b)
1009 {return !__a.equal(__b);}
1010
1011template <class _CharT, class _Traits>
Eric Fiselierc3589a82017-01-04 23:56:001012class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:161013 : public iterator<output_iterator_tag, void, void, void, void>
1014{
1015public:
1016 typedef _CharT char_type;
1017 typedef _Traits traits_type;
1018 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1019 typedef basic_ostream<_CharT,_Traits> ostream_type;
1020private:
1021 streambuf_type* __sbuf_;
1022public:
Howard Hinnantd06a6402012-07-20 19:36:341023 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161024 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:341025 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161026 : __sbuf_(__s) {}
1027 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1028 {
1029 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1030 __sbuf_ = 0;
1031 return *this;
1032 }
1033 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1034 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1035 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:341036 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:151037
Howard Hinnant537b2fa2012-11-14 21:17:151038#if !defined(__APPLE__) || \
1039 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1040 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1041
Howard Hinnanta585de62012-09-19 19:14:151042 template <class _Ch, class _Tr>
1043 friend
1044 _LIBCPP_HIDDEN
1045 ostreambuf_iterator<_Ch, _Tr>
1046 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1047 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1048 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:151049#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161050};
1051
1052template <class _Iter>
Eric Fiselierc3589a82017-01-04 23:56:001053class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:161054{
1055private:
1056 _Iter __i;
1057public:
1058 typedef _Iter iterator_type;
1059 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1060 typedef typename iterator_traits<iterator_type>::value_type value_type;
1061 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowdca800c2016-04-11 03:54:531062 typedef iterator_type pointer;
Howard Hinnant73d21a42010-09-04 23:28:191063#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Eric Fiselierdf46b782016-04-22 00:49:121064 typedef typename iterator_traits<iterator_type>::reference __reference;
1065 typedef typename conditional<
1066 is_reference<__reference>::value,
1067 typename remove_reference<__reference>::type&&,
1068 __reference
1069 >::type reference;
Howard Hinnantbc8d3f92010-05-11 19:42:161070#else
1071 typedef typename iterator_traits<iterator_type>::reference reference;
1072#endif
Howard Hinnant324bb032010-08-22 00:02:431073
Marshall Clowf333bee2016-11-02 15:30:261074 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1075 move_iterator() : __i() {}
1076 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1077 explicit move_iterator(_Iter __x) : __i(__x) {}
1078 template <class _Up>
1079 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1080 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1081 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1082 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1083 reference operator*() const { return static_cast<reference>(*__i); }
1084 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1085 pointer operator->() const { return __i;}
1086 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1087 move_iterator& operator++() {++__i; return *this;}
1088 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1089 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1090 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1091 move_iterator& operator--() {--__i; return *this;}
1092 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1093 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1095 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1096 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1097 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1098 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1099 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1100 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1101 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1102 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1103 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantbc8d3f92010-05-11 19:42:161104};
1105
1106template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261107inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161108bool
1109operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1110{
1111 return __x.base() == __y.base();
1112}
1113
1114template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261115inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161116bool
1117operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1118{
1119 return __x.base() < __y.base();
1120}
1121
1122template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261123inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161124bool
1125operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1126{
1127 return __x.base() != __y.base();
1128}
1129
1130template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261131inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161132bool
1133operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1134{
1135 return __x.base() > __y.base();
1136}
1137
1138template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261139inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161140bool
1141operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1142{
1143 return __x.base() >= __y.base();
1144}
1145
1146template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261147inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161148bool
1149operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1150{
1151 return __x.base() <= __y.base();
1152}
1153
Marshall Clow3f013892016-07-18 13:19:001154#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:471155template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261156inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowdf4a22d2016-07-08 16:54:471157auto
1158operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1159-> decltype(__x.base() - __y.base())
1160{
1161 return __x.base() - __y.base();
1162}
1163#else
Howard Hinnantbc8d3f92010-05-11 19:42:161164template <class _Iter1, class _Iter2>
1165inline _LIBCPP_INLINE_VISIBILITY
1166typename move_iterator<_Iter1>::difference_type
1167operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1168{
1169 return __x.base() - __y.base();
1170}
Marshall Clowdf4a22d2016-07-08 16:54:471171#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161172
1173template <class _Iter>
Marshall Clowf333bee2016-11-02 15:30:261174inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161175move_iterator<_Iter>
1176operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1177{
1178 return move_iterator<_Iter>(__x.base() + __n);
1179}
1180
1181template <class _Iter>
Marshall Clowf333bee2016-11-02 15:30:261182inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161183move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:031184make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:161185{
1186 return move_iterator<_Iter>(__i);
1187}
1188
1189// __wrap_iter
1190
1191template <class _Iter> class __wrap_iter;
1192
1193template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161194_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161195bool
Eric Fiselier2c8aa052016-12-28 05:35:321196operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161197
1198template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161199_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161200bool
Eric Fiselier2c8aa052016-12-28 05:35:321201operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161202
1203template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161204_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161205bool
Eric Fiselier2c8aa052016-12-28 05:35:321206operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161207
1208template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161209_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161210bool
Eric Fiselier2c8aa052016-12-28 05:35:321211operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161212
1213template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161214_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161215bool
Eric Fiselier2c8aa052016-12-28 05:35:321216operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161217
1218template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161219_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161220bool
Eric Fiselier2c8aa052016-12-28 05:35:321221operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161222
Marshall Clow3f013892016-07-18 13:19:001223#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:471224template <class _Iter1, class _Iter2>
1225_LIBCPP_INLINE_VISIBILITY
1226auto
Eric Fiselier2c8aa052016-12-28 05:35:321227operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Marshall Clowdf4a22d2016-07-08 16:54:471228-> decltype(__x.base() - __y.base());
1229#else
Howard Hinnantbc8d3f92010-05-11 19:42:161230template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161231_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161232typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier2c8aa052016-12-28 05:35:321233operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Marshall Clowdf4a22d2016-07-08 16:54:471234#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161235
1236template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:161237_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161238__wrap_iter<_Iter>
Eric Fiselier2c8aa052016-12-28 05:35:321239operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161240
Howard Hinnant33be35e2012-09-14 00:39:161241template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1242template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1243template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1244template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:161245
Eric Fiselier2c8aa052016-12-28 05:35:321246#if _LIBCPP_DEBUG_LEVEL < 2
1247
Howard Hinnantbc8d3f92010-05-11 19:42:161248template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:161249_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161250typename enable_if
1251<
Howard Hinnant1468b662010-11-19 22:17:281252 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161253 _Tp*
1254>::type
1255__unwrap_iter(__wrap_iter<_Tp*>);
1256
Eric Fiselier2c8aa052016-12-28 05:35:321257#else
1258
1259template <class _Tp>
1260inline _LIBCPP_INLINE_VISIBILITY
1261typename enable_if
1262<
1263 is_trivially_copy_assignable<_Tp>::value,
1264 __wrap_iter<_Tp*>
1265>::type
1266__unwrap_iter(__wrap_iter<_Tp*> __i);
1267
1268#endif
1269
Howard Hinnantbc8d3f92010-05-11 19:42:161270template <class _Iter>
1271class __wrap_iter
1272{
1273public:
1274 typedef _Iter iterator_type;
1275 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1276 typedef typename iterator_traits<iterator_type>::value_type value_type;
1277 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1278 typedef typename iterator_traits<iterator_type>::pointer pointer;
1279 typedef typename iterator_traits<iterator_type>::reference reference;
1280private:
1281 iterator_type __i;
1282public:
Eric Fiselier2c8aa052016-12-28 05:35:321283 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT_DEBUG
Marshall Clow0f164c92013-08-07 20:48:481284#if _LIBCPP_STD_VER > 11
1285 : __i{}
1286#endif
Howard Hinnant7608b4a2011-09-16 19:52:231287 {
1288#if _LIBCPP_DEBUG_LEVEL >= 2
1289 __get_db()->__insert_i(this);
1290#endif
1291 }
Howard Hinnantbc8d3f92010-05-11 19:42:161292 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Eric Fiselier2c8aa052016-12-28 05:35:321293 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511294 : __i(__u.base())
1295 {
Howard Hinnantabe26282011-09-16 17:29:171296#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511297 __get_db()->__iterator_copy(this, &__u);
1298#endif
1299 }
Howard Hinnantabe26282011-09-16 17:29:171300#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511301 _LIBCPP_INLINE_VISIBILITY
1302 __wrap_iter(const __wrap_iter& __x)
1303 : __i(__x.base())
1304 {
1305 __get_db()->__iterator_copy(this, &__x);
1306 }
1307 _LIBCPP_INLINE_VISIBILITY
1308 __wrap_iter& operator=(const __wrap_iter& __x)
1309 {
1310 if (this != &__x)
1311 {
1312 __get_db()->__iterator_copy(this, &__x);
1313 __i = __x.__i;
1314 }
1315 return *this;
1316 }
1317 _LIBCPP_INLINE_VISIBILITY
1318 ~__wrap_iter()
1319 {
1320 __get_db()->__erase_i(this);
1321 }
1322#endif
Eric Fiselier2c8aa052016-12-28 05:35:321323 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511324 {
Howard Hinnantabe26282011-09-16 17:29:171325#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511326 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1327 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:171328#endif
Howard Hinnant7a563db2011-09-14 18:33:511329 return *__i;
1330 }
Eric Fiselier2c8aa052016-12-28 05:35:321331 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT_DEBUG
Howard Hinnant2c39cbe2013-06-27 19:35:321332 {
1333#if _LIBCPP_DEBUG_LEVEL >= 2
1334 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1335 "Attempted to dereference a non-dereferenceable iterator");
1336#endif
Marshall Clowdca800c2016-04-11 03:54:531337 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant2c39cbe2013-06-27 19:35:321338 }
Eric Fiselier2c8aa052016-12-28 05:35:321339 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511340 {
Howard Hinnantabe26282011-09-16 17:29:171341#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511342 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1343 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:171344#endif
Howard Hinnant7a563db2011-09-14 18:33:511345 ++__i;
1346 return *this;
1347 }
Eric Fiselier2c8aa052016-12-28 05:35:321348 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511349 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Eric Fiselier2c8aa052016-12-28 05:35:321350 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511351 {
Howard Hinnantabe26282011-09-16 17:29:171352#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511353 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1354 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:171355#endif
Howard Hinnant7a563db2011-09-14 18:33:511356 --__i;
1357 return *this;
1358 }
Eric Fiselier2c8aa052016-12-28 05:35:321359 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511360 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier2c8aa052016-12-28 05:35:321361 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511362 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier2c8aa052016-12-28 05:35:321363 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511364 {
Howard Hinnantabe26282011-09-16 17:29:171365#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511366 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1367 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:171368#endif
Howard Hinnant7a563db2011-09-14 18:33:511369 __i += __n;
1370 return *this;
1371 }
Eric Fiselier2c8aa052016-12-28 05:35:321372 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511373 {return *this + (-__n);}
Eric Fiselier2c8aa052016-12-28 05:35:321374 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511375 {*this += -__n; return *this;}
Eric Fiselier2c8aa052016-12-28 05:35:321376 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511377 {
Howard Hinnantabe26282011-09-16 17:29:171378#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511379 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1380 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:171381#endif
Howard Hinnant7a563db2011-09-14 18:33:511382 return __i[__n];
1383 }
Howard Hinnantbc8d3f92010-05-11 19:42:161384
Eric Fiselier2c8aa052016-12-28 05:35:321385 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT_DEBUG {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:161386
1387private:
Howard Hinnantabe26282011-09-16 17:29:171388#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511389 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1390 {
1391 __get_db()->__insert_ic(this, __p);
1392 }
Howard Hinnant499cea12013-08-23 17:37:051393#else
Eric Fiselier2c8aa052016-12-28 05:35:321394 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:511395#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161396
1397 template <class _Up> friend class __wrap_iter;
1398 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierc3589a82017-01-04 23:56:001399 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Howard Hinnantbc8d3f92010-05-11 19:42:161400
1401 template <class _Iter1, class _Iter2>
1402 friend
1403 bool
Eric Fiselier2c8aa052016-12-28 05:35:321404 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431405
Howard Hinnantbc8d3f92010-05-11 19:42:161406 template <class _Iter1, class _Iter2>
1407 friend
1408 bool
Eric Fiselier2c8aa052016-12-28 05:35:321409 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431410
Howard Hinnantbc8d3f92010-05-11 19:42:161411 template <class _Iter1, class _Iter2>
1412 friend
1413 bool
Eric Fiselier2c8aa052016-12-28 05:35:321414 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431415
Howard Hinnantbc8d3f92010-05-11 19:42:161416 template <class _Iter1, class _Iter2>
1417 friend
1418 bool
Eric Fiselier2c8aa052016-12-28 05:35:321419 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431420
Howard Hinnantbc8d3f92010-05-11 19:42:161421 template <class _Iter1, class _Iter2>
1422 friend
1423 bool
Eric Fiselier2c8aa052016-12-28 05:35:321424 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431425
Howard Hinnantbc8d3f92010-05-11 19:42:161426 template <class _Iter1, class _Iter2>
1427 friend
1428 bool
Eric Fiselier2c8aa052016-12-28 05:35:321429 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431430
Marshall Clow3f013892016-07-18 13:19:001431#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:471432 template <class _Iter1, class _Iter2>
1433 friend
1434 auto
Eric Fiselier2c8aa052016-12-28 05:35:321435 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Marshall Clowdf4a22d2016-07-08 16:54:471436 -> decltype(__x.base() - __y.base());
1437#else
Howard Hinnantbc8d3f92010-05-11 19:42:161438 template <class _Iter1, class _Iter2>
1439 friend
1440 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier2c8aa052016-12-28 05:35:321441 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Marshall Clowdf4a22d2016-07-08 16:54:471442#endif
Howard Hinnant324bb032010-08-22 00:02:431443
Howard Hinnantbc8d3f92010-05-11 19:42:161444 template <class _Iter1>
1445 friend
1446 __wrap_iter<_Iter1>
Eric Fiselier2c8aa052016-12-28 05:35:321447 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161448
Howard Hinnant99968442011-11-29 18:15:501449 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:161450 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:501451 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:161452 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1453
Eric Fiselier2c8aa052016-12-28 05:35:321454#if _LIBCPP_DEBUG_LEVEL < 2
Howard Hinnantbc8d3f92010-05-11 19:42:161455 template <class _Tp>
1456 friend
1457 typename enable_if
1458 <
Howard Hinnant1468b662010-11-19 22:17:281459 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161460 _Tp*
1461 >::type
1462 __unwrap_iter(__wrap_iter<_Tp*>);
Eric Fiselier2c8aa052016-12-28 05:35:321463#else
1464 template <class _Tp>
1465 inline _LIBCPP_INLINE_VISIBILITY
1466 typename enable_if
1467 <
1468 is_trivially_copy_assignable<_Tp>::value,
1469 __wrap_iter<_Tp*>
1470 >::type
1471 __unwrap_iter(__wrap_iter<_Tp*> __i);
1472#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161473};
1474
1475template <class _Iter1, class _Iter2>
1476inline _LIBCPP_INLINE_VISIBILITY
1477bool
Eric Fiselier2c8aa052016-12-28 05:35:321478operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161479{
1480 return __x.base() == __y.base();
1481}
1482
1483template <class _Iter1, class _Iter2>
1484inline _LIBCPP_INLINE_VISIBILITY
1485bool
Eric Fiselier2c8aa052016-12-28 05:35:321486operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161487{
Howard Hinnantabe26282011-09-16 17:29:171488#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:351489 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:511490 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:171491#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161492 return __x.base() < __y.base();
1493}
1494
1495template <class _Iter1, class _Iter2>
1496inline _LIBCPP_INLINE_VISIBILITY
1497bool
Eric Fiselier2c8aa052016-12-28 05:35:321498operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161499{
Howard Hinnant7a563db2011-09-14 18:33:511500 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:161501}
1502
1503template <class _Iter1, class _Iter2>
1504inline _LIBCPP_INLINE_VISIBILITY
1505bool
Eric Fiselier2c8aa052016-12-28 05:35:321506operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161507{
Howard Hinnant7a563db2011-09-14 18:33:511508 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:161509}
1510
1511template <class _Iter1, class _Iter2>
1512inline _LIBCPP_INLINE_VISIBILITY
1513bool
Eric Fiselier2c8aa052016-12-28 05:35:321514operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161515{
Howard Hinnant7a563db2011-09-14 18:33:511516 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:161517}
1518
1519template <class _Iter1, class _Iter2>
1520inline _LIBCPP_INLINE_VISIBILITY
1521bool
Eric Fiselier2c8aa052016-12-28 05:35:321522operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161523{
Howard Hinnant7a563db2011-09-14 18:33:511524 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161525}
1526
Howard Hinnant95c0e9f2012-10-02 19:45:421527template <class _Iter1>
1528inline _LIBCPP_INLINE_VISIBILITY
1529bool
Eric Fiselier2c8aa052016-12-28 05:35:321530operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:421531{
1532 return !(__x == __y);
1533}
1534
1535template <class _Iter1>
1536inline _LIBCPP_INLINE_VISIBILITY
1537bool
Eric Fiselier2c8aa052016-12-28 05:35:321538operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:421539{
1540 return __y < __x;
1541}
1542
1543template <class _Iter1>
1544inline _LIBCPP_INLINE_VISIBILITY
1545bool
Eric Fiselier2c8aa052016-12-28 05:35:321546operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:421547{
1548 return !(__x < __y);
1549}
1550
1551template <class _Iter1>
1552inline _LIBCPP_INLINE_VISIBILITY
1553bool
Eric Fiselier2c8aa052016-12-28 05:35:321554operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:421555{
1556 return !(__y < __x);
1557}
1558
Marshall Clow3f013892016-07-18 13:19:001559#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:471560template <class _Iter1, class _Iter2>
1561inline _LIBCPP_INLINE_VISIBILITY
1562auto
Eric Fiselier2c8aa052016-12-28 05:35:321563operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Marshall Clowdf4a22d2016-07-08 16:54:471564-> decltype(__x.base() - __y.base())
1565{
1566#if _LIBCPP_DEBUG_LEVEL >= 2
1567 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1568 "Attempted to subtract incompatible iterators");
1569#endif
1570 return __x.base() - __y.base();
1571}
1572#else
Howard Hinnantbc8d3f92010-05-11 19:42:161573template <class _Iter1, class _Iter2>
1574inline _LIBCPP_INLINE_VISIBILITY
1575typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier2c8aa052016-12-28 05:35:321576operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161577{
Howard Hinnantabe26282011-09-16 17:29:171578#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:351579 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:511580 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:171581#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161582 return __x.base() - __y.base();
1583}
Marshall Clowdf4a22d2016-07-08 16:54:471584#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161585
1586template <class _Iter>
1587inline _LIBCPP_INLINE_VISIBILITY
1588__wrap_iter<_Iter>
1589operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier2c8aa052016-12-28 05:35:321590 __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161591{
Howard Hinnant7a563db2011-09-14 18:33:511592 __x += __n;
1593 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:161594}
1595
Marshall Clowdf9db312016-01-13 21:54:341596template <class _Iter>
1597struct __libcpp_is_trivial_iterator
Marshall Clowf333bee2016-11-02 15:30:261598 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1599
Marshall Clowdf9db312016-01-13 21:54:341600template <class _Iter>
1601struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
Marshall Clowf333bee2016-11-02 15:30:261602 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clowdf9db312016-01-13 21:54:341603
1604template <class _Iter>
1605struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
Marshall Clowf333bee2016-11-02 15:30:261606 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clowdf9db312016-01-13 21:54:341607
1608template <class _Iter>
1609struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
Marshall Clowf333bee2016-11-02 15:30:261610 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clowdf9db312016-01-13 21:54:341611
1612
Marshall Clow6daf5342013-12-02 03:24:331613template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:301614inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:331615_Tp*
1616begin(_Tp (&__array)[_Np])
1617{
1618 return __array;
1619}
1620
1621template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:301622inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:331623_Tp*
1624end(_Tp (&__array)[_Np])
1625{
1626 return __array + _Np;
1627}
1628
Eric Fiselier4e3e15a2016-09-25 03:34:281629#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow1c398692013-12-11 19:32:321630
Howard Hinnant99968442011-11-29 18:15:501631template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171632inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161633auto
Howard Hinnant99968442011-11-29 18:15:501634begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:161635{
1636 return __c.begin();
1637}
1638
Howard Hinnant99968442011-11-29 18:15:501639template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171640inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161641auto
Howard Hinnant99968442011-11-29 18:15:501642begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:161643{
1644 return __c.begin();
1645}
1646
Howard Hinnant99968442011-11-29 18:15:501647template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171648inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161649auto
Howard Hinnant99968442011-11-29 18:15:501650end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:161651{
1652 return __c.end();
1653}
1654
Howard Hinnant99968442011-11-29 18:15:501655template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171656inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161657auto
Howard Hinnant99968442011-11-29 18:15:501658end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:161659{
1660 return __c.end();
1661}
1662
Marshall Clow09da3c02013-08-30 01:17:071663#if _LIBCPP_STD_VER > 11
1664
Marshall Clow6daf5342013-12-02 03:24:331665template <class _Tp, size_t _Np>
Marshall Clowe22af6b2017-01-04 17:58:171666inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:331667reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1668{
1669 return reverse_iterator<_Tp*>(__array + _Np);
1670}
1671
1672template <class _Tp, size_t _Np>
Marshall Clowe22af6b2017-01-04 17:58:171673inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:331674reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1675{
1676 return reverse_iterator<_Tp*>(__array);
1677}
1678
1679template <class _Ep>
Marshall Clowe22af6b2017-01-04 17:58:171680inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:331681reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1682{
1683 return reverse_iterator<const _Ep*>(__il.end());
1684}
1685
1686template <class _Ep>
Marshall Clowe22af6b2017-01-04 17:58:171687inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:331688reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1689{
1690 return reverse_iterator<const _Ep*>(__il.begin());
1691}
1692
Marshall Clow09da3c02013-08-30 01:17:071693template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:301694inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow02e94f82016-08-10 20:04:461695auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clow09da3c02013-08-30 01:17:071696{
Marshall Clow02e94f82016-08-10 20:04:461697 return _VSTD::begin(__c);
Marshall Clow09da3c02013-08-30 01:17:071698}
1699
1700template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:301701inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow02e94f82016-08-10 20:04:461702auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clow09da3c02013-08-30 01:17:071703{
Marshall Clow02e94f82016-08-10 20:04:461704 return _VSTD::end(__c);
Marshall Clow09da3c02013-08-30 01:17:071705}
1706
1707template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171708inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:071709auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1710{
1711 return __c.rbegin();
1712}
1713
1714template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171715inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:071716auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1717{
1718 return __c.rbegin();
1719}
1720
1721template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171722inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:071723auto rend(_Cp& __c) -> decltype(__c.rend())
1724{
1725 return __c.rend();
1726}
1727
1728template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171729inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:071730auto rend(const _Cp& __c) -> decltype(__c.rend())
1731{
1732 return __c.rend();
1733}
1734
1735template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171736inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow02e94f82016-08-10 20:04:461737auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clow09da3c02013-08-30 01:17:071738{
Marshall Clow02e94f82016-08-10 20:04:461739 return _VSTD::rbegin(__c);
Marshall Clow09da3c02013-08-30 01:17:071740}
1741
1742template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171743inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow02e94f82016-08-10 20:04:461744auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clow09da3c02013-08-30 01:17:071745{
Marshall Clow02e94f82016-08-10 20:04:461746 return _VSTD::rend(__c);
Marshall Clow09da3c02013-08-30 01:17:071747}
1748
1749#endif
1750
1751
Eric Fiselier4e3e15a2016-09-25 03:34:281752#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantbc8d3f92010-05-11 19:42:161753
Howard Hinnant99968442011-11-29 18:15:501754template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:341755inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501756typename _Cp::iterator
1757begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:161758{
1759 return __c.begin();
1760}
1761
Howard Hinnant99968442011-11-29 18:15:501762template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:341763inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501764typename _Cp::const_iterator
1765begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:161766{
1767 return __c.begin();
1768}
1769
Howard Hinnant99968442011-11-29 18:15:501770template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:341771inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501772typename _Cp::iterator
1773end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:161774{
1775 return __c.end();
1776}
1777
Howard Hinnant99968442011-11-29 18:15:501778template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:341779inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501780typename _Cp::const_iterator
1781end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:161782{
1783 return __c.end();
1784}
1785
Eric Fiselier4e3e15a2016-09-25 03:34:281786#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantbc8d3f92010-05-11 19:42:161787
Marshall Clow03c67912014-11-19 19:43:231788#if _LIBCPP_STD_VER > 14
Marshall Clow35e462d2015-02-11 16:14:011789template <class _Cont>
1790constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
Marshall Clow03c67912014-11-19 19:43:231791
Marshall Clow35e462d2015-02-11 16:14:011792template <class _Tp, size_t _Sz>
Eric Fiselier0e5ebbc2016-12-23 23:37:521793constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clow03c67912014-11-19 19:43:231794
Marshall Clow35e462d2015-02-11 16:14:011795template <class _Cont>
1796constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
Marshall Clow03c67912014-11-19 19:43:231797
Marshall Clow35e462d2015-02-11 16:14:011798template <class _Tp, size_t _Sz>
Eric Fiselier0e5ebbc2016-12-23 23:37:521799constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clow03c67912014-11-19 19:43:231800
1801template <class _Ep>
1802constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1803
Marshall Clow35e462d2015-02-11 16:14:011804template <class _Cont> constexpr
1805auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:231806
Marshall Clow35e462d2015-02-11 16:14:011807template <class _Cont> constexpr
1808auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:231809
Marshall Clow35e462d2015-02-11 16:14:011810template <class _Tp, size_t _Sz>
1811constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clow03c67912014-11-19 19:43:231812
1813template <class _Ep>
1814constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1815#endif
1816
1817
Howard Hinnantbc8d3f92010-05-11 19:42:161818_LIBCPP_END_NAMESPACE_STD
1819
1820#endif // _LIBCPP_ITERATOR