blob: d759eae914acb3f3706e40f770c5a0fc5cfb8f65 [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
Howard Hinnantc51e1022010-05-11 19:42:16 +000082template<class Category, class T, class Distance = ptrdiff_t,
83 class Pointer = T*, class Reference = T&>
84struct iterator
85{
86 typedef T value_type;
87 typedef Distance difference_type;
88 typedef Pointer pointer;
89 typedef Reference reference;
90 typedef Category iterator_category;
91};
92
93struct input_iterator_tag {};
94struct output_iterator_tag {};
95struct forward_iterator_tag : public input_iterator_tag {};
96struct bidirectional_iterator_tag : public forward_iterator_tag {};
97struct random_access_iterator_tag : public bidirectional_iterator_tag {};
98
Marshall Clow75468e72017-05-17 18:51:36 +000099// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -0400100template <class InputIterator, class Distance> // constexpr in C++17
101 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102
Marshall Clow75468e72017-05-17 18:51:36 +0000103template <class InputIterator> // constexpr in C++17
104 constexpr typename iterator_traits<InputIterator>::difference_type
105 distance(InputIterator first, InputIterator last);
106
107template <class InputIterator> // constexpr in C++17
108 constexpr InputIterator next(InputIterator x,
109typename iterator_traits<InputIterator>::difference_type n = 1);
110
111template <class BidirectionalIterator> // constexpr in C++17
112 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +0000113 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114
115template <class Iterator>
116class reverse_iterator
117 : public iterator<typename iterator_traits<Iterator>::iterator_category,
118 typename iterator_traits<Iterator>::value_type,
119 typename iterator_traits<Iterator>::difference_type,
120 typename iterator_traits<Iterator>::pointer,
121 typename iterator_traits<Iterator>::reference>
122{
123protected:
124 Iterator current;
125public:
126 typedef Iterator iterator_type;
127 typedef typename iterator_traits<Iterator>::difference_type difference_type;
128 typedef typename iterator_traits<Iterator>::reference reference;
129 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000130
Marshall Clow5ace5542016-10-19 15:12:50 +0000131 constexpr reverse_iterator();
132 constexpr explicit reverse_iterator(Iterator x);
133 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
134 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
135 constexpr Iterator base() const;
136 constexpr reference operator*() const;
137 constexpr pointer operator->() const;
138 constexpr reverse_iterator& operator++();
139 constexpr reverse_iterator operator++(int);
140 constexpr reverse_iterator& operator--();
141 constexpr reverse_iterator operator--(int);
142 constexpr reverse_iterator operator+ (difference_type n) const;
143 constexpr reverse_iterator& operator+=(difference_type n);
144 constexpr reverse_iterator operator- (difference_type n) const;
145 constexpr reverse_iterator& operator-=(difference_type n);
146 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147};
148
149template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000150constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
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 auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000175operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000176-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177
178template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000179constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000180operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000181 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182
Marshall Clow5ace5542016-10-19 15:12:50 +0000183template <class Iterator>
184constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000185
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186template <class Container>
187class back_insert_iterator
188{
189protected:
190 Container* container;
191public:
192 typedef Container container_type;
193 typedef void value_type;
194 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000195 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196 typedef void pointer;
197
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500198 explicit back_insert_iterator(Container& x); // constexpr in C++20
199 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
200 back_insert_iterator& operator*(); // constexpr in C++20
201 back_insert_iterator& operator++(); // constexpr in C++20
202 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203};
204
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500205template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206
207template <class Container>
208class front_insert_iterator
209{
210protected:
211 Container* container;
212public:
213 typedef Container container_type;
214 typedef void value_type;
215 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000216 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217 typedef void pointer;
218
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500219 explicit front_insert_iterator(Container& x); // constexpr in C++20
220 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
221 front_insert_iterator& operator*(); // constexpr in C++20
222 front_insert_iterator& operator++(); // constexpr in C++20
223 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224};
225
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500226template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000227
228template <class Container>
229class insert_iterator
230{
231protected:
232 Container* container;
233 typename Container::iterator iter;
234public:
235 typedef Container container_type;
236 typedef void value_type;
237 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000238 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239 typedef void pointer;
240
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500241 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
242 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
243 insert_iterator& operator*(); // constexpr in C++20
244 insert_iterator& operator++(); // constexpr in C++20
245 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246};
247
248template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500249insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000251template <class Iterator>
252class move_iterator {
253public:
254 typedef Iterator iterator_type;
255 typedef typename iterator_traits<Iterator>::difference_type difference_type;
256 typedef Iterator pointer;
257 typedef typename iterator_traits<Iterator>::value_type value_type;
258 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
259 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000260
Marshall Clowb5f99122016-11-02 15:30:26 +0000261 constexpr move_iterator(); // all the constexprs are in C++17
262 constexpr explicit move_iterator(Iterator i);
263 template <class U>
264 constexpr move_iterator(const move_iterator<U>& u);
265 template <class U>
266 constexpr move_iterator& operator=(const move_iterator<U>& u);
267 constexpr iterator_type base() const;
268 constexpr reference operator*() const;
269 constexpr pointer operator->() const;
270 constexpr move_iterator& operator++();
271 constexpr move_iterator operator++(int);
272 constexpr move_iterator& operator--();
273 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000274 constexpr move_iterator operator+(difference_type n) const;
275 constexpr move_iterator& operator+=(difference_type n);
276 constexpr move_iterator operator-(difference_type n) const;
277 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000278 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000279private:
280 Iterator current; // exposition only
281};
282
283template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000284constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000285operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
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 auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000309operator-(const move_iterator<Iterator1>& x,
310 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
311
312template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000313constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000314 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000315 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000316
Marshall Clowb5f99122016-11-02 15:30:26 +0000317template <class Iterator> // constexpr in C++17
318constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000319
320
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
322class istream_iterator
323 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
324{
325public:
326 typedef charT char_type;
327 typedef traits traits_type;
328 typedef basic_istream<charT,traits> istream_type;
329
Marshall Clow0735e4e2015-04-16 21:36:54 +0000330 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000331 istream_iterator(istream_type& s);
332 istream_iterator(const istream_iterator& x);
333 ~istream_iterator();
334
335 const T& operator*() const;
336 const T* operator->() const;
337 istream_iterator& operator++();
338 istream_iterator operator++(int);
339};
340
341template <class T, class charT, class traits, class Distance>
342bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
343 const istream_iterator<T,charT,traits,Distance>& y);
344template <class T, class charT, class traits, class Distance>
345bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
346 const istream_iterator<T,charT,traits,Distance>& y);
347
348template <class T, class charT = char, class traits = char_traits<charT> >
349class ostream_iterator
350 : public iterator<output_iterator_tag, void, void, void ,void>
351{
352public:
353 typedef charT char_type;
354 typedef traits traits_type;
355 typedef basic_ostream<charT,traits> ostream_type;
356
357 ostream_iterator(ostream_type& s);
358 ostream_iterator(ostream_type& s, const charT* delimiter);
359 ostream_iterator(const ostream_iterator& x);
360 ~ostream_iterator();
361 ostream_iterator& operator=(const T& value);
362
363 ostream_iterator& operator*();
364 ostream_iterator& operator++();
365 ostream_iterator& operator++(int);
366};
367
368template<class charT, class traits = char_traits<charT> >
369class istreambuf_iterator
370 : public iterator<input_iterator_tag, charT,
371 typename traits::off_type, unspecified,
372 charT>
373{
374public:
375 typedef charT char_type;
376 typedef traits traits_type;
377 typedef typename traits::int_type int_type;
378 typedef basic_streambuf<charT,traits> streambuf_type;
379 typedef basic_istream<charT,traits> istream_type;
380
Howard Hinnant011138d2012-07-20 19:36:34 +0000381 istreambuf_iterator() noexcept;
382 istreambuf_iterator(istream_type& s) noexcept;
383 istreambuf_iterator(streambuf_type* s) noexcept;
384 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385
386 charT operator*() const;
387 pointer operator->() const;
388 istreambuf_iterator& operator++();
389 a-private-type operator++(int);
390
391 bool equal(const istreambuf_iterator& b) const;
392};
393
394template <class charT, class traits>
395bool operator==(const istreambuf_iterator<charT,traits>& a,
396 const istreambuf_iterator<charT,traits>& b);
397template <class charT, class traits>
398bool operator!=(const istreambuf_iterator<charT,traits>& a,
399 const istreambuf_iterator<charT,traits>& b);
400
401template <class charT, class traits = char_traits<charT> >
402class ostreambuf_iterator
403 : public iterator<output_iterator_tag, void, void, void, void>
404{
405public:
406 typedef charT char_type;
407 typedef traits traits_type;
408 typedef basic_streambuf<charT,traits> streambuf_type;
409 typedef basic_ostream<charT,traits> ostream_type;
410
Howard Hinnant011138d2012-07-20 19:36:34 +0000411 ostreambuf_iterator(ostream_type& s) noexcept;
412 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413 ostreambuf_iterator& operator=(charT c);
414 ostreambuf_iterator& operator*();
415 ostreambuf_iterator& operator++();
416 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000417 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000418};
419
Marshall Clow99ba0022017-01-04 17:58:17 +0000420template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
421template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
422template <class C> constexpr auto end(C& c) -> decltype(c.end());
423template <class C> constexpr auto end(const C& c) -> decltype(c.end());
424template <class T, size_t N> constexpr T* begin(T (&array)[N]);
425template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426
Marshall Clow99ba0022017-01-04 17:58:17 +0000427template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
428template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
429template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
430template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
431template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
432template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
433template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
434template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
435template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
436template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
437template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
438template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000439
Marshall Clowef357272014-11-19 19:43:23 +0000440// 24.8, container access:
441template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
442template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000443
444template <class C> constexpr auto ssize(const C& c)
Arthur O'Dwyer2fc9b5d2021-04-17 17:03:20 -0400445 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
Marshall Clow3c5363e2019-02-27 02:58:56 +0000446template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
447
Marshall Clowef357272014-11-19 19:43:23 +0000448template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
449template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
450template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
451template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
452template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
453template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
454template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
455
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456} // std
457
458*/
459
460#include <__config>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400461#include <__debug>
Marshall Clow3dc05502014-02-27 02:11:50 +0000462#include <__functional_base>
Louis Dionne463afb82021-04-22 11:05:30 -0400463#include <__iterator/concepts.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400464#include <__iterator/incrementable_traits.h>
Louis Dionneca989a52021-04-20 14:40:43 -0400465#include <__iterator/iter_move.h>
zoecarver5d41ff52021-04-19 14:44:42 -0700466#include <__iterator/iterator_traits.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400467#include <__iterator/readable_traits.h>
Louis Dionne735bc462021-04-14 13:59:03 -0400468#include <__memory/addressof.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500469#include <__memory/pointer_traits.h>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400470#include <compare>
471#include <concepts> // Mandated by the Standard.
472#include <cstddef>
473#include <initializer_list>
474#include <iosfwd> // for forward declarations of vector and string
475#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000476#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000477
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000478#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000480#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481
482_LIBCPP_BEGIN_NAMESPACE_STD
Christopher Di Bella490fe402021-03-23 03:55:52 +0000483
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484template<class _Category, class _Tp, class _Distance = ptrdiff_t,
485 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000486struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487{
488 typedef _Tp value_type;
489 typedef _Distance difference_type;
490 typedef _Pointer pointer;
491 typedef _Reference reference;
492 typedef _Category iterator_category;
493};
494
495template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000496inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497void __advance(_InputIter& __i,
498 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
499{
500 for (; __n > 0; --__n)
501 ++__i;
502}
503
504template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000505inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506void __advance(_BiDirIter& __i,
507 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
508{
509 if (__n >= 0)
510 for (; __n > 0; --__n)
511 ++__i;
512 else
513 for (; __n < 0; ++__n)
514 --__i;
515}
516
517template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000518inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519void __advance(_RandIter& __i,
520 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
521{
522 __i += __n;
523}
524
Louis Dionne45768662020-06-08 16:16:01 -0400525template <class _InputIter, class _Distance>
Marshall Clow75468e72017-05-17 18:51:36 +0000526inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Louis Dionne45768662020-06-08 16:16:01 -0400527void advance(_InputIter& __i, _Distance __orig_n)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528{
Louis Dionne45768662020-06-08 16:16:01 -0400529 _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
530 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500531 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
Louis Dionne45768662020-06-08 16:16:01 -0400532 _IntegralSize __n = __orig_n;
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500533 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534}
535
536template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000537inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538typename iterator_traits<_InputIter>::difference_type
539__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
540{
541 typename iterator_traits<_InputIter>::difference_type __r(0);
542 for (; __first != __last; ++__first)
543 ++__r;
544 return __r;
545}
546
547template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000548inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549typename iterator_traits<_RandIter>::difference_type
550__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
551{
552 return __last - __first;
553}
554
555template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000556inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557typename iterator_traits<_InputIter>::difference_type
558distance(_InputIter __first, _InputIter __last)
559{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500560 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561}
562
Marshall Clow990c70d2015-11-07 17:48:49 +0000563template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000564inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000565typename enable_if
566<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500567 __is_cpp17_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000568 _InputIter
569>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000570next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000571 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500573 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400574 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
Marshall Clow3d435212019-03-22 22:32:20 +0000575
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000576 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577 return __x;
578}
579
Marshall Clow3d435212019-03-22 22:32:20 +0000580template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000581inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000582typename enable_if
583<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500584 __is_cpp17_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000585 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000586>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000587prev(_InputIter __x,
588 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500590 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400591 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000592 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 return __x;
594}
595
Eric Fiselier883af112017-04-13 02:54:13 +0000596
597template <class _Tp, class = void>
598struct __is_stashing_iterator : false_type {};
599
600template <class _Tp>
601struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
602 : true_type {};
603
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000605class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606 : public iterator<typename iterator_traits<_Iter>::iterator_category,
607 typename iterator_traits<_Iter>::value_type,
608 typename iterator_traits<_Iter>::difference_type,
609 typename iterator_traits<_Iter>::pointer,
610 typename iterator_traits<_Iter>::reference>
611{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000612private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000613 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000614
615 static_assert(!__is_stashing_iterator<_Iter>::value,
616 "The specified iterator type cannot be used with reverse_iterator; "
617 "Using stashing iterators with reverse_iterator causes undefined behavior");
618
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000619protected:
620 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621public:
622 typedef _Iter iterator_type;
623 typedef typename iterator_traits<_Iter>::difference_type difference_type;
624 typedef typename iterator_traits<_Iter>::reference reference;
625 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500626 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
627 random_access_iterator_tag,
628 typename iterator_traits<_Iter>::iterator_category> iterator_category;
629#if _LIBCPP_STD_VER > 17
630 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
631 random_access_iterator_tag,
632 bidirectional_iterator_tag> iterator_concept;
633#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000634
Marshall Clow5ace5542016-10-19 15:12:50 +0000635 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
636 reverse_iterator() : __t(), current() {}
637 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
638 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
639 template <class _Up>
640 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
641 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
642 template <class _Up>
643 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
644 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
645 { __t = current = __u.base(); return *this; }
646 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
647 _Iter base() const {return current;}
648 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
649 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
650 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
651 pointer operator->() const {return _VSTD::addressof(operator*());}
652 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
653 reverse_iterator& operator++() {--current; return *this;}
654 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
655 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
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+ (difference_type __n) const {return reverse_iterator(current - __n);}
662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
663 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
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 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670};
671
672template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000673inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674bool
675operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
676{
677 return __x.base() == __y.base();
678}
679
680template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000681inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682bool
683operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
684{
685 return __x.base() > __y.base();
686}
687
688template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000689inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000690bool
691operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
692{
693 return __x.base() != __y.base();
694}
695
696template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000697inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698bool
699operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
700{
701 return __x.base() < __y.base();
702}
703
704template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000705inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706bool
707operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
708{
709 return __x.base() <= __y.base();
710}
711
712template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000713inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714bool
715operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
716{
717 return __x.base() >= __y.base();
718}
719
Marshall Clow476d3f42016-07-18 13:19:00 +0000720#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000721template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000722inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000723auto
724operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
725-> decltype(__y.base() - __x.base())
726{
727 return __y.base() - __x.base();
728}
729#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000730template <class _Iter1, class _Iter2>
731inline _LIBCPP_INLINE_VISIBILITY
732typename reverse_iterator<_Iter1>::difference_type
733operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
734{
735 return __y.base() - __x.base();
736}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000737#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000738
739template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000740inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741reverse_iterator<_Iter>
742operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
743{
744 return reverse_iterator<_Iter>(__x.base() - __n);
745}
746
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000747#if _LIBCPP_STD_VER > 11
748template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000749inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000750reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
751{
752 return reverse_iterator<_Iter>(__i);
753}
754#endif
755
Howard Hinnantc51e1022010-05-11 19:42:16 +0000756template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000757class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758 : public iterator<output_iterator_tag,
759 void,
760 void,
761 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000762 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763{
764protected:
765 _Container* container;
766public:
767 typedef _Container container_type;
768
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500769 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
770 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000771 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000772#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500773 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000774 {container->push_back(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400775#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500776 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
777 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
778 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779};
780
781template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500782inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783back_insert_iterator<_Container>
784back_inserter(_Container& __x)
785{
786 return back_insert_iterator<_Container>(__x);
787}
788
789template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000790class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791 : public iterator<output_iterator_tag,
792 void,
793 void,
794 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000795 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796{
797protected:
798 _Container* container;
799public:
800 typedef _Container container_type;
801
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500802 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
803 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000804 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000805#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500806 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000807 {container->push_front(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400808#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500809 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
810 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
811 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812};
813
814template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500815inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816front_insert_iterator<_Container>
817front_inserter(_Container& __x)
818{
819 return front_insert_iterator<_Container>(__x);
820}
821
822template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000823class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824 : public iterator<output_iterator_tag,
825 void,
826 void,
827 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000828 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829{
830protected:
831 _Container* container;
832 typename _Container::iterator iter;
833public:
834 typedef _Container container_type;
835
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500836 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000837 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500838 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000839 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000840#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500841 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000842 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400843#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500844 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
845 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
846 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847};
848
849template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500850inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851insert_iterator<_Container>
852inserter(_Container& __x, typename _Container::iterator __i)
853{
854 return insert_iterator<_Container>(__x, __i);
855}
856
857template <class _Tp, class _CharT = char,
858 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000859class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
861{
862public:
863 typedef _CharT char_type;
864 typedef _Traits traits_type;
865 typedef basic_istream<_CharT,_Traits> istream_type;
866private:
867 istream_type* __in_stream_;
868 _Tp __value_;
869public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500870 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000871 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872 {
873 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500874 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875 }
876
877 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000878 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
880 {
881 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500882 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883 return *this;
884 }
885 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
886 {istream_iterator __t(*this); ++(*this); return __t;}
887
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000888 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000890 bool
891 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
892 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000894 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000896 bool
897 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
898 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899};
900
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000901template <class _Tp, class _CharT, class _Traits, class _Distance>
902inline _LIBCPP_INLINE_VISIBILITY
903bool
904operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
905 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
906{
907 return __x.__in_stream_ == __y.__in_stream_;
908}
909
910template <class _Tp, class _CharT, class _Traits, class _Distance>
911inline _LIBCPP_INLINE_VISIBILITY
912bool
913operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
914 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
915{
916 return !(__x == __y);
917}
918
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000920class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000921 : public iterator<output_iterator_tag, void, void, void, void>
922{
923public:
Louis Dionnea4d79522020-09-11 10:15:56 -0400924 typedef output_iterator_tag iterator_category;
925 typedef void value_type;
926#if _LIBCPP_STD_VER > 17
927 typedef std::ptrdiff_t difference_type;
928#else
929 typedef void difference_type;
930#endif
931 typedef void pointer;
932 typedef void reference;
933 typedef _CharT char_type;
934 typedef _Traits traits_type;
935 typedef basic_ostream<_CharT, _Traits> ostream_type;
936
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937private:
938 ostream_type* __out_stream_;
939 const char_type* __delim_;
940public:
Marshall Clow27a89512016-10-12 16:13:48 +0000941 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500942 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +0000943 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +0000944 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000945 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946 {
Howard Hinnantbf074022011-10-22 20:59:45 +0000947 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948 if (__delim_)
949 *__out_stream_ << __delim_;
950 return *this;
951 }
952
953 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
954 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
955 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
956};
957
958template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000959class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960 : public iterator<input_iterator_tag, _CharT,
961 typename _Traits::off_type, _CharT*,
962 _CharT>
963{
964public:
965 typedef _CharT char_type;
966 typedef _Traits traits_type;
967 typedef typename _Traits::int_type int_type;
968 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
969 typedef basic_istream<_CharT,_Traits> istream_type;
970private:
Howard Hinnant3e57b272012-11-16 22:17:23 +0000971 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972
973 class __proxy
974 {
975 char_type __keep_;
976 streambuf_type* __sbuf_;
977 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
978 : __keep_(__c), __sbuf_(__s) {}
979 friend class istreambuf_iterator;
980 public:
981 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
982 };
983
Howard Hinnant756c69b2010-09-22 16:48:34 +0000984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +0000985 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986 {
987 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500988 __sbuf_ = nullptr;
989 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990 }
991public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500992 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000993 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +0000994 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000995 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +0000996 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000997 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998 : __sbuf_(__p.__sbuf_) {}
999
Howard Hinnant28b24882011-12-01 20:21:04 +00001000 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1001 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1003 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001004 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005 return *this;
1006 }
1007 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1008 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001009 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010 }
1011
1012 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001013 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014};
1015
1016template <class _CharT, class _Traits>
1017inline _LIBCPP_INLINE_VISIBILITY
1018bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1019 const istreambuf_iterator<_CharT,_Traits>& __b)
1020 {return __a.equal(__b);}
1021
1022template <class _CharT, class _Traits>
1023inline _LIBCPP_INLINE_VISIBILITY
1024bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1025 const istreambuf_iterator<_CharT,_Traits>& __b)
1026 {return !__a.equal(__b);}
1027
1028template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001029class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030 : public iterator<output_iterator_tag, void, void, void, void>
1031{
1032public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001033 typedef output_iterator_tag iterator_category;
1034 typedef void value_type;
1035#if _LIBCPP_STD_VER > 17
1036 typedef std::ptrdiff_t difference_type;
1037#else
1038 typedef void difference_type;
1039#endif
1040 typedef void pointer;
1041 typedef void reference;
1042 typedef _CharT char_type;
1043 typedef _Traits traits_type;
1044 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1045 typedef basic_ostream<_CharT, _Traits> ostream_type;
1046
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047private:
1048 streambuf_type* __sbuf_;
1049public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001050 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001052 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053 : __sbuf_(__s) {}
1054 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1055 {
1056 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001057 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058 return *this;
1059 }
1060 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1061 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1062 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001063 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001064
1065 template <class _Ch, class _Tr>
1066 friend
1067 _LIBCPP_HIDDEN
1068 ostreambuf_iterator<_Ch, _Tr>
1069 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1070 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1071 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001072};
1073
1074template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001075class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076{
1077private:
1078 _Iter __i;
1079public:
1080 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 typedef typename iterator_traits<iterator_type>::value_type value_type;
1082 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001083 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001084 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1085 random_access_iterator_tag,
1086 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1087#if _LIBCPP_STD_VER > 17
1088 typedef input_iterator_tag iterator_concept;
1089#endif
1090
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001091#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001092 typedef typename iterator_traits<iterator_type>::reference __reference;
1093 typedef typename conditional<
1094 is_reference<__reference>::value,
1095 typename remove_reference<__reference>::type&&,
1096 __reference
1097 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098#else
1099 typedef typename iterator_traits<iterator_type>::reference reference;
1100#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001101
Marshall Clowb5f99122016-11-02 15:30:26 +00001102 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1103 move_iterator() : __i() {}
1104 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1105 explicit move_iterator(_Iter __x) : __i(__x) {}
1106 template <class _Up>
1107 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1108 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1109 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001110 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001111 reference operator*() const { return static_cast<reference>(*__i); }
1112 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1113 pointer operator->() const { return __i;}
1114 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1115 move_iterator& operator++() {++__i; return *this;}
1116 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1117 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
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+ (difference_type __n) const {return move_iterator(__i + __n);}
1124 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1125 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
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 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132};
1133
1134template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001135inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136bool
1137operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1138{
1139 return __x.base() == __y.base();
1140}
1141
1142template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001143inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144bool
1145operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1146{
1147 return __x.base() < __y.base();
1148}
1149
1150template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001151inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001152bool
1153operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1154{
1155 return __x.base() != __y.base();
1156}
1157
1158template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001159inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160bool
1161operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1162{
1163 return __x.base() > __y.base();
1164}
1165
1166template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001167inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168bool
1169operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1170{
1171 return __x.base() >= __y.base();
1172}
1173
1174template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001175inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176bool
1177operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1178{
1179 return __x.base() <= __y.base();
1180}
1181
Marshall Clow476d3f42016-07-18 13:19:00 +00001182#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001183template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001184inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001185auto
1186operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1187-> decltype(__x.base() - __y.base())
1188{
1189 return __x.base() - __y.base();
1190}
1191#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192template <class _Iter1, class _Iter2>
1193inline _LIBCPP_INLINE_VISIBILITY
1194typename move_iterator<_Iter1>::difference_type
1195operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1196{
1197 return __x.base() - __y.base();
1198}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001199#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200
1201template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001202inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203move_iterator<_Iter>
1204operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1205{
1206 return move_iterator<_Iter>(__x.base() + __n);
1207}
1208
1209template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001210inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001211move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001212make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213{
1214 return move_iterator<_Iter>(__i);
1215}
1216
1217// __wrap_iter
1218
1219template <class _Iter> class __wrap_iter;
1220
1221template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001222_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001224operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001225
1226template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001227_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001229operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230
1231template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001232_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001234operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001235
1236template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001237_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001239operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240
1241template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001242_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001243bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001244operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001245
1246template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001247_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001249operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250
Marshall Clow476d3f42016-07-18 13:19:00 +00001251#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001252template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001253_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001254auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001255operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001256-> decltype(__x.base() - __y.base());
1257#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001259_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001261operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001262#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263
1264template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001265_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001267operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001268
Louis Dionne65b433b2019-11-06 12:02:41 +00001269template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1270template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001271template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1272template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273
Howard Hinnantc51e1022010-05-11 19:42:16 +00001274template <class _Iter>
1275class __wrap_iter
1276{
1277public:
1278 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001279 typedef typename iterator_traits<iterator_type>::value_type value_type;
1280 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1281 typedef typename iterator_traits<iterator_type>::pointer pointer;
1282 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001283 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1284#if _LIBCPP_STD_VER > 17
1285 typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1286 contiguous_iterator_tag, iterator_category> iterator_concept;
1287#endif
1288
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289private:
1290 iterator_type __i;
1291public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001292 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001293#if _LIBCPP_STD_VER > 11
1294 : __i{}
1295#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001296 {
Louis Dionneba400782020-10-02 15:02:52 -04001297#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001298 __get_db()->__insert_i(this);
1299#endif
1300 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001301 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1302 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001303 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001304 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001305 {
Louis Dionneba400782020-10-02 15:02:52 -04001306#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001307 __get_db()->__iterator_copy(this, &__u);
1308#endif
1309 }
Louis Dionneba400782020-10-02 15:02:52 -04001310#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001311 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001312 __wrap_iter(const __wrap_iter& __x)
1313 : __i(__x.base())
1314 {
1315 __get_db()->__iterator_copy(this, &__x);
1316 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001317 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001318 __wrap_iter& operator=(const __wrap_iter& __x)
1319 {
1320 if (this != &__x)
1321 {
1322 __get_db()->__iterator_copy(this, &__x);
1323 __i = __x.__i;
1324 }
1325 return *this;
1326 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001327 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001328 ~__wrap_iter()
1329 {
1330 __get_db()->__erase_i(this);
1331 }
1332#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001333 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001334 {
Louis Dionneba400782020-10-02 15:02:52 -04001335#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001336 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1337 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001338#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001339 return *__i;
1340 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001341 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001342 {
Louis Dionneba400782020-10-02 15:02:52 -04001343#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001344 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1345 "Attempted to dereference a non-dereferenceable iterator");
1346#endif
Marshall Clowd85a0562016-04-11 03:54:53 +00001347 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001348 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001349 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001350 {
Louis Dionneba400782020-10-02 15:02:52 -04001351#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001352 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1353 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001354#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001355 ++__i;
1356 return *this;
1357 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001358 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001359 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001360
Eric Fiselier873b8d32019-03-18 21:50:12 +00001361 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001362 {
Louis Dionneba400782020-10-02 15:02:52 -04001363#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001364 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1365 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001366#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001367 --__i;
1368 return *this;
1369 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001371 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001372 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001373 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001375 {
Louis Dionneba400782020-10-02 15:02:52 -04001376#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001377 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1378 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001379#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001380 __i += __n;
1381 return *this;
1382 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001383 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001384 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001385 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001386 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001387 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001388 {
Louis Dionneba400782020-10-02 15:02:52 -04001389#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001390 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1391 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001392#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001393 return __i[__n];
1394 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395
Eric Fiselier873b8d32019-03-18 21:50:12 +00001396 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397
1398private:
Louis Dionneba400782020-10-02 15:02:52 -04001399#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001400 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001401 {
1402 __get_db()->__insert_ic(this, __p);
1403 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001404#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001405 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001406#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001407
1408 template <class _Up> friend class __wrap_iter;
1409 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001410 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001411 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412
1413 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001414 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001416 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001417
Howard Hinnantc51e1022010-05-11 19:42:16 +00001418 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001419 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001421 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001422
Howard Hinnantc51e1022010-05-11 19:42:16 +00001423 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001424 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001425 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001426 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001427
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001429 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001431 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001432
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001434 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001435 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001436 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001437
Howard Hinnantc51e1022010-05-11 19:42:16 +00001438 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001439 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001441 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001442
Marshall Clow476d3f42016-07-18 13:19:00 +00001443#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001444 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001445 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001446 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001447 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001448 -> decltype(__x.base() - __y.base());
1449#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001451 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001452 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001453 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001454#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001455
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001457 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001459 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460};
1461
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001462#if _LIBCPP_STD_VER <= 17
1463template <class _It>
1464struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1465#endif
1466
1467template <class _Iter>
1468_LIBCPP_CONSTEXPR
1469_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1470__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1471 return _VSTD::__to_address(__w.base());
1472}
1473
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001475inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001476bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001477operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478{
1479 return __x.base() == __y.base();
1480}
1481
1482template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001483inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001485operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486{
Louis Dionneba400782020-10-02 15:02:52 -04001487#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001488 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001489 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001490#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491 return __x.base() < __y.base();
1492}
1493
1494template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001495inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001496bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001497operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001499 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500}
1501
1502template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001503inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001505operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001507 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508}
1509
1510template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001511inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001513operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001515 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516}
1517
1518template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001519inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001521operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001523 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524}
1525
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001526template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001527inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001528bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001529operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001530{
1531 return !(__x == __y);
1532}
1533
1534template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001535inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001536bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001537operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001538{
1539 return __y < __x;
1540}
1541
1542template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001543inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001544bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001545operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001546{
1547 return !(__x < __y);
1548}
1549
1550template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001551inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001552bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001553operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001554{
1555 return !(__y < __x);
1556}
1557
Marshall Clow476d3f42016-07-18 13:19:00 +00001558#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001559template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001560inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001561auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001562operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001563-> decltype(__x.base() - __y.base())
1564{
Louis Dionneba400782020-10-02 15:02:52 -04001565#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001566 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1567 "Attempted to subtract incompatible iterators");
1568#endif
1569 return __x.base() - __y.base();
1570}
1571#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001572template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001573inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001575operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001576{
Louis Dionneba400782020-10-02 15:02:52 -04001577#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001578 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001579 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001580#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581 return __x.base() - __y.base();
1582}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001583#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584
1585template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001586inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587__wrap_iter<_Iter>
1588operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001589 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001591 __x += __n;
1592 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001593}
1594
Marshall Clow8411ebf2013-12-02 03:24:33 +00001595template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001596_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001597_Tp*
1598begin(_Tp (&__array)[_Np])
1599{
1600 return __array;
1601}
1602
1603template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001604_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001605_Tp*
1606end(_Tp (&__array)[_Np])
1607{
1608 return __array + _Np;
1609}
1610
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001611#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001612
Howard Hinnantc834c512011-11-29 18:15:50 +00001613template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001614_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001616begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001617{
1618 return __c.begin();
1619}
1620
Howard Hinnantc834c512011-11-29 18:15:50 +00001621template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001622_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001624begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625{
1626 return __c.begin();
1627}
1628
Howard Hinnantc834c512011-11-29 18:15:50 +00001629template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001630_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001632end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633{
1634 return __c.end();
1635}
1636
Howard Hinnantc834c512011-11-29 18:15:50 +00001637template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001638_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001639auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001640end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641{
1642 return __c.end();
1643}
1644
Marshall Clowb278e9c2013-08-30 01:17:07 +00001645#if _LIBCPP_STD_VER > 11
1646
Marshall Clow8411ebf2013-12-02 03:24:33 +00001647template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001648_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001649reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1650{
1651 return reverse_iterator<_Tp*>(__array + _Np);
1652}
1653
1654template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001655_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001656reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1657{
1658 return reverse_iterator<_Tp*>(__array);
1659}
1660
1661template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001662_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001663reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1664{
1665 return reverse_iterator<const _Ep*>(__il.end());
1666}
1667
1668template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001669_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001670reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1671{
1672 return reverse_iterator<const _Ep*>(__il.begin());
1673}
1674
Marshall Clowb278e9c2013-08-30 01:17:07 +00001675template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001676_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001677auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001678{
Marshall Clow3862f532016-08-10 20:04:46 +00001679 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001680}
1681
1682template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001683_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001684auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001685{
Marshall Clow3862f532016-08-10 20:04:46 +00001686 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001687}
1688
1689template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001690_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001691auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1692{
1693 return __c.rbegin();
1694}
1695
1696template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001697_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001698auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1699{
1700 return __c.rbegin();
1701}
1702
1703template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001704_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001705auto rend(_Cp& __c) -> decltype(__c.rend())
1706{
1707 return __c.rend();
1708}
1709
1710template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001711_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001712auto rend(const _Cp& __c) -> decltype(__c.rend())
1713{
1714 return __c.rend();
1715}
1716
1717template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001718_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001719auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001720{
Marshall Clow3862f532016-08-10 20:04:46 +00001721 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001722}
1723
1724template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001725_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001726auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001727{
Marshall Clow3862f532016-08-10 20:04:46 +00001728 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001729}
1730
1731#endif
1732
1733
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001734#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001735
Howard Hinnantc834c512011-11-29 18:15:50 +00001736template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001737_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001738typename _Cp::iterator
1739begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740{
1741 return __c.begin();
1742}
1743
Howard Hinnantc834c512011-11-29 18:15:50 +00001744template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001745_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001746typename _Cp::const_iterator
1747begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001748{
1749 return __c.begin();
1750}
1751
Howard Hinnantc834c512011-11-29 18:15:50 +00001752template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001753_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001754typename _Cp::iterator
1755end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001756{
1757 return __c.end();
1758}
1759
Howard Hinnantc834c512011-11-29 18:15:50 +00001760template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001761_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001762typename _Cp::const_iterator
1763end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001764{
1765 return __c.end();
1766}
1767
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001768#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769
Marshall Clowef357272014-11-19 19:43:23 +00001770#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001771
1772// #if _LIBCPP_STD_VER > 11
1773// template <>
1774// struct _LIBCPP_TEMPLATE_VIS plus<void>
1775// {
1776// template <class _T1, class _T2>
1777// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1778// auto operator()(_T1&& __t, _T2&& __u) const
1779// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1780// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1781// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1782// typedef void is_transparent;
1783// };
1784// #endif
1785
Marshall Clowc4b4a342015-02-11 16:14:01 +00001786template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001787_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001788constexpr auto size(const _Cont& __c)
1789_NOEXCEPT_(noexcept(__c.size()))
1790-> decltype (__c.size())
1791{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001792
Marshall Clowc4b4a342015-02-11 16:14:01 +00001793template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001794_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001795constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001796
Marshall Clow3c5363e2019-02-27 02:58:56 +00001797#if _LIBCPP_STD_VER > 17
1798template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001799_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001800constexpr auto ssize(const _Cont& __c)
1801_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1802-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1803{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1804
1805template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001806_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001807constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1808#endif
1809
Marshall Clowc4b4a342015-02-11 16:14:01 +00001810template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001811_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001812constexpr auto empty(const _Cont& __c)
1813_NOEXCEPT_(noexcept(__c.empty()))
1814-> decltype (__c.empty())
1815{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001816
Marshall Clowc4b4a342015-02-11 16:14:01 +00001817template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001818_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001819constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001820
1821template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001822_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001823constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1824
Marshall Clowc4b4a342015-02-11 16:14:01 +00001825template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001826_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001827auto data(_Cont& __c)
1828_NOEXCEPT_(noexcept(__c.data()))
1829-> decltype (__c.data())
1830{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001831
Marshall Clowc4b4a342015-02-11 16:14:01 +00001832template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001833_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001834auto data(const _Cont& __c)
1835_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001836-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001837{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001838
Marshall Clowc4b4a342015-02-11 16:14:01 +00001839template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001840_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001841constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001842
1843template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001844_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001845constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1846#endif
1847
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001848template <class _Container, class _Predicate>
1849typename _Container::size_type
1850__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
1851 typename _Container::size_type __old_size = __c.size();
1852
1853 const typename _Container::iterator __last = __c.end();
1854 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
1855 if (__pred(*__iter))
1856 __iter = __c.erase(__iter);
1857 else
1858 ++__iter;
1859 }
1860
1861 return __old_size - __c.size();
1862}
Marshall Clowef357272014-11-19 19:43:23 +00001863
Howard Hinnantc51e1022010-05-11 19:42:16 +00001864_LIBCPP_END_NAMESPACE_STD
1865
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001866#endif // _LIBCPP_ITERATOR