blob: 78f67ddf222902d6176a6d2cf5203ca08165118f [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
Christopher Di Bella490fe402021-03-23 03:55:52 +000016#include <concepts>
17
Howard Hinnantc51e1022010-05-11 19:42:16 +000018namespace std
19{
Christopher Di Bellae00eebc2021-03-23 20:48:41 +000020template<class> struct incrementable_traits; // since C++20
Christopher Di Bellaa3a10062021-04-20 18:56:08 +000021template<class T>
22 using iter_difference_t = see below; // since C++20
23
Christopher Di Bellae00eebc2021-03-23 20:48:41 +000024template<class> struct indirectly_readable_traits; // since C++20
Christopher Di Bellaa3a10062021-04-20 18:56:08 +000025template<class T>
26 using iter_value_t = see below; // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000027
28template<class Iterator>
zoecarver9f1e2972021-04-20 08:50:11 -040029struct iterator_traits;
Howard Hinnantc51e1022010-05-11 19:42:16 +000030
31template<class T>
zoecarver9f1e2972021-04-20 08:50:11 -040032 requires is_object_v<T> // since C++20
33struct iterator_traits<T*>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000034
Christopher Di Bella875636f2021-04-04 05:12:46 +000035template<dereferenceable T>
36 using iter_reference_t = decltype(*declval<T&>());
37
Louis Dionneca989a52021-04-20 14:40:43 -040038namespace ranges::inline unspecified {
39 inline constexpr unspecified iter_move = unspecified; // since C++20, nodiscard as an extension
40}}
41
42template<dereferenceable T>
43 requires ...
44using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // since C++20
45
Louis Dionne463afb82021-04-22 11:05:30 -040046// [iterator.concepts], iterator concepts
47// [iterator.concept.readable], concept indirectly_readable
48template<class In>
49 concept indirectly_readable = see below; // since C++20
50
51// [iterator.concept.writable], concept indirectly_writable
52template<class Out, class T>
53 concept indirectly_writable = see below; // since C++20
54
Mark de Wever6639f422021-04-26 17:53:20 +020055// [iterator.concept.winc], concept weakly_incrementable
Christopher Di Bella54ffc182021-04-23 18:22:55 -070056template<class I>
57 concept weakly_incrementable = see below; // since C++20
58
59// [iterator.concept.inc], concept incrementable
60template<class I>
61 concept incrementable = see below; // since C++20
62
Mark de Wever6639f422021-04-26 17:53:20 +020063// [iterator.concept.iterator], concept input_or_output_iterator
Christopher Di Bella0ef52282021-04-09 02:10:32 +000064 template<class I>
65 concept input_or_output_iterator = see below; // since C++20
66
Mark de Wever6639f422021-04-26 17:53:20 +020067// [iterator.concept.sentinel], concept sentinel_for
Christopher Di Bella0ef52282021-04-09 02:10:32 +000068template<class S, class I>
69 concept sentinel_for = see below; // since C++20
70
zoecarver11391bc2021-04-26 09:35:47 -070071// [iterator.concept.sizedsentinel], concept sized_sentinel_for
72template<class S, class I>
73 inline constexpr bool disable_sized_sentinel_for = false;
74
75template<class S, class I>
76 concept sized_sentinel_for = see below;
77
Christopher Di Bella8250c632021-04-11 19:04:52 +000078// [iterator.concept.input], concept input_iterator
79template<class I>
80 concept input_iterator = see below; // since C++20
81
Christopher Di Bella8f1370d2021-04-11 22:11:03 +000082// [iterator.concept.forward], concept forward_iterator
83template<class I>
84 concept forward_iterator = see below; // since C++20
85
Howard Hinnantc51e1022010-05-11 19:42:16 +000086template<class Category, class T, class Distance = ptrdiff_t,
87 class Pointer = T*, class Reference = T&>
88struct iterator
89{
90 typedef T value_type;
91 typedef Distance difference_type;
92 typedef Pointer pointer;
93 typedef Reference reference;
94 typedef Category iterator_category;
95};
96
97struct input_iterator_tag {};
98struct output_iterator_tag {};
99struct forward_iterator_tag : public input_iterator_tag {};
100struct bidirectional_iterator_tag : public forward_iterator_tag {};
101struct random_access_iterator_tag : public bidirectional_iterator_tag {};
102
Marshall Clow75468e72017-05-17 18:51:36 +0000103// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -0400104template <class InputIterator, class Distance> // constexpr in C++17
105 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000106
Marshall Clow75468e72017-05-17 18:51:36 +0000107template <class InputIterator> // constexpr in C++17
108 constexpr typename iterator_traits<InputIterator>::difference_type
109 distance(InputIterator first, InputIterator last);
110
111template <class InputIterator> // constexpr in C++17
112 constexpr InputIterator next(InputIterator x,
113typename iterator_traits<InputIterator>::difference_type n = 1);
114
115template <class BidirectionalIterator> // constexpr in C++17
116 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +0000117 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000118
119template <class Iterator>
120class reverse_iterator
121 : public iterator<typename iterator_traits<Iterator>::iterator_category,
122 typename iterator_traits<Iterator>::value_type,
123 typename iterator_traits<Iterator>::difference_type,
124 typename iterator_traits<Iterator>::pointer,
125 typename iterator_traits<Iterator>::reference>
126{
127protected:
128 Iterator current;
129public:
130 typedef Iterator iterator_type;
131 typedef typename iterator_traits<Iterator>::difference_type difference_type;
132 typedef typename iterator_traits<Iterator>::reference reference;
133 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000134
Marshall Clow5ace5542016-10-19 15:12:50 +0000135 constexpr reverse_iterator();
136 constexpr explicit reverse_iterator(Iterator x);
137 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
138 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
139 constexpr Iterator base() const;
140 constexpr reference operator*() const;
141 constexpr pointer operator->() const;
142 constexpr reverse_iterator& operator++();
143 constexpr reverse_iterator operator++(int);
144 constexpr reverse_iterator& operator--();
145 constexpr reverse_iterator operator--(int);
146 constexpr reverse_iterator operator+ (difference_type n) const;
147 constexpr reverse_iterator& operator+=(difference_type n);
148 constexpr reverse_iterator operator- (difference_type n) const;
149 constexpr reverse_iterator& operator-=(difference_type n);
150 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151};
152
153template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000154constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
156
157template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000158constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
160
161template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000162constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
164
165template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000166constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
168
169template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000170constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
172
173template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000174constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
176
177template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000178constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000179operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000180-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181
182template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000183constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000184operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000185 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186
Marshall Clow5ace5542016-10-19 15:12:50 +0000187template <class Iterator>
188constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000189
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190template <class Container>
191class back_insert_iterator
192{
193protected:
194 Container* container;
195public:
196 typedef Container container_type;
197 typedef void value_type;
198 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000199 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200 typedef void pointer;
201
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500202 explicit back_insert_iterator(Container& x); // constexpr in C++20
203 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
204 back_insert_iterator& operator*(); // constexpr in C++20
205 back_insert_iterator& operator++(); // constexpr in C++20
206 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207};
208
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500209template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210
211template <class Container>
212class front_insert_iterator
213{
214protected:
215 Container* container;
216public:
217 typedef Container container_type;
218 typedef void value_type;
219 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000220 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221 typedef void pointer;
222
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500223 explicit front_insert_iterator(Container& x); // constexpr in C++20
224 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
225 front_insert_iterator& operator*(); // constexpr in C++20
226 front_insert_iterator& operator++(); // constexpr in C++20
227 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228};
229
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500230template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000231
232template <class Container>
233class insert_iterator
234{
235protected:
236 Container* container;
237 typename Container::iterator iter;
238public:
239 typedef Container container_type;
240 typedef void value_type;
241 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000242 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243 typedef void pointer;
244
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500245 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
246 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
247 insert_iterator& operator*(); // constexpr in C++20
248 insert_iterator& operator++(); // constexpr in C++20
249 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250};
251
252template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500253insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000255template <class Iterator>
256class move_iterator {
257public:
258 typedef Iterator iterator_type;
259 typedef typename iterator_traits<Iterator>::difference_type difference_type;
260 typedef Iterator pointer;
261 typedef typename iterator_traits<Iterator>::value_type value_type;
262 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
263 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000264
Marshall Clowb5f99122016-11-02 15:30:26 +0000265 constexpr move_iterator(); // all the constexprs are in C++17
266 constexpr explicit move_iterator(Iterator i);
267 template <class U>
268 constexpr move_iterator(const move_iterator<U>& u);
269 template <class U>
270 constexpr move_iterator& operator=(const move_iterator<U>& u);
271 constexpr iterator_type base() const;
272 constexpr reference operator*() const;
273 constexpr pointer operator->() const;
274 constexpr move_iterator& operator++();
275 constexpr move_iterator operator++(int);
276 constexpr move_iterator& operator--();
277 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000278 constexpr move_iterator operator+(difference_type n) const;
279 constexpr move_iterator& operator+=(difference_type n);
280 constexpr move_iterator operator-(difference_type n) const;
281 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000282 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000283private:
284 Iterator current; // exposition only
285};
286
287template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000288constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000289operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
290
291template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000292constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000293operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
294
295template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000296constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000297operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
298
299template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000300constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000301operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
302
303template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000304constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000305operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
306
307template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000308constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000309operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
310
311template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000312constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000313operator-(const move_iterator<Iterator1>& x,
314 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
315
316template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000317constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000318 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000319 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000320
Marshall Clowb5f99122016-11-02 15:30:26 +0000321template <class Iterator> // constexpr in C++17
322constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000323
324
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
326class istream_iterator
327 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
328{
329public:
330 typedef charT char_type;
331 typedef traits traits_type;
332 typedef basic_istream<charT,traits> istream_type;
333
Marshall Clow0735e4e2015-04-16 21:36:54 +0000334 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000335 istream_iterator(istream_type& s);
336 istream_iterator(const istream_iterator& x);
337 ~istream_iterator();
338
339 const T& operator*() const;
340 const T* operator->() const;
341 istream_iterator& operator++();
342 istream_iterator operator++(int);
343};
344
345template <class T, class charT, class traits, class Distance>
346bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
347 const istream_iterator<T,charT,traits,Distance>& y);
348template <class T, class charT, class traits, class Distance>
349bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
350 const istream_iterator<T,charT,traits,Distance>& y);
351
352template <class T, class charT = char, class traits = char_traits<charT> >
353class ostream_iterator
354 : public iterator<output_iterator_tag, void, void, void ,void>
355{
356public:
357 typedef charT char_type;
358 typedef traits traits_type;
359 typedef basic_ostream<charT,traits> ostream_type;
360
361 ostream_iterator(ostream_type& s);
362 ostream_iterator(ostream_type& s, const charT* delimiter);
363 ostream_iterator(const ostream_iterator& x);
364 ~ostream_iterator();
365 ostream_iterator& operator=(const T& value);
366
367 ostream_iterator& operator*();
368 ostream_iterator& operator++();
369 ostream_iterator& operator++(int);
370};
371
372template<class charT, class traits = char_traits<charT> >
373class istreambuf_iterator
374 : public iterator<input_iterator_tag, charT,
375 typename traits::off_type, unspecified,
376 charT>
377{
378public:
379 typedef charT char_type;
380 typedef traits traits_type;
381 typedef typename traits::int_type int_type;
382 typedef basic_streambuf<charT,traits> streambuf_type;
383 typedef basic_istream<charT,traits> istream_type;
384
Howard Hinnant011138d2012-07-20 19:36:34 +0000385 istreambuf_iterator() noexcept;
386 istreambuf_iterator(istream_type& s) noexcept;
387 istreambuf_iterator(streambuf_type* s) noexcept;
388 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389
390 charT operator*() const;
391 pointer operator->() const;
392 istreambuf_iterator& operator++();
393 a-private-type operator++(int);
394
395 bool equal(const istreambuf_iterator& b) const;
396};
397
398template <class charT, class traits>
399bool operator==(const istreambuf_iterator<charT,traits>& a,
400 const istreambuf_iterator<charT,traits>& b);
401template <class charT, class traits>
402bool operator!=(const istreambuf_iterator<charT,traits>& a,
403 const istreambuf_iterator<charT,traits>& b);
404
405template <class charT, class traits = char_traits<charT> >
406class ostreambuf_iterator
407 : public iterator<output_iterator_tag, void, void, void, void>
408{
409public:
410 typedef charT char_type;
411 typedef traits traits_type;
412 typedef basic_streambuf<charT,traits> streambuf_type;
413 typedef basic_ostream<charT,traits> ostream_type;
414
Howard Hinnant011138d2012-07-20 19:36:34 +0000415 ostreambuf_iterator(ostream_type& s) noexcept;
416 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417 ostreambuf_iterator& operator=(charT c);
418 ostreambuf_iterator& operator*();
419 ostreambuf_iterator& operator++();
420 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000421 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422};
423
Marshall Clow99ba0022017-01-04 17:58:17 +0000424template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
425template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
426template <class C> constexpr auto end(C& c) -> decltype(c.end());
427template <class C> constexpr auto end(const C& c) -> decltype(c.end());
428template <class T, size_t N> constexpr T* begin(T (&array)[N]);
429template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430
Marshall Clow99ba0022017-01-04 17:58:17 +0000431template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
432template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
433template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
434template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
435template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
436template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
437template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
438template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
439template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
440template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
441template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
442template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000443
Marshall Clowef357272014-11-19 19:43:23 +0000444// 24.8, container access:
445template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
446template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000447
448template <class C> constexpr auto ssize(const C& c)
Arthur O'Dwyer2fc9b5d2021-04-17 17:03:20 -0400449 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
Marshall Clow3c5363e2019-02-27 02:58:56 +0000450template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
451
Marshall Clowef357272014-11-19 19:43:23 +0000452template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
453template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
454template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
455template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
456template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
457template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
458template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
459
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460} // std
461
462*/
463
464#include <__config>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400465#include <__debug>
Marshall Clow3dc05502014-02-27 02:11:50 +0000466#include <__functional_base>
Louis Dionne463afb82021-04-22 11:05:30 -0400467#include <__iterator/concepts.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400468#include <__iterator/incrementable_traits.h>
Louis Dionneca989a52021-04-20 14:40:43 -0400469#include <__iterator/iter_move.h>
zoecarver5d41ff52021-04-19 14:44:42 -0700470#include <__iterator/iterator_traits.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400471#include <__iterator/readable_traits.h>
Louis Dionne735bc462021-04-14 13:59:03 -0400472#include <__memory/addressof.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500473#include <__memory/pointer_traits.h>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400474#include <compare>
475#include <concepts> // Mandated by the Standard.
476#include <cstddef>
477#include <initializer_list>
478#include <iosfwd> // for forward declarations of vector and string
479#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000480#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000481
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000482#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000484#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485
486_LIBCPP_BEGIN_NAMESPACE_STD
Christopher Di Bella490fe402021-03-23 03:55:52 +0000487
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488template<class _Category, class _Tp, class _Distance = ptrdiff_t,
489 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000490struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491{
492 typedef _Tp value_type;
493 typedef _Distance difference_type;
494 typedef _Pointer pointer;
495 typedef _Reference reference;
496 typedef _Category iterator_category;
497};
498
499template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000500inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501void __advance(_InputIter& __i,
502 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
503{
504 for (; __n > 0; --__n)
505 ++__i;
506}
507
508template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000509inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510void __advance(_BiDirIter& __i,
511 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
512{
513 if (__n >= 0)
514 for (; __n > 0; --__n)
515 ++__i;
516 else
517 for (; __n < 0; ++__n)
518 --__i;
519}
520
521template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000522inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523void __advance(_RandIter& __i,
524 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
525{
526 __i += __n;
527}
528
Louis Dionne45768662020-06-08 16:16:01 -0400529template <class _InputIter, class _Distance>
Marshall Clow75468e72017-05-17 18:51:36 +0000530inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Louis Dionne45768662020-06-08 16:16:01 -0400531void advance(_InputIter& __i, _Distance __orig_n)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532{
Louis Dionne45768662020-06-08 16:16:01 -0400533 _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
534 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500535 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
Louis Dionne45768662020-06-08 16:16:01 -0400536 _IntegralSize __n = __orig_n;
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500537 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538}
539
540template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000541inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542typename iterator_traits<_InputIter>::difference_type
543__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
544{
545 typename iterator_traits<_InputIter>::difference_type __r(0);
546 for (; __first != __last; ++__first)
547 ++__r;
548 return __r;
549}
550
551template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000552inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553typename iterator_traits<_RandIter>::difference_type
554__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
555{
556 return __last - __first;
557}
558
559template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000560inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561typename iterator_traits<_InputIter>::difference_type
562distance(_InputIter __first, _InputIter __last)
563{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500564 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565}
566
Marshall Clow990c70d2015-11-07 17:48:49 +0000567template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000568inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000569typename enable_if
570<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500571 __is_cpp17_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000572 _InputIter
573>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000574next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000575 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500577 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400578 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
Marshall Clow3d435212019-03-22 22:32:20 +0000579
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000580 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581 return __x;
582}
583
Marshall Clow3d435212019-03-22 22:32:20 +0000584template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000585inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000586typename enable_if
587<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500588 __is_cpp17_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000589 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000590>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000591prev(_InputIter __x,
592 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500594 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400595 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000596 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597 return __x;
598}
599
Eric Fiselier883af112017-04-13 02:54:13 +0000600
601template <class _Tp, class = void>
602struct __is_stashing_iterator : false_type {};
603
604template <class _Tp>
605struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
606 : true_type {};
607
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000609class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 : public iterator<typename iterator_traits<_Iter>::iterator_category,
611 typename iterator_traits<_Iter>::value_type,
612 typename iterator_traits<_Iter>::difference_type,
613 typename iterator_traits<_Iter>::pointer,
614 typename iterator_traits<_Iter>::reference>
615{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000616private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000617 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000618
619 static_assert(!__is_stashing_iterator<_Iter>::value,
620 "The specified iterator type cannot be used with reverse_iterator; "
621 "Using stashing iterators with reverse_iterator causes undefined behavior");
622
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000623protected:
624 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625public:
626 typedef _Iter iterator_type;
627 typedef typename iterator_traits<_Iter>::difference_type difference_type;
628 typedef typename iterator_traits<_Iter>::reference reference;
629 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500630 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
631 random_access_iterator_tag,
632 typename iterator_traits<_Iter>::iterator_category> iterator_category;
633#if _LIBCPP_STD_VER > 17
634 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
635 random_access_iterator_tag,
636 bidirectional_iterator_tag> iterator_concept;
637#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000638
Marshall Clow5ace5542016-10-19 15:12:50 +0000639 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
640 reverse_iterator() : __t(), current() {}
641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
642 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
643 template <class _Up>
644 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
645 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
646 template <class _Up>
647 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
648 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
649 { __t = current = __u.base(); return *this; }
650 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
651 _Iter base() const {return current;}
652 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
653 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
654 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
655 pointer operator->() const {return _VSTD::addressof(operator*());}
656 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
657 reverse_iterator& operator++() {--current; return *this;}
658 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
659 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
661 reverse_iterator& operator--() {++current; return *this;}
662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
663 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
664 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
665 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
667 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
668 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
669 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
670 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
671 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
672 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
673 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674};
675
676template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000677inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678bool
679operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
680{
681 return __x.base() == __y.base();
682}
683
684template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000685inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686bool
687operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
688{
689 return __x.base() > __y.base();
690}
691
692template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000693inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694bool
695operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
696{
697 return __x.base() != __y.base();
698}
699
700template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000701inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702bool
703operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
704{
705 return __x.base() < __y.base();
706}
707
708template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000709inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710bool
711operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
712{
713 return __x.base() <= __y.base();
714}
715
716template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000717inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718bool
719operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
720{
721 return __x.base() >= __y.base();
722}
723
Marshall Clow476d3f42016-07-18 13:19:00 +0000724#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000725template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000726inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000727auto
728operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
729-> decltype(__y.base() - __x.base())
730{
731 return __y.base() - __x.base();
732}
733#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734template <class _Iter1, class _Iter2>
735inline _LIBCPP_INLINE_VISIBILITY
736typename reverse_iterator<_Iter1>::difference_type
737operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
738{
739 return __y.base() - __x.base();
740}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000741#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742
743template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000744inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745reverse_iterator<_Iter>
746operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
747{
748 return reverse_iterator<_Iter>(__x.base() - __n);
749}
750
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000751#if _LIBCPP_STD_VER > 11
752template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000753inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000754reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
755{
756 return reverse_iterator<_Iter>(__i);
757}
758#endif
759
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000761class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762 : public iterator<output_iterator_tag,
763 void,
764 void,
765 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000766 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000767{
768protected:
769 _Container* container;
770public:
771 typedef _Container container_type;
772
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500773 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
774 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000775 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000776#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500777 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000778 {container->push_back(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400779#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500780 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
781 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
782 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783};
784
785template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500786inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787back_insert_iterator<_Container>
788back_inserter(_Container& __x)
789{
790 return back_insert_iterator<_Container>(__x);
791}
792
793template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000794class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795 : public iterator<output_iterator_tag,
796 void,
797 void,
798 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000799 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800{
801protected:
802 _Container* container;
803public:
804 typedef _Container container_type;
805
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500806 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
807 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000808 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000809#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500810 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000811 {container->push_front(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400812#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500813 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
814 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
815 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816};
817
818template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500819inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820front_insert_iterator<_Container>
821front_inserter(_Container& __x)
822{
823 return front_insert_iterator<_Container>(__x);
824}
825
826template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000827class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828 : public iterator<output_iterator_tag,
829 void,
830 void,
831 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000832 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833{
834protected:
835 _Container* container;
836 typename _Container::iterator iter;
837public:
838 typedef _Container container_type;
839
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500840 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000841 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500842 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000843 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000844#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500845 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000846 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400847#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500848 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
849 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
850 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851};
852
853template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500854inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855insert_iterator<_Container>
856inserter(_Container& __x, typename _Container::iterator __i)
857{
858 return insert_iterator<_Container>(__x, __i);
859}
860
861template <class _Tp, class _CharT = char,
862 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000863class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
865{
866public:
867 typedef _CharT char_type;
868 typedef _Traits traits_type;
869 typedef basic_istream<_CharT,_Traits> istream_type;
870private:
871 istream_type* __in_stream_;
872 _Tp __value_;
873public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500874 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000875 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876 {
877 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500878 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 }
880
881 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000882 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
884 {
885 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500886 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887 return *this;
888 }
889 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
890 {istream_iterator __t(*this); ++(*this); return __t;}
891
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000892 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000894 bool
895 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
896 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000898 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000900 bool
901 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
902 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903};
904
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000905template <class _Tp, class _CharT, class _Traits, class _Distance>
906inline _LIBCPP_INLINE_VISIBILITY
907bool
908operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
909 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
910{
911 return __x.__in_stream_ == __y.__in_stream_;
912}
913
914template <class _Tp, class _CharT, class _Traits, class _Distance>
915inline _LIBCPP_INLINE_VISIBILITY
916bool
917operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
918 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
919{
920 return !(__x == __y);
921}
922
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000924class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925 : public iterator<output_iterator_tag, void, void, void, void>
926{
927public:
Louis Dionnea4d79522020-09-11 10:15:56 -0400928 typedef output_iterator_tag iterator_category;
929 typedef void value_type;
930#if _LIBCPP_STD_VER > 17
931 typedef std::ptrdiff_t difference_type;
932#else
933 typedef void difference_type;
934#endif
935 typedef void pointer;
936 typedef void reference;
937 typedef _CharT char_type;
938 typedef _Traits traits_type;
939 typedef basic_ostream<_CharT, _Traits> ostream_type;
940
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941private:
942 ostream_type* __out_stream_;
943 const char_type* __delim_;
944public:
Marshall Clow27a89512016-10-12 16:13:48 +0000945 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500946 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +0000947 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +0000948 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000949 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950 {
Howard Hinnantbf074022011-10-22 20:59:45 +0000951 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952 if (__delim_)
953 *__out_stream_ << __delim_;
954 return *this;
955 }
956
957 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
958 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
959 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
960};
961
962template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000963class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964 : public iterator<input_iterator_tag, _CharT,
965 typename _Traits::off_type, _CharT*,
966 _CharT>
967{
968public:
969 typedef _CharT char_type;
970 typedef _Traits traits_type;
971 typedef typename _Traits::int_type int_type;
972 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
973 typedef basic_istream<_CharT,_Traits> istream_type;
974private:
Howard Hinnant3e57b272012-11-16 22:17:23 +0000975 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976
977 class __proxy
978 {
979 char_type __keep_;
980 streambuf_type* __sbuf_;
981 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
982 : __keep_(__c), __sbuf_(__s) {}
983 friend class istreambuf_iterator;
984 public:
985 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
986 };
987
Howard Hinnant756c69b2010-09-22 16:48:34 +0000988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +0000989 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990 {
991 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500992 __sbuf_ = nullptr;
993 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 }
995public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500996 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000997 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +0000998 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000999 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001000 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001001 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002 : __sbuf_(__p.__sbuf_) {}
1003
Howard Hinnant28b24882011-12-01 20:21:04 +00001004 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1005 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1007 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001008 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009 return *this;
1010 }
1011 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1012 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001013 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 }
1015
1016 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001017 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001018};
1019
1020template <class _CharT, class _Traits>
1021inline _LIBCPP_INLINE_VISIBILITY
1022bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1023 const istreambuf_iterator<_CharT,_Traits>& __b)
1024 {return __a.equal(__b);}
1025
1026template <class _CharT, class _Traits>
1027inline _LIBCPP_INLINE_VISIBILITY
1028bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1029 const istreambuf_iterator<_CharT,_Traits>& __b)
1030 {return !__a.equal(__b);}
1031
1032template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001033class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034 : public iterator<output_iterator_tag, void, void, void, void>
1035{
1036public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001037 typedef output_iterator_tag iterator_category;
1038 typedef void value_type;
1039#if _LIBCPP_STD_VER > 17
1040 typedef std::ptrdiff_t difference_type;
1041#else
1042 typedef void difference_type;
1043#endif
1044 typedef void pointer;
1045 typedef void reference;
1046 typedef _CharT char_type;
1047 typedef _Traits traits_type;
1048 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1049 typedef basic_ostream<_CharT, _Traits> ostream_type;
1050
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051private:
1052 streambuf_type* __sbuf_;
1053public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001054 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001056 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 : __sbuf_(__s) {}
1058 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1059 {
1060 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001061 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062 return *this;
1063 }
1064 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1065 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1066 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001067 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001068
1069 template <class _Ch, class _Tr>
1070 friend
1071 _LIBCPP_HIDDEN
1072 ostreambuf_iterator<_Ch, _Tr>
1073 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1074 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1075 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076};
1077
1078template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001079class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080{
1081private:
1082 _Iter __i;
1083public:
1084 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 typedef typename iterator_traits<iterator_type>::value_type value_type;
1086 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001087 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001088 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1089 random_access_iterator_tag,
1090 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1091#if _LIBCPP_STD_VER > 17
1092 typedef input_iterator_tag iterator_concept;
1093#endif
1094
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001095#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001096 typedef typename iterator_traits<iterator_type>::reference __reference;
1097 typedef typename conditional<
1098 is_reference<__reference>::value,
1099 typename remove_reference<__reference>::type&&,
1100 __reference
1101 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102#else
1103 typedef typename iterator_traits<iterator_type>::reference reference;
1104#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001105
Marshall Clowb5f99122016-11-02 15:30:26 +00001106 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1107 move_iterator() : __i() {}
1108 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1109 explicit move_iterator(_Iter __x) : __i(__x) {}
1110 template <class _Up>
1111 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1112 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1113 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001114 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001115 reference operator*() const { return static_cast<reference>(*__i); }
1116 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1117 pointer operator->() const { return __i;}
1118 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1119 move_iterator& operator++() {++__i; return *this;}
1120 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1121 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1122 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1123 move_iterator& operator--() {--__i; return *this;}
1124 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1125 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1126 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1127 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1128 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1129 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1130 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1131 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1132 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1133 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1134 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1135 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136};
1137
1138template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001139inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140bool
1141operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1142{
1143 return __x.base() == __y.base();
1144}
1145
1146template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001147inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001148bool
1149operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1150{
1151 return __x.base() < __y.base();
1152}
1153
1154template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001155inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156bool
1157operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1158{
1159 return __x.base() != __y.base();
1160}
1161
1162template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001163inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164bool
1165operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1166{
1167 return __x.base() > __y.base();
1168}
1169
1170template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001171inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172bool
1173operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1174{
1175 return __x.base() >= __y.base();
1176}
1177
1178template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001179inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180bool
1181operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1182{
1183 return __x.base() <= __y.base();
1184}
1185
Marshall Clow476d3f42016-07-18 13:19:00 +00001186#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001187template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001188inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001189auto
1190operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1191-> decltype(__x.base() - __y.base())
1192{
1193 return __x.base() - __y.base();
1194}
1195#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196template <class _Iter1, class _Iter2>
1197inline _LIBCPP_INLINE_VISIBILITY
1198typename move_iterator<_Iter1>::difference_type
1199operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1200{
1201 return __x.base() - __y.base();
1202}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001203#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204
1205template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001206inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001207move_iterator<_Iter>
1208operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1209{
1210 return move_iterator<_Iter>(__x.base() + __n);
1211}
1212
1213template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001214inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001216make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001217{
1218 return move_iterator<_Iter>(__i);
1219}
1220
1221// __wrap_iter
1222
1223template <class _Iter> class __wrap_iter;
1224
1225template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001226_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001228operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001229
1230template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001231_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001233operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234
1235template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001236_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001237bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001238operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001239
1240template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001241_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001242bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001243operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244
1245template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001246_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001248operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001249
1250template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001251_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001252bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001253operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254
Marshall Clow476d3f42016-07-18 13:19:00 +00001255#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001256template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001257_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001258auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001259operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001260-> decltype(__x.base() - __y.base());
1261#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001263_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001265operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001266#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267
1268template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001269_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001271operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272
Louis Dionne65b433b2019-11-06 12:02:41 +00001273template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1274template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001275template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1276template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278template <class _Iter>
1279class __wrap_iter
1280{
1281public:
1282 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283 typedef typename iterator_traits<iterator_type>::value_type value_type;
1284 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1285 typedef typename iterator_traits<iterator_type>::pointer pointer;
1286 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001287 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1288#if _LIBCPP_STD_VER > 17
1289 typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1290 contiguous_iterator_tag, iterator_category> iterator_concept;
1291#endif
1292
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293private:
1294 iterator_type __i;
1295public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001296 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001297#if _LIBCPP_STD_VER > 11
1298 : __i{}
1299#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001300 {
Louis Dionneba400782020-10-02 15:02:52 -04001301#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001302 __get_db()->__insert_i(this);
1303#endif
1304 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001305 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1306 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001307 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001308 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001309 {
Louis Dionneba400782020-10-02 15:02:52 -04001310#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001311 __get_db()->__iterator_copy(this, &__u);
1312#endif
1313 }
Louis Dionneba400782020-10-02 15:02:52 -04001314#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001315 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001316 __wrap_iter(const __wrap_iter& __x)
1317 : __i(__x.base())
1318 {
1319 __get_db()->__iterator_copy(this, &__x);
1320 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001321 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001322 __wrap_iter& operator=(const __wrap_iter& __x)
1323 {
1324 if (this != &__x)
1325 {
1326 __get_db()->__iterator_copy(this, &__x);
1327 __i = __x.__i;
1328 }
1329 return *this;
1330 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001331 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001332 ~__wrap_iter()
1333 {
1334 __get_db()->__erase_i(this);
1335 }
1336#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001337 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001338 {
Louis Dionneba400782020-10-02 15:02:52 -04001339#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001340 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1341 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001342#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001343 return *__i;
1344 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001345 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001346 {
Louis Dionneba400782020-10-02 15:02:52 -04001347#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001348 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1349 "Attempted to dereference a non-dereferenceable iterator");
1350#endif
Marshall Clowd85a0562016-04-11 03:54:53 +00001351 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001352 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001353 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001354 {
Louis Dionneba400782020-10-02 15:02:52 -04001355#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001356 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1357 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001358#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001359 ++__i;
1360 return *this;
1361 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001362 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001363 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001364
Eric Fiselier873b8d32019-03-18 21:50:12 +00001365 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001366 {
Louis Dionneba400782020-10-02 15:02:52 -04001367#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001368 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1369 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001370#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001371 --__i;
1372 return *this;
1373 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001375 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001376 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001377 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001378 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001379 {
Louis Dionneba400782020-10-02 15:02:52 -04001380#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001381 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1382 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001383#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001384 __i += __n;
1385 return *this;
1386 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001387 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001388 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001389 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001390 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001391 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001392 {
Louis Dionneba400782020-10-02 15:02:52 -04001393#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001394 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1395 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001396#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001397 return __i[__n];
1398 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399
Eric Fiselier873b8d32019-03-18 21:50:12 +00001400 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001401
1402private:
Louis Dionneba400782020-10-02 15:02:52 -04001403#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001404 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001405 {
1406 __get_db()->__insert_ic(this, __p);
1407 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001408#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001409 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001410#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411
1412 template <class _Up> friend class __wrap_iter;
1413 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001414 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001415 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416
1417 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001418 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001420 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001421
Howard Hinnantc51e1022010-05-11 19:42:16 +00001422 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001423 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001425 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001426
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001428 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001429 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001430 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001431
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001433 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001435 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001436
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001438 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001439 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001440 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001441
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001443 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001445 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001446
Marshall Clow476d3f42016-07-18 13:19:00 +00001447#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001448 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001449 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001450 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001451 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001452 -> decltype(__x.base() - __y.base());
1453#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001455 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001457 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001458#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001459
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001461 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001463 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464};
1465
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001466#if _LIBCPP_STD_VER <= 17
1467template <class _It>
1468struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1469#endif
1470
1471template <class _Iter>
1472_LIBCPP_CONSTEXPR
1473_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1474__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1475 return _VSTD::__to_address(__w.base());
1476}
1477
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001479inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001480bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001481operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482{
1483 return __x.base() == __y.base();
1484}
1485
1486template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001487inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001489operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001490{
Louis Dionneba400782020-10-02 15:02:52 -04001491#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001492 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001493 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001494#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001495 return __x.base() < __y.base();
1496}
1497
1498template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001499inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001501operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001503 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504}
1505
1506template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001507inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001509operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001510{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001511 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512}
1513
1514template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001515inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001517operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001519 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520}
1521
1522template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001523inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001525operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001527 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528}
1529
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001530template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001531inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001532bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001533operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001534{
1535 return !(__x == __y);
1536}
1537
1538template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001539inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001540bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001541operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001542{
1543 return __y < __x;
1544}
1545
1546template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001547inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001548bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001549operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001550{
1551 return !(__x < __y);
1552}
1553
1554template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001555inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001556bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001557operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001558{
1559 return !(__y < __x);
1560}
1561
Marshall Clow476d3f42016-07-18 13:19:00 +00001562#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001563template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001564inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001565auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001566operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001567-> decltype(__x.base() - __y.base())
1568{
Louis Dionneba400782020-10-02 15:02:52 -04001569#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001570 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1571 "Attempted to subtract incompatible iterators");
1572#endif
1573 return __x.base() - __y.base();
1574}
1575#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001576template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001577inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001579operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580{
Louis Dionneba400782020-10-02 15:02:52 -04001581#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001582 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001583 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001584#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001585 return __x.base() - __y.base();
1586}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001587#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588
1589template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001590inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001591__wrap_iter<_Iter>
1592operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001593 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001594{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001595 __x += __n;
1596 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597}
1598
Marshall Clow8411ebf2013-12-02 03:24:33 +00001599template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001600_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001601_Tp*
1602begin(_Tp (&__array)[_Np])
1603{
1604 return __array;
1605}
1606
1607template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001608_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001609_Tp*
1610end(_Tp (&__array)[_Np])
1611{
1612 return __array + _Np;
1613}
1614
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001615#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001616
Howard Hinnantc834c512011-11-29 18:15:50 +00001617template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001618_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001620begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001621{
1622 return __c.begin();
1623}
1624
Howard Hinnantc834c512011-11-29 18:15:50 +00001625template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001626_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001627auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001628begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629{
1630 return __c.begin();
1631}
1632
Howard Hinnantc834c512011-11-29 18:15:50 +00001633template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001634_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001636end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637{
1638 return __c.end();
1639}
1640
Howard Hinnantc834c512011-11-29 18:15:50 +00001641template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001642_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001643auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001644end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001645{
1646 return __c.end();
1647}
1648
Marshall Clowb278e9c2013-08-30 01:17:07 +00001649#if _LIBCPP_STD_VER > 11
1650
Marshall Clow8411ebf2013-12-02 03:24:33 +00001651template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001652_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001653reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1654{
1655 return reverse_iterator<_Tp*>(__array + _Np);
1656}
1657
1658template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001659_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001660reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1661{
1662 return reverse_iterator<_Tp*>(__array);
1663}
1664
1665template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001666_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001667reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1668{
1669 return reverse_iterator<const _Ep*>(__il.end());
1670}
1671
1672template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001673_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001674reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1675{
1676 return reverse_iterator<const _Ep*>(__il.begin());
1677}
1678
Marshall Clowb278e9c2013-08-30 01:17:07 +00001679template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001680_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001681auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001682{
Marshall Clow3862f532016-08-10 20:04:46 +00001683 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001684}
1685
1686template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001687_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001688auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001689{
Marshall Clow3862f532016-08-10 20:04:46 +00001690 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001691}
1692
1693template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001694_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001695auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1696{
1697 return __c.rbegin();
1698}
1699
1700template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001701_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001702auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1703{
1704 return __c.rbegin();
1705}
1706
1707template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001708_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001709auto rend(_Cp& __c) -> decltype(__c.rend())
1710{
1711 return __c.rend();
1712}
1713
1714template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001715_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001716auto rend(const _Cp& __c) -> decltype(__c.rend())
1717{
1718 return __c.rend();
1719}
1720
1721template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001722_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001723auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001724{
Marshall Clow3862f532016-08-10 20:04:46 +00001725 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001726}
1727
1728template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001729_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001730auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001731{
Marshall Clow3862f532016-08-10 20:04:46 +00001732 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001733}
1734
1735#endif
1736
1737
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001738#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001739
Howard Hinnantc834c512011-11-29 18:15:50 +00001740template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001741_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001742typename _Cp::iterator
1743begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001744{
1745 return __c.begin();
1746}
1747
Howard Hinnantc834c512011-11-29 18:15:50 +00001748template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001749_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001750typename _Cp::const_iterator
1751begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752{
1753 return __c.begin();
1754}
1755
Howard Hinnantc834c512011-11-29 18:15:50 +00001756template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001757_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001758typename _Cp::iterator
1759end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001760{
1761 return __c.end();
1762}
1763
Howard Hinnantc834c512011-11-29 18:15:50 +00001764template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001765_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001766typename _Cp::const_iterator
1767end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768{
1769 return __c.end();
1770}
1771
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001772#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001773
Marshall Clowef357272014-11-19 19:43:23 +00001774#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001775
1776// #if _LIBCPP_STD_VER > 11
1777// template <>
1778// struct _LIBCPP_TEMPLATE_VIS plus<void>
1779// {
1780// template <class _T1, class _T2>
1781// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1782// auto operator()(_T1&& __t, _T2&& __u) const
1783// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1784// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1785// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1786// typedef void is_transparent;
1787// };
1788// #endif
1789
Marshall Clowc4b4a342015-02-11 16:14:01 +00001790template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001791_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001792constexpr auto size(const _Cont& __c)
1793_NOEXCEPT_(noexcept(__c.size()))
1794-> decltype (__c.size())
1795{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001796
Marshall Clowc4b4a342015-02-11 16:14:01 +00001797template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001798_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001799constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001800
Marshall Clow3c5363e2019-02-27 02:58:56 +00001801#if _LIBCPP_STD_VER > 17
1802template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001803_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001804constexpr auto ssize(const _Cont& __c)
1805_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1806-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1807{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1808
1809template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001810_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001811constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1812#endif
1813
Marshall Clowc4b4a342015-02-11 16:14:01 +00001814template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001815_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001816constexpr auto empty(const _Cont& __c)
1817_NOEXCEPT_(noexcept(__c.empty()))
1818-> decltype (__c.empty())
1819{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001820
Marshall Clowc4b4a342015-02-11 16:14:01 +00001821template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001822_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001823constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001824
1825template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001826_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001827constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1828
Marshall Clowc4b4a342015-02-11 16:14:01 +00001829template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001830_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001831auto data(_Cont& __c)
1832_NOEXCEPT_(noexcept(__c.data()))
1833-> decltype (__c.data())
1834{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001835
Marshall Clowc4b4a342015-02-11 16:14:01 +00001836template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001837_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001838auto data(const _Cont& __c)
1839_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001840-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001841{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001842
Marshall Clowc4b4a342015-02-11 16:14:01 +00001843template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001844_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001845constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001846
1847template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001848_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001849constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1850#endif
1851
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001852template <class _Container, class _Predicate>
1853typename _Container::size_type
1854__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
1855 typename _Container::size_type __old_size = __c.size();
1856
1857 const typename _Container::iterator __last = __c.end();
1858 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
1859 if (__pred(*__iter))
1860 __iter = __c.erase(__iter);
1861 else
1862 ++__iter;
1863 }
1864
1865 return __old_size - __c.size();
1866}
Marshall Clowef357272014-11-19 19:43:23 +00001867
Howard Hinnantc51e1022010-05-11 19:42:16 +00001868_LIBCPP_END_NAMESPACE_STD
1869
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001870#endif // _LIBCPP_ITERATOR