blob: 3e1fb610821a3389383572606361c55f3efb2d64 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ITERATOR
11#define _LIBCPP_ITERATOR
12
13/*
14 iterator synopsis
15
16namespace std
17{
18
19template<class Iterator>
20struct iterator_traits
21{
22 typedef typename Iterator::difference_type difference_type;
23 typedef typename Iterator::value_type value_type;
24 typedef typename Iterator::pointer pointer;
25 typedef typename Iterator::reference reference;
26 typedef typename Iterator::iterator_category iterator_category;
27};
28
29template<class T>
30struct iterator_traits<T*>
31{
32 typedef ptrdiff_t difference_type;
33 typedef T value_type;
34 typedef T* pointer;
35 typedef T& reference;
36 typedef random_access_iterator_tag iterator_category;
37};
38
Howard Hinnantc51e1022010-05-11 19:42:16 +000039template<class Category, class T, class Distance = ptrdiff_t,
40 class Pointer = T*, class Reference = T&>
41struct iterator
42{
43 typedef T value_type;
44 typedef Distance difference_type;
45 typedef Pointer pointer;
46 typedef Reference reference;
47 typedef Category iterator_category;
48};
49
50struct input_iterator_tag {};
51struct output_iterator_tag {};
52struct forward_iterator_tag : public input_iterator_tag {};
53struct bidirectional_iterator_tag : public forward_iterator_tag {};
54struct random_access_iterator_tag : public bidirectional_iterator_tag {};
55
Marshall Clow75468e72017-05-17 18:51:36 +000056// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -040057template <class InputIterator, class Distance> // constexpr in C++17
58 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +000059
Marshall Clow75468e72017-05-17 18:51:36 +000060template <class InputIterator> // constexpr in C++17
61 constexpr typename iterator_traits<InputIterator>::difference_type
62 distance(InputIterator first, InputIterator last);
63
64template <class InputIterator> // constexpr in C++17
65 constexpr InputIterator next(InputIterator x,
66typename iterator_traits<InputIterator>::difference_type n = 1);
67
68template <class BidirectionalIterator> // constexpr in C++17
69 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +000070 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +000071
72template <class Iterator>
73class reverse_iterator
74 : public iterator<typename iterator_traits<Iterator>::iterator_category,
75 typename iterator_traits<Iterator>::value_type,
76 typename iterator_traits<Iterator>::difference_type,
77 typename iterator_traits<Iterator>::pointer,
78 typename iterator_traits<Iterator>::reference>
79{
80protected:
81 Iterator current;
82public:
83 typedef Iterator iterator_type;
84 typedef typename iterator_traits<Iterator>::difference_type difference_type;
85 typedef typename iterator_traits<Iterator>::reference reference;
86 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000087
Marshall Clow5ace5542016-10-19 15:12:50 +000088 constexpr reverse_iterator();
89 constexpr explicit reverse_iterator(Iterator x);
90 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
91 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
92 constexpr Iterator base() const;
93 constexpr reference operator*() const;
94 constexpr pointer operator->() const;
95 constexpr reverse_iterator& operator++();
96 constexpr reverse_iterator operator++(int);
97 constexpr reverse_iterator& operator--();
98 constexpr reverse_iterator operator--(int);
99 constexpr reverse_iterator operator+ (difference_type n) const;
100 constexpr reverse_iterator& operator+=(difference_type n);
101 constexpr reverse_iterator operator- (difference_type n) const;
102 constexpr reverse_iterator& operator-=(difference_type n);
103 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000104};
105
106template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000107constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
109
110template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000111constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000112operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
113
114template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000115constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000116operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
117
118template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000119constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
121
122template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000123constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000124operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
125
126template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000127constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000128operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
129
130template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000131constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000132operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000133-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000134
135template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000136constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000137operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000138 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000139
Marshall Clow5ace5542016-10-19 15:12:50 +0000140template <class Iterator>
141constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000142
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143template <class Container>
144class back_insert_iterator
145{
146protected:
147 Container* container;
148public:
149 typedef Container container_type;
150 typedef void value_type;
151 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000152 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000153 typedef void pointer;
154
155 explicit back_insert_iterator(Container& x);
Howard Hinnant60e95c62010-09-14 20:26:27 +0000156 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157 back_insert_iterator& operator*();
158 back_insert_iterator& operator++();
159 back_insert_iterator operator++(int);
160};
161
162template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
163
164template <class Container>
165class front_insert_iterator
166{
167protected:
168 Container* container;
169public:
170 typedef Container container_type;
171 typedef void value_type;
172 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000173 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174 typedef void pointer;
175
176 explicit front_insert_iterator(Container& x);
Howard Hinnant60e95c62010-09-14 20:26:27 +0000177 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178 front_insert_iterator& operator*();
179 front_insert_iterator& operator++();
180 front_insert_iterator operator++(int);
181};
182
183template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
184
185template <class Container>
186class insert_iterator
187{
188protected:
189 Container* container;
190 typename Container::iterator iter;
191public:
192 typedef Container container_type;
193 typedef void value_type;
194 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000195 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196 typedef void pointer;
197
198 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant60e95c62010-09-14 20:26:27 +0000199 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200 insert_iterator& operator*();
201 insert_iterator& operator++();
202 insert_iterator& operator++(int);
203};
204
205template <class Container, class Iterator>
206insert_iterator<Container> inserter(Container& x, Iterator i);
207
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000208template <class Iterator>
209class move_iterator {
210public:
211 typedef Iterator iterator_type;
212 typedef typename iterator_traits<Iterator>::difference_type difference_type;
213 typedef Iterator pointer;
214 typedef typename iterator_traits<Iterator>::value_type value_type;
215 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
216 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000217
Marshall Clowb5f99122016-11-02 15:30:26 +0000218 constexpr move_iterator(); // all the constexprs are in C++17
219 constexpr explicit move_iterator(Iterator i);
220 template <class U>
221 constexpr move_iterator(const move_iterator<U>& u);
222 template <class U>
223 constexpr move_iterator& operator=(const move_iterator<U>& u);
224 constexpr iterator_type base() const;
225 constexpr reference operator*() const;
226 constexpr pointer operator->() const;
227 constexpr move_iterator& operator++();
228 constexpr move_iterator operator++(int);
229 constexpr move_iterator& operator--();
230 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000231 constexpr move_iterator operator+(difference_type n) const;
232 constexpr move_iterator& operator+=(difference_type n);
233 constexpr move_iterator operator-(difference_type n) const;
234 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000235 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000236private:
237 Iterator current; // exposition only
238};
239
240template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000241constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000242operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
243
244template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000245constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000246operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
247
248template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000249constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000250operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
251
252template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000253constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000254operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
255
256template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000257constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000258operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
259
260template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000261constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000262operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
263
264template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000265constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000266operator-(const move_iterator<Iterator1>& x,
267 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
268
269template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000270constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000271 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000272 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000273
Marshall Clowb5f99122016-11-02 15:30:26 +0000274template <class Iterator> // constexpr in C++17
275constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000276
277
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
279class istream_iterator
280 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
281{
282public:
283 typedef charT char_type;
284 typedef traits traits_type;
285 typedef basic_istream<charT,traits> istream_type;
286
Marshall Clow0735e4e2015-04-16 21:36:54 +0000287 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288 istream_iterator(istream_type& s);
289 istream_iterator(const istream_iterator& x);
290 ~istream_iterator();
291
292 const T& operator*() const;
293 const T* operator->() const;
294 istream_iterator& operator++();
295 istream_iterator operator++(int);
296};
297
298template <class T, class charT, class traits, class Distance>
299bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
300 const istream_iterator<T,charT,traits,Distance>& y);
301template <class T, class charT, class traits, class Distance>
302bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
303 const istream_iterator<T,charT,traits,Distance>& y);
304
305template <class T, class charT = char, class traits = char_traits<charT> >
306class ostream_iterator
307 : public iterator<output_iterator_tag, void, void, void ,void>
308{
309public:
310 typedef charT char_type;
311 typedef traits traits_type;
312 typedef basic_ostream<charT,traits> ostream_type;
313
314 ostream_iterator(ostream_type& s);
315 ostream_iterator(ostream_type& s, const charT* delimiter);
316 ostream_iterator(const ostream_iterator& x);
317 ~ostream_iterator();
318 ostream_iterator& operator=(const T& value);
319
320 ostream_iterator& operator*();
321 ostream_iterator& operator++();
322 ostream_iterator& operator++(int);
323};
324
325template<class charT, class traits = char_traits<charT> >
326class istreambuf_iterator
327 : public iterator<input_iterator_tag, charT,
328 typename traits::off_type, unspecified,
329 charT>
330{
331public:
332 typedef charT char_type;
333 typedef traits traits_type;
334 typedef typename traits::int_type int_type;
335 typedef basic_streambuf<charT,traits> streambuf_type;
336 typedef basic_istream<charT,traits> istream_type;
337
Howard Hinnant011138d2012-07-20 19:36:34 +0000338 istreambuf_iterator() noexcept;
339 istreambuf_iterator(istream_type& s) noexcept;
340 istreambuf_iterator(streambuf_type* s) noexcept;
341 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342
343 charT operator*() const;
344 pointer operator->() const;
345 istreambuf_iterator& operator++();
346 a-private-type operator++(int);
347
348 bool equal(const istreambuf_iterator& b) const;
349};
350
351template <class charT, class traits>
352bool operator==(const istreambuf_iterator<charT,traits>& a,
353 const istreambuf_iterator<charT,traits>& b);
354template <class charT, class traits>
355bool operator!=(const istreambuf_iterator<charT,traits>& a,
356 const istreambuf_iterator<charT,traits>& b);
357
358template <class charT, class traits = char_traits<charT> >
359class ostreambuf_iterator
360 : public iterator<output_iterator_tag, void, void, void, void>
361{
362public:
363 typedef charT char_type;
364 typedef traits traits_type;
365 typedef basic_streambuf<charT,traits> streambuf_type;
366 typedef basic_ostream<charT,traits> ostream_type;
367
Howard Hinnant011138d2012-07-20 19:36:34 +0000368 ostreambuf_iterator(ostream_type& s) noexcept;
369 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 ostreambuf_iterator& operator=(charT c);
371 ostreambuf_iterator& operator*();
372 ostreambuf_iterator& operator++();
373 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000374 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375};
376
Marshall Clow99ba0022017-01-04 17:58:17 +0000377template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
378template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
379template <class C> constexpr auto end(C& c) -> decltype(c.end());
380template <class C> constexpr auto end(const C& c) -> decltype(c.end());
381template <class T, size_t N> constexpr T* begin(T (&array)[N]);
382template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383
Marshall Clow99ba0022017-01-04 17:58:17 +0000384template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
385template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
386template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
387template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
388template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
389template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
390template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
391template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
392template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
393template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
394template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
395template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000396
Marshall Clowef357272014-11-19 19:43:23 +0000397// 24.8, container access:
398template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
399template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000400
401template <class C> constexpr auto ssize(const C& c)
402 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
403template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
404
Marshall Clowef357272014-11-19 19:43:23 +0000405template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
406template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
407template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
408template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
409template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
410template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
411template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
412
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413} // std
414
415*/
416
417#include <__config>
Eric Fiselier876c6862016-02-20 00:19:45 +0000418#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow3dc05502014-02-27 02:11:50 +0000419#include <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420#include <type_traits>
421#include <cstddef>
Marshall Clowb278e9c2013-08-30 01:17:07 +0000422#include <initializer_list>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000423#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000424
Eric Fiselier14b6de92014-08-10 23:53:08 +0000425#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000427#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000429#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430
431_LIBCPP_BEGIN_NAMESPACE_STD
Eric Fiselier7b2a34f2019-11-16 20:24:39 -0500432template <class _Iter>
433struct _LIBCPP_TEMPLATE_VIS iterator_traits;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000435struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
436struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
437struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
438struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
439struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
Eric Fiselier30005a92019-11-16 20:12:48 -0500440#if _LIBCPP_STD_VER > 17
441// TODO(EricWF) contiguous_iterator_tag is provided as an extension prior to
442// C++20 to allow optimizations for users providing wrapped iterator types.
443struct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag: public random_access_iterator_tag { };
444#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
Eric Fiselier7b2a34f2019-11-16 20:24:39 -0500446template <class _Iter>
447struct __iter_traits_cache {
448 using type = _If<
449 __is_primary_template<iterator_traits<_Iter> >::value,
450 _Iter,
451 iterator_traits<_Iter>
452 >;
453};
454template <class _Iter>
455using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type;
456
457struct __iter_concept_concept_test {
458 template <class _Iter>
459 using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept;
460};
461struct __iter_concept_category_test {
462 template <class _Iter>
463 using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category;
464};
465struct __iter_concept_random_fallback {
466 template <class _Iter>
467 using _Apply = _EnableIf<
468 __is_primary_template<iterator_traits<_Iter> >::value,
469 random_access_iterator_tag
470 >;
471};
472
473template <class _Iter, class _Tester> struct __test_iter_concept
474 : _IsValidExpansion<_Tester::template _Apply, _Iter>,
475 _Tester
476{
477};
478
479template <class _Iter>
480struct __iter_concept_cache {
481 using type = _Or<
482 __test_iter_concept<_Iter, __iter_concept_concept_test>,
483 __test_iter_concept<_Iter, __iter_concept_category_test>,
484 __test_iter_concept<_Iter, __iter_concept_random_fallback>
485 >;
486};
487
488template <class _Iter>
489using _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
490
491
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492template <class _Tp>
Marshall Clow50abbe42018-11-13 05:33:31 +0000493struct __has_iterator_typedefs
494{
495private:
496 struct __two {char __lx; char __lxx;};
497 template <class _Up> static __two __test(...);
Arthur O'Dwyer07b22492020-11-27 11:02:06 -0500498 template <class _Up> static char __test(typename __void_t<typename _Up::iterator_category>::type* = 0,
499 typename __void_t<typename _Up::difference_type>::type* = 0,
500 typename __void_t<typename _Up::value_type>::type* = 0,
501 typename __void_t<typename _Up::reference>::type* = 0,
502 typename __void_t<typename _Up::pointer>::type* = 0);
Marshall Clow50abbe42018-11-13 05:33:31 +0000503public:
504 static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1;
505};
506
507
508template <class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509struct __has_iterator_category
510{
511private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000512 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 template <class _Up> static __two __test(...);
Bruce Mitchener170d8972020-11-24 12:53:53 -0500514 template <class _Up> static char __test(typename _Up::iterator_category* = nullptr);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500516 static const bool value = sizeof(__test<_Tp>(nullptr)) == 1;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517};
518
Marshall Clow75533b02014-01-03 22:55:49 +0000519template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520
521template <class _Iter>
Marshall Clow75533b02014-01-03 22:55:49 +0000522struct __iterator_traits_impl<_Iter, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523{
524 typedef typename _Iter::difference_type difference_type;
525 typedef typename _Iter::value_type value_type;
526 typedef typename _Iter::pointer pointer;
527 typedef typename _Iter::reference reference;
528 typedef typename _Iter::iterator_category iterator_category;
529};
530
531template <class _Iter, bool> struct __iterator_traits {};
532
533template <class _Iter>
534struct __iterator_traits<_Iter, true>
Marshall Clow75533b02014-01-03 22:55:49 +0000535 : __iterator_traits_impl
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536 <
537 _Iter,
538 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
539 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
540 >
541{};
542
543// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
544// exists. Else iterator_traits<Iterator> will be an empty class. This is a
545// conforming extension which allows some programs to compile and behave as
546// the client expects instead of failing at compile time.
547
548template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000549struct _LIBCPP_TEMPLATE_VIS iterator_traits
Eric Fiselier7b2a34f2019-11-16 20:24:39 -0500550 : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {
551
552 using __primary_template = iterator_traits;
553};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554
555template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000556struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557{
558 typedef ptrdiff_t difference_type;
Marshall Clow56d53522017-11-14 00:03:10 +0000559 typedef typename remove_cv<_Tp>::type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560 typedef _Tp* pointer;
561 typedef _Tp& reference;
562 typedef random_access_iterator_tag iterator_category;
Eric Fiselier30005a92019-11-16 20:12:48 -0500563#if _LIBCPP_STD_VER > 17
564 typedef contiguous_iterator_tag iterator_concept;
565#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566};
567
568template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
569struct __has_iterator_category_convertible_to
570 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
571{};
572
573template <class _Tp, class _Up>
574struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
575
576template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500577struct __is_cpp17_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578
579template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500580struct __is_cpp17_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581
582template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500583struct __is_cpp17_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584
585template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500586struct __is_cpp17_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587
Eric Fiselier30005a92019-11-16 20:12:48 -0500588#if _LIBCPP_STD_VER > 17
589template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500590struct __is_cpp17_contiguous_iterator : public __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag> {};
591#else
592template <class _Tp>
593struct __is_cpp17_contiguous_iterator : public false_type {};
Eric Fiselier30005a92019-11-16 20:12:48 -0500594#endif
595
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500596
Marshall Clow039b2f02016-01-13 21:54:34 +0000597template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500598struct __is_exactly_cpp17_input_iterator
Louis Dionne173f29e2019-05-29 16:01:36 +0000599 : public integral_constant<bool,
600 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
Marshall Clowb5f99122016-11-02 15:30:26 +0000601 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
Marshall Clow039b2f02016-01-13 21:54:34 +0000602
Louis Dionned23a5f22019-06-20 19:32:00 +0000603#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
604template<class _InputIterator>
605using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
606
607template<class _InputIterator>
608using __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
609
610template<class _InputIterator>
611using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
612
613template<class _InputIterator>
614using __iter_to_alloc_type = pair<
615 add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
616 typename iterator_traits<_InputIterator>::value_type::second_type>;
617#endif
618
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619template<class _Category, class _Tp, class _Distance = ptrdiff_t,
620 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000621struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622{
623 typedef _Tp value_type;
624 typedef _Distance difference_type;
625 typedef _Pointer pointer;
626 typedef _Reference reference;
627 typedef _Category iterator_category;
628};
629
630template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000631inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632void __advance(_InputIter& __i,
633 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
634{
635 for (; __n > 0; --__n)
636 ++__i;
637}
638
639template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000640inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641void __advance(_BiDirIter& __i,
642 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
643{
644 if (__n >= 0)
645 for (; __n > 0; --__n)
646 ++__i;
647 else
648 for (; __n < 0; ++__n)
649 --__i;
650}
651
652template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000653inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654void __advance(_RandIter& __i,
655 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
656{
657 __i += __n;
658}
659
Louis Dionne45768662020-06-08 16:16:01 -0400660template <class _InputIter, class _Distance>
Marshall Clow75468e72017-05-17 18:51:36 +0000661inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Louis Dionne45768662020-06-08 16:16:01 -0400662void advance(_InputIter& __i, _Distance __orig_n)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000663{
Louis Dionne45768662020-06-08 16:16:01 -0400664 _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
665 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500666 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
Louis Dionne45768662020-06-08 16:16:01 -0400667 _IntegralSize __n = __orig_n;
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500668 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669}
670
671template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000672inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673typename iterator_traits<_InputIter>::difference_type
674__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
675{
676 typename iterator_traits<_InputIter>::difference_type __r(0);
677 for (; __first != __last; ++__first)
678 ++__r;
679 return __r;
680}
681
682template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000683inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000684typename iterator_traits<_RandIter>::difference_type
685__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
686{
687 return __last - __first;
688}
689
690template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000691inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692typename iterator_traits<_InputIter>::difference_type
693distance(_InputIter __first, _InputIter __last)
694{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500695 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696}
697
Marshall Clow990c70d2015-11-07 17:48:49 +0000698template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000699inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000700typename enable_if
701<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500702 __is_cpp17_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000703 _InputIter
704>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000705next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000706 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500708 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400709 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
Marshall Clow3d435212019-03-22 22:32:20 +0000710
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000711 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712 return __x;
713}
714
Marshall Clow3d435212019-03-22 22:32:20 +0000715template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000716inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000717typename enable_if
718<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500719 __is_cpp17_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000720 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000721>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000722prev(_InputIter __x,
723 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500725 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400726 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000727 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000728 return __x;
729}
730
Eric Fiselier883af112017-04-13 02:54:13 +0000731
732template <class _Tp, class = void>
733struct __is_stashing_iterator : false_type {};
734
735template <class _Tp>
736struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
737 : true_type {};
738
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000740class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741 : public iterator<typename iterator_traits<_Iter>::iterator_category,
742 typename iterator_traits<_Iter>::value_type,
743 typename iterator_traits<_Iter>::difference_type,
744 typename iterator_traits<_Iter>::pointer,
745 typename iterator_traits<_Iter>::reference>
746{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000747private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000748 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000749
750 static_assert(!__is_stashing_iterator<_Iter>::value,
751 "The specified iterator type cannot be used with reverse_iterator; "
752 "Using stashing iterators with reverse_iterator causes undefined behavior");
753
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000754protected:
755 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000756public:
757 typedef _Iter iterator_type;
758 typedef typename iterator_traits<_Iter>::difference_type difference_type;
759 typedef typename iterator_traits<_Iter>::reference reference;
760 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000761
Marshall Clow5ace5542016-10-19 15:12:50 +0000762 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
763 reverse_iterator() : __t(), current() {}
764 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
765 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
766 template <class _Up>
767 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
768 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
769 template <class _Up>
770 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
771 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
772 { __t = current = __u.base(); return *this; }
773 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
774 _Iter base() const {return current;}
775 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
776 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
777 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
778 pointer operator->() const {return _VSTD::addressof(operator*());}
779 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
780 reverse_iterator& operator++() {--current; return *this;}
781 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
782 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
783 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
784 reverse_iterator& operator--() {++current; return *this;}
785 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
786 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
787 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
788 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
789 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
790 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
791 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
792 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
793 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
794 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
795 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
796 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797};
798
799template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000800inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801bool
802operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
803{
804 return __x.base() == __y.base();
805}
806
807template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000808inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809bool
810operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
811{
812 return __x.base() > __y.base();
813}
814
815template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000816inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817bool
818operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
819{
820 return __x.base() != __y.base();
821}
822
823template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000824inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825bool
826operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
827{
828 return __x.base() < __y.base();
829}
830
831template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000832inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833bool
834operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
835{
836 return __x.base() <= __y.base();
837}
838
839template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000840inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841bool
842operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
843{
844 return __x.base() >= __y.base();
845}
846
Marshall Clow476d3f42016-07-18 13:19:00 +0000847#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000848template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000849inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000850auto
851operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
852-> decltype(__y.base() - __x.base())
853{
854 return __y.base() - __x.base();
855}
856#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857template <class _Iter1, class _Iter2>
858inline _LIBCPP_INLINE_VISIBILITY
859typename reverse_iterator<_Iter1>::difference_type
860operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
861{
862 return __y.base() - __x.base();
863}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000864#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000865
866template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000867inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868reverse_iterator<_Iter>
869operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
870{
871 return reverse_iterator<_Iter>(__x.base() - __n);
872}
873
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000874#if _LIBCPP_STD_VER > 11
875template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000876inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000877reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
878{
879 return reverse_iterator<_Iter>(__i);
880}
881#endif
882
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000884class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000885 : public iterator<output_iterator_tag,
886 void,
887 void,
888 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000889 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890{
891protected:
892 _Container* container;
893public:
894 typedef _Container container_type;
895
Marshall Clowcef31682014-03-03 19:20:40 +0000896 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000897 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
898 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000899#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf074022011-10-22 20:59:45 +0000900 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
901 {container->push_back(_VSTD::move(__value_)); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000902#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
904 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
905 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
906};
907
908template <class _Container>
909inline _LIBCPP_INLINE_VISIBILITY
910back_insert_iterator<_Container>
911back_inserter(_Container& __x)
912{
913 return back_insert_iterator<_Container>(__x);
914}
915
916template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000917class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918 : public iterator<output_iterator_tag,
919 void,
920 void,
921 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000922 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923{
924protected:
925 _Container* container;
926public:
927 typedef _Container container_type;
928
Marshall Clowcef31682014-03-03 19:20:40 +0000929 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000930 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
931 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000932#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf074022011-10-22 20:59:45 +0000933 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
934 {container->push_front(_VSTD::move(__value_)); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000935#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000936 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
937 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
938 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
939};
940
941template <class _Container>
942inline _LIBCPP_INLINE_VISIBILITY
943front_insert_iterator<_Container>
944front_inserter(_Container& __x)
945{
946 return front_insert_iterator<_Container>(__x);
947}
948
949template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000950class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951 : public iterator<output_iterator_tag,
952 void,
953 void,
954 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000955 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000956{
957protected:
958 _Container* container;
959 typename _Container::iterator iter;
960public:
961 typedef _Container container_type;
962
963 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000964 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000965 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
966 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000967#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf074022011-10-22 20:59:45 +0000968 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
969 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000970#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
972 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
973 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
974};
975
976template <class _Container>
977inline _LIBCPP_INLINE_VISIBILITY
978insert_iterator<_Container>
979inserter(_Container& __x, typename _Container::iterator __i)
980{
981 return insert_iterator<_Container>(__x, __i);
982}
983
984template <class _Tp, class _CharT = char,
985 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000986class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
988{
989public:
990 typedef _CharT char_type;
991 typedef _Traits traits_type;
992 typedef basic_istream<_CharT,_Traits> istream_type;
993private:
994 istream_type* __in_stream_;
995 _Tp __value_;
996public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500997 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000998 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000999 {
1000 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001001 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002 }
1003
1004 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +00001005 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
1007 {
1008 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001009 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010 return *this;
1011 }
1012 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
1013 {istream_iterator __t(*this); ++(*this); return __t;}
1014
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001015 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001017 bool
1018 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
1019 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001021 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001023 bool
1024 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
1025 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001026};
1027
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001028template <class _Tp, class _CharT, class _Traits, class _Distance>
1029inline _LIBCPP_INLINE_VISIBILITY
1030bool
1031operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
1032 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
1033{
1034 return __x.__in_stream_ == __y.__in_stream_;
1035}
1036
1037template <class _Tp, class _CharT, class _Traits, class _Distance>
1038inline _LIBCPP_INLINE_VISIBILITY
1039bool
1040operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
1041 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
1042{
1043 return !(__x == __y);
1044}
1045
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001047class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 : public iterator<output_iterator_tag, void, void, void, void>
1049{
1050public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001051 typedef output_iterator_tag iterator_category;
1052 typedef void value_type;
1053#if _LIBCPP_STD_VER > 17
1054 typedef std::ptrdiff_t difference_type;
1055#else
1056 typedef void difference_type;
1057#endif
1058 typedef void pointer;
1059 typedef void reference;
1060 typedef _CharT char_type;
1061 typedef _Traits traits_type;
1062 typedef basic_ostream<_CharT, _Traits> ostream_type;
1063
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064private:
1065 ostream_type* __out_stream_;
1066 const char_type* __delim_;
1067public:
Marshall Clow27a89512016-10-12 16:13:48 +00001068 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -05001069 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +00001070 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +00001071 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +00001072 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073 {
Howard Hinnantbf074022011-10-22 20:59:45 +00001074 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075 if (__delim_)
1076 *__out_stream_ << __delim_;
1077 return *this;
1078 }
1079
1080 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
1081 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
1082 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
1083};
1084
1085template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001086class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 : public iterator<input_iterator_tag, _CharT,
1088 typename _Traits::off_type, _CharT*,
1089 _CharT>
1090{
1091public:
1092 typedef _CharT char_type;
1093 typedef _Traits traits_type;
1094 typedef typename _Traits::int_type int_type;
1095 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1096 typedef basic_istream<_CharT,_Traits> istream_type;
1097private:
Howard Hinnant3e57b272012-11-16 22:17:23 +00001098 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099
1100 class __proxy
1101 {
1102 char_type __keep_;
1103 streambuf_type* __sbuf_;
1104 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
1105 : __keep_(__c), __sbuf_(__s) {}
1106 friend class istreambuf_iterator;
1107 public:
1108 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
1109 };
1110
Howard Hinnant756c69b2010-09-22 16:48:34 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +00001112 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113 {
1114 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001115 __sbuf_ = nullptr;
1116 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117 }
1118public:
Bruce Mitchener170d8972020-11-24 12:53:53 -05001119 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001120 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001121 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001122 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001123 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001124 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001125 : __sbuf_(__p.__sbuf_) {}
1126
Howard Hinnant28b24882011-12-01 20:21:04 +00001127 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1128 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001129 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1130 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001131 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132 return *this;
1133 }
1134 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1135 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001136 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 }
1138
1139 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001140 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141};
1142
1143template <class _CharT, class _Traits>
1144inline _LIBCPP_INLINE_VISIBILITY
1145bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1146 const istreambuf_iterator<_CharT,_Traits>& __b)
1147 {return __a.equal(__b);}
1148
1149template <class _CharT, class _Traits>
1150inline _LIBCPP_INLINE_VISIBILITY
1151bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1152 const istreambuf_iterator<_CharT,_Traits>& __b)
1153 {return !__a.equal(__b);}
1154
1155template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001156class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001157 : public iterator<output_iterator_tag, void, void, void, void>
1158{
1159public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001160 typedef output_iterator_tag iterator_category;
1161 typedef void value_type;
1162#if _LIBCPP_STD_VER > 17
1163 typedef std::ptrdiff_t difference_type;
1164#else
1165 typedef void difference_type;
1166#endif
1167 typedef void pointer;
1168 typedef void reference;
1169 typedef _CharT char_type;
1170 typedef _Traits traits_type;
1171 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1172 typedef basic_ostream<_CharT, _Traits> ostream_type;
1173
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174private:
1175 streambuf_type* __sbuf_;
1176public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001177 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001179 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180 : __sbuf_(__s) {}
1181 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1182 {
1183 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001184 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185 return *this;
1186 }
1187 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1188 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1189 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001190 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001191
1192 template <class _Ch, class _Tr>
1193 friend
1194 _LIBCPP_HIDDEN
1195 ostreambuf_iterator<_Ch, _Tr>
1196 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1197 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1198 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199};
1200
1201template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001202class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203{
1204private:
1205 _Iter __i;
1206public:
1207 typedef _Iter iterator_type;
1208 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1209 typedef typename iterator_traits<iterator_type>::value_type value_type;
1210 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001211 typedef iterator_type pointer;
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001212#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001213 typedef typename iterator_traits<iterator_type>::reference __reference;
1214 typedef typename conditional<
1215 is_reference<__reference>::value,
1216 typename remove_reference<__reference>::type&&,
1217 __reference
1218 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219#else
1220 typedef typename iterator_traits<iterator_type>::reference reference;
1221#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001222
Marshall Clowb5f99122016-11-02 15:30:26 +00001223 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1224 move_iterator() : __i() {}
1225 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1226 explicit move_iterator(_Iter __x) : __i(__x) {}
1227 template <class _Up>
1228 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1229 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1230 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001231 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001232 reference operator*() const { return static_cast<reference>(*__i); }
1233 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1234 pointer operator->() const { return __i;}
1235 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1236 move_iterator& operator++() {++__i; return *this;}
1237 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1238 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1239 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1240 move_iterator& operator--() {--__i; return *this;}
1241 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1242 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1243 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1244 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1245 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1246 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1247 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1248 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1249 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1250 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1251 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1252 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253};
1254
1255template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001256inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257bool
1258operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1259{
1260 return __x.base() == __y.base();
1261}
1262
1263template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001264inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265bool
1266operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1267{
1268 return __x.base() < __y.base();
1269}
1270
1271template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001272inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273bool
1274operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1275{
1276 return __x.base() != __y.base();
1277}
1278
1279template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001280inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281bool
1282operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1283{
1284 return __x.base() > __y.base();
1285}
1286
1287template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001288inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289bool
1290operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1291{
1292 return __x.base() >= __y.base();
1293}
1294
1295template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001296inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297bool
1298operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1299{
1300 return __x.base() <= __y.base();
1301}
1302
Marshall Clow476d3f42016-07-18 13:19:00 +00001303#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001304template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001305inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001306auto
1307operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1308-> decltype(__x.base() - __y.base())
1309{
1310 return __x.base() - __y.base();
1311}
1312#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313template <class _Iter1, class _Iter2>
1314inline _LIBCPP_INLINE_VISIBILITY
1315typename move_iterator<_Iter1>::difference_type
1316operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1317{
1318 return __x.base() - __y.base();
1319}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001320#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321
1322template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001323inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324move_iterator<_Iter>
1325operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1326{
1327 return move_iterator<_Iter>(__x.base() + __n);
1328}
1329
1330template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001331inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001332move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001333make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001334{
1335 return move_iterator<_Iter>(__i);
1336}
1337
1338// __wrap_iter
1339
1340template <class _Iter> class __wrap_iter;
1341
1342template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001343_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001344bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001345operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346
1347template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001348_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001349bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001350operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001351
1352template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001353_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001354bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001355operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001356
1357template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001358_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001359bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001360operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001361
1362template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001363_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001365operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366
1367template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001368_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001370operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371
Marshall Clow476d3f42016-07-18 13:19:00 +00001372#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001373template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001374_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001375auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001376operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001377-> decltype(__x.base() - __y.base());
1378#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001380_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001382operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001383#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001384
1385template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001386_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001388operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389
Louis Dionne65b433b2019-11-06 12:02:41 +00001390template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1391template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001392template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1393template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394
Eric Fiselier38badb82016-12-28 05:35:32 +00001395#if _LIBCPP_DEBUG_LEVEL < 2
1396
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397template <class _Tp>
zoecarverd0279de2020-09-14 18:11:08 -04001398_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399typename enable_if
1400<
Howard Hinnanta9a897e2010-11-19 22:17:28 +00001401 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402 _Tp*
1403>::type
1404__unwrap_iter(__wrap_iter<_Tp*>);
1405
Eric Fiselier38badb82016-12-28 05:35:32 +00001406#else
1407
1408template <class _Tp>
zoecarverd0279de2020-09-14 18:11:08 -04001409inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Eric Fiselier38badb82016-12-28 05:35:32 +00001410typename enable_if
1411<
1412 is_trivially_copy_assignable<_Tp>::value,
1413 __wrap_iter<_Tp*>
1414>::type
1415__unwrap_iter(__wrap_iter<_Tp*> __i);
1416
1417#endif
1418
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419template <class _Iter>
1420class __wrap_iter
1421{
1422public:
1423 typedef _Iter iterator_type;
1424 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1425 typedef typename iterator_traits<iterator_type>::value_type value_type;
1426 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1427 typedef typename iterator_traits<iterator_type>::pointer pointer;
1428 typedef typename iterator_traits<iterator_type>::reference reference;
1429private:
1430 iterator_type __i;
1431public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001432 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001433#if _LIBCPP_STD_VER > 11
1434 : __i{}
1435#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001436 {
Louis Dionneba400782020-10-02 15:02:52 -04001437#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001438 __get_db()->__insert_i(this);
1439#endif
1440 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001441 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1442 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001443 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001444 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001445 {
Louis Dionneba400782020-10-02 15:02:52 -04001446#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001447 __get_db()->__iterator_copy(this, &__u);
1448#endif
1449 }
Louis Dionneba400782020-10-02 15:02:52 -04001450#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001451 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001452 __wrap_iter(const __wrap_iter& __x)
1453 : __i(__x.base())
1454 {
1455 __get_db()->__iterator_copy(this, &__x);
1456 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001457 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001458 __wrap_iter& operator=(const __wrap_iter& __x)
1459 {
1460 if (this != &__x)
1461 {
1462 __get_db()->__iterator_copy(this, &__x);
1463 __i = __x.__i;
1464 }
1465 return *this;
1466 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001467 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001468 ~__wrap_iter()
1469 {
1470 __get_db()->__erase_i(this);
1471 }
1472#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001473 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001474 {
Louis Dionneba400782020-10-02 15:02:52 -04001475#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001476 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1477 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001478#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001479 return *__i;
1480 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001481 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001482 {
Louis Dionneba400782020-10-02 15:02:52 -04001483#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001484 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1485 "Attempted to dereference a non-dereferenceable iterator");
1486#endif
Marshall Clowd85a0562016-04-11 03:54:53 +00001487 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001488 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001489 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001490 {
Louis Dionneba400782020-10-02 15:02:52 -04001491#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001492 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1493 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001494#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001495 ++__i;
1496 return *this;
1497 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001498 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001499 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001500
Eric Fiselier873b8d32019-03-18 21:50:12 +00001501 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001502 {
Louis Dionneba400782020-10-02 15:02:52 -04001503#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001504 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1505 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001506#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001507 --__i;
1508 return *this;
1509 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001510 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001511 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001512 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001513 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001514 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001515 {
Louis Dionneba400782020-10-02 15:02:52 -04001516#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001517 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1518 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001519#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001520 __i += __n;
1521 return *this;
1522 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001523 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001524 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001525 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001526 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001527 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001528 {
Louis Dionneba400782020-10-02 15:02:52 -04001529#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001530 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1531 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001532#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001533 return __i[__n];
1534 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001535
Eric Fiselier873b8d32019-03-18 21:50:12 +00001536 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001537
1538private:
Louis Dionneba400782020-10-02 15:02:52 -04001539#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001540 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001541 {
1542 __get_db()->__insert_ic(this, __p);
1543 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001544#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001545 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001546#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001547
1548 template <class _Up> friend class __wrap_iter;
1549 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001550 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001551 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552
1553 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001554 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001556 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001557
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001559 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001561 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001562
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001564 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001565 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001566 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001567
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001569 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001570 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001571 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001572
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001574 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001575 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001576 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001577
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001579 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001581 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001582
Marshall Clow476d3f42016-07-18 13:19:00 +00001583#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001584 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001585 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001586 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001587 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001588 -> decltype(__x.base() - __y.base());
1589#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001591 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001593 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001594#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001595
Howard Hinnantc51e1022010-05-11 19:42:16 +00001596 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001597 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001599 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600
Louis Dionne65b433b2019-11-06 12:02:41 +00001601 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op);
1602 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001603 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op move(_Ip, _Ip, _Op);
1604 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605
Eric Fiselier38badb82016-12-28 05:35:32 +00001606#if _LIBCPP_DEBUG_LEVEL < 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607 template <class _Tp>
zoecarverd0279de2020-09-14 18:11:08 -04001608 _LIBCPP_CONSTEXPR friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609 typename enable_if
1610 <
Howard Hinnanta9a897e2010-11-19 22:17:28 +00001611 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001612 _Tp*
1613 >::type
1614 __unwrap_iter(__wrap_iter<_Tp*>);
Eric Fiselier38badb82016-12-28 05:35:32 +00001615#else
1616 template <class _Tp>
Louis Dionne2c5a8c12020-09-15 14:19:06 -04001617 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR friend
Eric Fiselier38badb82016-12-28 05:35:32 +00001618 typename enable_if
1619 <
1620 is_trivially_copy_assignable<_Tp>::value,
1621 __wrap_iter<_Tp*>
1622 >::type
1623 __unwrap_iter(__wrap_iter<_Tp*> __i);
1624#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625};
1626
1627template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001628inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001630operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631{
1632 return __x.base() == __y.base();
1633}
1634
1635template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001636inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001638operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001639{
Louis Dionneba400782020-10-02 15:02:52 -04001640#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001641 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001642 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001643#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644 return __x.base() < __y.base();
1645}
1646
1647template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001648inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001649bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001650operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001652 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653}
1654
1655template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001656inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001657bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001658operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001660 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001661}
1662
1663template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001664inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001665bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001666operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001667{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001668 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669}
1670
1671template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001672inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001673bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001674operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001675{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001676 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001677}
1678
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001679template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001680inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001681bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001682operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001683{
1684 return !(__x == __y);
1685}
1686
1687template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001688inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001689bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001690operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001691{
1692 return __y < __x;
1693}
1694
1695template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001696inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001697bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001698operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001699{
1700 return !(__x < __y);
1701}
1702
1703template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001704inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001705bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001706operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001707{
1708 return !(__y < __x);
1709}
1710
Marshall Clow476d3f42016-07-18 13:19:00 +00001711#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001712template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001713inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001714auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001715operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001716-> decltype(__x.base() - __y.base())
1717{
Louis Dionneba400782020-10-02 15:02:52 -04001718#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001719 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1720 "Attempted to subtract incompatible iterators");
1721#endif
1722 return __x.base() - __y.base();
1723}
1724#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001725template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001726inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001727typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001728operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001729{
Louis Dionneba400782020-10-02 15:02:52 -04001730#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001731 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001732 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001733#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734 return __x.base() - __y.base();
1735}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001736#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001737
1738template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001739inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740__wrap_iter<_Iter>
1741operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001742 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001743{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001744 __x += __n;
1745 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001746}
1747
Marshall Clow039b2f02016-01-13 21:54:34 +00001748template <class _Iter>
1749struct __libcpp_is_trivial_iterator
Marshall Clowb5f99122016-11-02 15:30:26 +00001750 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
Louis Dionne173f29e2019-05-29 16:01:36 +00001751
Marshall Clow039b2f02016-01-13 21:54:34 +00001752template <class _Iter>
1753struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001754 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001755
1756template <class _Iter>
1757struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001758 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001759
1760template <class _Iter>
1761struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001762 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001763
1764
Marshall Clow8411ebf2013-12-02 03:24:33 +00001765template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001766_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001767_Tp*
1768begin(_Tp (&__array)[_Np])
1769{
1770 return __array;
1771}
1772
1773template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001774_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001775_Tp*
1776end(_Tp (&__array)[_Np])
1777{
1778 return __array + _Np;
1779}
1780
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001781#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001782
Howard Hinnantc834c512011-11-29 18:15:50 +00001783template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001784_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001785auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001786begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001787{
1788 return __c.begin();
1789}
1790
Howard Hinnantc834c512011-11-29 18:15:50 +00001791template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001792_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001793auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001794begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001795{
1796 return __c.begin();
1797}
1798
Howard Hinnantc834c512011-11-29 18:15:50 +00001799template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001800_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001801auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001802end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001803{
1804 return __c.end();
1805}
1806
Howard Hinnantc834c512011-11-29 18:15:50 +00001807template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001808_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001809auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001810end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001811{
1812 return __c.end();
1813}
1814
Marshall Clowb278e9c2013-08-30 01:17:07 +00001815#if _LIBCPP_STD_VER > 11
1816
Marshall Clow8411ebf2013-12-02 03:24:33 +00001817template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001818_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001819reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1820{
1821 return reverse_iterator<_Tp*>(__array + _Np);
1822}
1823
1824template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001825_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001826reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1827{
1828 return reverse_iterator<_Tp*>(__array);
1829}
1830
1831template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001832_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001833reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1834{
1835 return reverse_iterator<const _Ep*>(__il.end());
1836}
1837
1838template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001839_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001840reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1841{
1842 return reverse_iterator<const _Ep*>(__il.begin());
1843}
1844
Marshall Clowb278e9c2013-08-30 01:17:07 +00001845template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001846_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001847auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001848{
Marshall Clow3862f532016-08-10 20:04:46 +00001849 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001850}
1851
1852template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001853_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001854auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001855{
Marshall Clow3862f532016-08-10 20:04:46 +00001856 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001857}
1858
1859template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001860_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001861auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1862{
1863 return __c.rbegin();
1864}
1865
1866template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001867_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001868auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1869{
1870 return __c.rbegin();
1871}
1872
1873template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001874_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001875auto rend(_Cp& __c) -> decltype(__c.rend())
1876{
1877 return __c.rend();
1878}
1879
1880template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001881_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001882auto rend(const _Cp& __c) -> decltype(__c.rend())
1883{
1884 return __c.rend();
1885}
1886
1887template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001888_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001889auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001890{
Marshall Clow3862f532016-08-10 20:04:46 +00001891 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001892}
1893
1894template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001895_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001896auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001897{
Marshall Clow3862f532016-08-10 20:04:46 +00001898 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001899}
1900
1901#endif
1902
1903
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001904#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001905
Howard Hinnantc834c512011-11-29 18:15:50 +00001906template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001907_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001908typename _Cp::iterator
1909begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001910{
1911 return __c.begin();
1912}
1913
Howard Hinnantc834c512011-11-29 18:15:50 +00001914template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001915_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001916typename _Cp::const_iterator
1917begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001918{
1919 return __c.begin();
1920}
1921
Howard Hinnantc834c512011-11-29 18:15:50 +00001922template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001923_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001924typename _Cp::iterator
1925end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926{
1927 return __c.end();
1928}
1929
Howard Hinnantc834c512011-11-29 18:15:50 +00001930template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001931_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001932typename _Cp::const_iterator
1933end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001934{
1935 return __c.end();
1936}
1937
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001938#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001939
Marshall Clowef357272014-11-19 19:43:23 +00001940#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001941
1942// #if _LIBCPP_STD_VER > 11
1943// template <>
1944// struct _LIBCPP_TEMPLATE_VIS plus<void>
1945// {
1946// template <class _T1, class _T2>
1947// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1948// auto operator()(_T1&& __t, _T2&& __u) const
1949// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1950// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1951// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1952// typedef void is_transparent;
1953// };
1954// #endif
1955
Marshall Clowc4b4a342015-02-11 16:14:01 +00001956template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001957_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001958constexpr auto size(const _Cont& __c)
1959_NOEXCEPT_(noexcept(__c.size()))
1960-> decltype (__c.size())
1961{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001962
Marshall Clowc4b4a342015-02-11 16:14:01 +00001963template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001964_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001965constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001966
Marshall Clow3c5363e2019-02-27 02:58:56 +00001967#if _LIBCPP_STD_VER > 17
1968template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001969_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001970constexpr auto ssize(const _Cont& __c)
1971_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1972-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1973{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1974
1975template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001976_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001977constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1978#endif
1979
Marshall Clowc4b4a342015-02-11 16:14:01 +00001980template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001981_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001982constexpr auto empty(const _Cont& __c)
1983_NOEXCEPT_(noexcept(__c.empty()))
1984-> decltype (__c.empty())
1985{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001986
Marshall Clowc4b4a342015-02-11 16:14:01 +00001987template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001988_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001989constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001990
1991template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001992_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001993constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1994
Marshall Clowc4b4a342015-02-11 16:14:01 +00001995template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001996_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001997auto data(_Cont& __c)
1998_NOEXCEPT_(noexcept(__c.data()))
1999-> decltype (__c.data())
2000{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00002001
Marshall Clowc4b4a342015-02-11 16:14:01 +00002002template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00002003_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00002004auto data(const _Cont& __c)
2005_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00002006-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00002007{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00002008
Marshall Clowc4b4a342015-02-11 16:14:01 +00002009template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00002010_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00002011constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00002012
2013template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00002014_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00002015constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
2016#endif
2017
2018
Howard Hinnantc51e1022010-05-11 19:42:16 +00002019_LIBCPP_END_NAMESPACE_STD
2020
2021#endif // _LIBCPP_ITERATOR