blob: 8dbcc9d0f355c1af4bd6490b942244beba5f30c4 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ITERATOR
11#define _LIBCPP_ITERATOR
12
13/*
14 iterator synopsis
15
Christopher Di Bella490fe402021-03-23 03:55:52 +000016#include <concepts>
17
Howard Hinnantc51e1022010-05-11 19:42:16 +000018namespace std
19{
Christopher Di Bellae00eebc2021-03-23 20:48:41 +000020template<class> struct incrementable_traits; // since C++20
Christopher Di Bellaa3a10062021-04-20 18:56:08 +000021template<class T>
22 using iter_difference_t = see below; // since C++20
23
Christopher Di Bellae00eebc2021-03-23 20:48:41 +000024template<class> struct indirectly_readable_traits; // since C++20
Christopher Di Bellaa3a10062021-04-20 18:56:08 +000025template<class T>
26 using iter_value_t = see below; // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000027
28template<class Iterator>
zoecarver9f1e2972021-04-20 08:50:11 -040029struct iterator_traits;
Howard Hinnantc51e1022010-05-11 19:42:16 +000030
31template<class T>
zoecarver9f1e2972021-04-20 08:50:11 -040032 requires is_object_v<T> // since C++20
33struct iterator_traits<T*>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000034
Christopher Di Bella875636f2021-04-04 05:12:46 +000035template<dereferenceable T>
36 using iter_reference_t = decltype(*declval<T&>());
37
Louis Dionneca989a52021-04-20 14:40:43 -040038namespace ranges::inline unspecified {
39 inline constexpr unspecified iter_move = unspecified; // since C++20, nodiscard as an extension
40}}
41
42template<dereferenceable T>
43 requires ...
44using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // since C++20
45
Louis Dionne463afb82021-04-22 11:05:30 -040046// [iterator.concepts], iterator concepts
47// [iterator.concept.readable], concept indirectly_readable
48template<class In>
49 concept indirectly_readable = see below; // since C++20
50
51// [iterator.concept.writable], concept indirectly_writable
52template<class Out, class T>
53 concept indirectly_writable = see below; // since C++20
54
Mark de Wever6639f422021-04-26 17:53:20 +020055// [iterator.concept.winc], concept weakly_incrementable
Christopher Di Bella54ffc182021-04-23 18:22:55 -070056template<class I>
57 concept weakly_incrementable = see below; // since C++20
58
59// [iterator.concept.inc], concept incrementable
60template<class I>
61 concept incrementable = see below; // since C++20
62
Mark de Wever6639f422021-04-26 17:53:20 +020063// [iterator.concept.iterator], concept input_or_output_iterator
Christopher Di Bella0ef52282021-04-09 02:10:32 +000064 template<class I>
65 concept input_or_output_iterator = see below; // since C++20
66
Mark de Wever6639f422021-04-26 17:53:20 +020067// [iterator.concept.sentinel], concept sentinel_for
Christopher Di Bella0ef52282021-04-09 02:10:32 +000068template<class S, class I>
69 concept sentinel_for = see below; // since C++20
70
zoecarver11391bc2021-04-26 09:35:47 -070071// [iterator.concept.sizedsentinel], concept sized_sentinel_for
72template<class S, class I>
73 inline constexpr bool disable_sized_sentinel_for = false;
74
75template<class S, class I>
76 concept sized_sentinel_for = see below;
77
Christopher Di Bella8250c632021-04-11 19:04:52 +000078// [iterator.concept.input], concept input_iterator
79template<class I>
80 concept input_iterator = see below; // since C++20
81
Christopher Di Bella8f1370d2021-04-11 22:11:03 +000082// [iterator.concept.forward], concept forward_iterator
83template<class I>
84 concept forward_iterator = see below; // since C++20
85
Christopher Di Bella10a31472021-04-12 01:16:45 +000086// [iterator.concept.bidir], concept bidirectional_iterator
87template<class I>
88 concept bidirectional_iterator = see below; // since C++20
89
zoecarver21da57e2021-04-23 17:11:44 -070090// [iterator.concept.random.access], concept random_access_iterator
91template<class I>
92 concept random_access_iterator = see below; // since C++20
93
Howard Hinnantc51e1022010-05-11 19:42:16 +000094template<class Category, class T, class Distance = ptrdiff_t,
95 class Pointer = T*, class Reference = T&>
96struct iterator
97{
98 typedef T value_type;
99 typedef Distance difference_type;
100 typedef Pointer pointer;
101 typedef Reference reference;
102 typedef Category iterator_category;
103};
104
105struct input_iterator_tag {};
106struct output_iterator_tag {};
107struct forward_iterator_tag : public input_iterator_tag {};
108struct bidirectional_iterator_tag : public forward_iterator_tag {};
109struct random_access_iterator_tag : public bidirectional_iterator_tag {};
110
Marshall Clow75468e72017-05-17 18:51:36 +0000111// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -0400112template <class InputIterator, class Distance> // constexpr in C++17
113 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114
Marshall Clow75468e72017-05-17 18:51:36 +0000115template <class InputIterator> // constexpr in C++17
116 constexpr typename iterator_traits<InputIterator>::difference_type
117 distance(InputIterator first, InputIterator last);
118
119template <class InputIterator> // constexpr in C++17
120 constexpr InputIterator next(InputIterator x,
121typename iterator_traits<InputIterator>::difference_type n = 1);
122
123template <class BidirectionalIterator> // constexpr in C++17
124 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +0000125 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126
Christopher Di Bellac6ead652021-05-05 07:14:08 +0000127// [range.iter.ops], range iterator operations
128namespace ranges {
129 // [range.iter.op.advance], ranges::advance
130 template<input_or_output_iterator I>
131 constexpr void advance(I& i, iter_difference_t<I> n); // since C++20
132 template<input_or_output_iterator I, sentinel_for<I> S>
133 constexpr void advance(I& i, S bound); // since C++20
134 template<input_or_output_iterator I, sentinel_for<I> S>
135 constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound); // since C++20
136}
137
Howard Hinnantc51e1022010-05-11 19:42:16 +0000138template <class Iterator>
139class reverse_iterator
140 : public iterator<typename iterator_traits<Iterator>::iterator_category,
141 typename iterator_traits<Iterator>::value_type,
142 typename iterator_traits<Iterator>::difference_type,
143 typename iterator_traits<Iterator>::pointer,
144 typename iterator_traits<Iterator>::reference>
145{
146protected:
147 Iterator current;
148public:
149 typedef Iterator iterator_type;
150 typedef typename iterator_traits<Iterator>::difference_type difference_type;
151 typedef typename iterator_traits<Iterator>::reference reference;
152 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000153
Marshall Clow5ace5542016-10-19 15:12:50 +0000154 constexpr reverse_iterator();
155 constexpr explicit reverse_iterator(Iterator x);
156 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
157 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
158 constexpr Iterator base() const;
159 constexpr reference operator*() const;
160 constexpr pointer operator->() const;
161 constexpr reverse_iterator& operator++();
162 constexpr reverse_iterator operator++(int);
163 constexpr reverse_iterator& operator--();
164 constexpr reverse_iterator operator--(int);
165 constexpr reverse_iterator operator+ (difference_type n) const;
166 constexpr reverse_iterator& operator+=(difference_type n);
167 constexpr reverse_iterator operator- (difference_type n) const;
168 constexpr reverse_iterator& operator-=(difference_type n);
169 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170};
171
172template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000173constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
175
176template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000177constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
179
180template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000181constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
183
184template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000185constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
187
188template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000189constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
191
192template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000193constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
195
196template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000197constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000198operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000199-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200
201template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000202constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000203operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000204 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205
Marshall Clow5ace5542016-10-19 15:12:50 +0000206template <class Iterator>
207constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000208
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209template <class Container>
210class back_insert_iterator
211{
212protected:
213 Container* container;
214public:
215 typedef Container container_type;
216 typedef void value_type;
217 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000218 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219 typedef void pointer;
220
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500221 explicit back_insert_iterator(Container& x); // constexpr in C++20
222 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
223 back_insert_iterator& operator*(); // constexpr in C++20
224 back_insert_iterator& operator++(); // constexpr in C++20
225 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226};
227
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500228template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000229
230template <class Container>
231class front_insert_iterator
232{
233protected:
234 Container* container;
235public:
236 typedef Container container_type;
237 typedef void value_type;
238 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000239 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240 typedef void pointer;
241
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500242 explicit front_insert_iterator(Container& x); // constexpr in C++20
243 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
244 front_insert_iterator& operator*(); // constexpr in C++20
245 front_insert_iterator& operator++(); // constexpr in C++20
246 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247};
248
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500249template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250
251template <class Container>
252class insert_iterator
253{
254protected:
255 Container* container;
256 typename Container::iterator iter;
257public:
258 typedef Container container_type;
259 typedef void value_type;
260 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000261 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262 typedef void pointer;
263
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500264 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
265 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
266 insert_iterator& operator*(); // constexpr in C++20
267 insert_iterator& operator++(); // constexpr in C++20
268 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000269};
270
271template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500272insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000274template <class Iterator>
275class move_iterator {
276public:
277 typedef Iterator iterator_type;
278 typedef typename iterator_traits<Iterator>::difference_type difference_type;
279 typedef Iterator pointer;
280 typedef typename iterator_traits<Iterator>::value_type value_type;
281 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
282 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000283
Marshall Clowb5f99122016-11-02 15:30:26 +0000284 constexpr move_iterator(); // all the constexprs are in C++17
285 constexpr explicit move_iterator(Iterator i);
286 template <class U>
287 constexpr move_iterator(const move_iterator<U>& u);
288 template <class U>
289 constexpr move_iterator& operator=(const move_iterator<U>& u);
290 constexpr iterator_type base() const;
291 constexpr reference operator*() const;
292 constexpr pointer operator->() const;
293 constexpr move_iterator& operator++();
294 constexpr move_iterator operator++(int);
295 constexpr move_iterator& operator--();
296 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000297 constexpr move_iterator operator+(difference_type n) const;
298 constexpr move_iterator& operator+=(difference_type n);
299 constexpr move_iterator operator-(difference_type n) const;
300 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000301 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000302private:
303 Iterator current; // exposition only
304};
305
306template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000307constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000308operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
309
310template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000311constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000312operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
313
314template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000315constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000316operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
317
318template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000319constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000320operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
321
322template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000323constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000324operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
325
326template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000327constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000328operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
329
330template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000331constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000332operator-(const move_iterator<Iterator1>& x,
333 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
334
335template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000336constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000337 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000338 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000339
Marshall Clowb5f99122016-11-02 15:30:26 +0000340template <class Iterator> // constexpr in C++17
341constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000342
343
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
345class istream_iterator
346 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
347{
348public:
349 typedef charT char_type;
350 typedef traits traits_type;
351 typedef basic_istream<charT,traits> istream_type;
352
Marshall Clow0735e4e2015-04-16 21:36:54 +0000353 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354 istream_iterator(istream_type& s);
355 istream_iterator(const istream_iterator& x);
356 ~istream_iterator();
357
358 const T& operator*() const;
359 const T* operator->() const;
360 istream_iterator& operator++();
361 istream_iterator operator++(int);
362};
363
364template <class T, class charT, class traits, class Distance>
365bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
366 const istream_iterator<T,charT,traits,Distance>& y);
367template <class T, class charT, class traits, class Distance>
368bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
369 const istream_iterator<T,charT,traits,Distance>& y);
370
371template <class T, class charT = char, class traits = char_traits<charT> >
372class ostream_iterator
373 : public iterator<output_iterator_tag, void, void, void ,void>
374{
375public:
376 typedef charT char_type;
377 typedef traits traits_type;
378 typedef basic_ostream<charT,traits> ostream_type;
379
380 ostream_iterator(ostream_type& s);
381 ostream_iterator(ostream_type& s, const charT* delimiter);
382 ostream_iterator(const ostream_iterator& x);
383 ~ostream_iterator();
384 ostream_iterator& operator=(const T& value);
385
386 ostream_iterator& operator*();
387 ostream_iterator& operator++();
388 ostream_iterator& operator++(int);
389};
390
391template<class charT, class traits = char_traits<charT> >
392class istreambuf_iterator
393 : public iterator<input_iterator_tag, charT,
394 typename traits::off_type, unspecified,
395 charT>
396{
397public:
398 typedef charT char_type;
399 typedef traits traits_type;
400 typedef typename traits::int_type int_type;
401 typedef basic_streambuf<charT,traits> streambuf_type;
402 typedef basic_istream<charT,traits> istream_type;
403
Howard Hinnant011138d2012-07-20 19:36:34 +0000404 istreambuf_iterator() noexcept;
405 istreambuf_iterator(istream_type& s) noexcept;
406 istreambuf_iterator(streambuf_type* s) noexcept;
407 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408
409 charT operator*() const;
410 pointer operator->() const;
411 istreambuf_iterator& operator++();
412 a-private-type operator++(int);
413
414 bool equal(const istreambuf_iterator& b) const;
415};
416
417template <class charT, class traits>
418bool operator==(const istreambuf_iterator<charT,traits>& a,
419 const istreambuf_iterator<charT,traits>& b);
420template <class charT, class traits>
421bool operator!=(const istreambuf_iterator<charT,traits>& a,
422 const istreambuf_iterator<charT,traits>& b);
423
424template <class charT, class traits = char_traits<charT> >
425class ostreambuf_iterator
426 : public iterator<output_iterator_tag, void, void, void, void>
427{
428public:
429 typedef charT char_type;
430 typedef traits traits_type;
431 typedef basic_streambuf<charT,traits> streambuf_type;
432 typedef basic_ostream<charT,traits> ostream_type;
433
Howard Hinnant011138d2012-07-20 19:36:34 +0000434 ostreambuf_iterator(ostream_type& s) noexcept;
435 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436 ostreambuf_iterator& operator=(charT c);
437 ostreambuf_iterator& operator*();
438 ostreambuf_iterator& operator++();
439 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000440 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441};
442
Marshall Clow99ba0022017-01-04 17:58:17 +0000443template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
444template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
445template <class C> constexpr auto end(C& c) -> decltype(c.end());
446template <class C> constexpr auto end(const C& c) -> decltype(c.end());
447template <class T, size_t N> constexpr T* begin(T (&array)[N]);
448template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
Marshall Clow99ba0022017-01-04 17:58:17 +0000450template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
451template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
452template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
453template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
454template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
455template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
456template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
457template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
458template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
459template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
460template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
461template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000462
Marshall Clowef357272014-11-19 19:43:23 +0000463// 24.8, container access:
464template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
465template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000466
467template <class C> constexpr auto ssize(const C& c)
Arthur O'Dwyer2fc9b5d2021-04-17 17:03:20 -0400468 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
Marshall Clow3c5363e2019-02-27 02:58:56 +0000469template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
470
Marshall Clowef357272014-11-19 19:43:23 +0000471template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
472template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
473template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
474template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
475template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
476template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
477template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
478
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479} // std
480
481*/
482
483#include <__config>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400484#include <__debug>
Marshall Clow3dc05502014-02-27 02:11:50 +0000485#include <__functional_base>
Christopher Di Bellac6ead652021-05-05 07:14:08 +0000486#include <__iterator/advance.h>
Louis Dionne463afb82021-04-22 11:05:30 -0400487#include <__iterator/concepts.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400488#include <__iterator/incrementable_traits.h>
Louis Dionneca989a52021-04-20 14:40:43 -0400489#include <__iterator/iter_move.h>
zoecarver5d41ff52021-04-19 14:44:42 -0700490#include <__iterator/iterator_traits.h>
Christopher Di Bella9c0adab2021-05-08 05:02:43 +0000491#include <__iterator/next.h>
Christopher Di Bellab8e21042021-05-16 01:39:22 +0000492#include <__iterator/prev.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400493#include <__iterator/readable_traits.h>
Louis Dionne735bc462021-04-14 13:59:03 -0400494#include <__memory/addressof.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500495#include <__memory/pointer_traits.h>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400496#include <compare>
497#include <concepts> // Mandated by the Standard.
498#include <cstddef>
499#include <initializer_list>
500#include <iosfwd> // for forward declarations of vector and string
501#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000502#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000503
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000504#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000506#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507
508_LIBCPP_BEGIN_NAMESPACE_STD
Christopher Di Bella490fe402021-03-23 03:55:52 +0000509
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510template<class _Category, class _Tp, class _Distance = ptrdiff_t,
511 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000512struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513{
514 typedef _Tp value_type;
515 typedef _Distance difference_type;
516 typedef _Pointer pointer;
517 typedef _Reference reference;
518 typedef _Category iterator_category;
519};
520
521template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000522inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523void __advance(_InputIter& __i,
524 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
525{
526 for (; __n > 0; --__n)
527 ++__i;
528}
529
530template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000531inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532void __advance(_BiDirIter& __i,
533 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
534{
535 if (__n >= 0)
536 for (; __n > 0; --__n)
537 ++__i;
538 else
539 for (; __n < 0; ++__n)
540 --__i;
541}
542
543template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000544inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545void __advance(_RandIter& __i,
546 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
547{
548 __i += __n;
549}
550
Christopher Di Bellac6ead652021-05-05 07:14:08 +0000551template <class _InputIter, class _Distance,
552 class = typename enable_if<is_integral<decltype(_VSTD::__convert_to_integral(declval<_Distance>()))>::value>::type>
Marshall Clow75468e72017-05-17 18:51:36 +0000553inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Louis Dionne45768662020-06-08 16:16:01 -0400554void advance(_InputIter& __i, _Distance __orig_n)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500556 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
Louis Dionne45768662020-06-08 16:16:01 -0400557 _IntegralSize __n = __orig_n;
Arthur O'Dwyerca133912021-04-20 15:59:22 -0400558 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
559 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500560 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561}
562
563template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000564inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565typename iterator_traits<_InputIter>::difference_type
566__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
567{
568 typename iterator_traits<_InputIter>::difference_type __r(0);
569 for (; __first != __last; ++__first)
570 ++__r;
571 return __r;
572}
573
574template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000575inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576typename iterator_traits<_RandIter>::difference_type
577__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
578{
579 return __last - __first;
580}
581
582template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000583inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584typename iterator_traits<_InputIter>::difference_type
585distance(_InputIter __first, _InputIter __last)
586{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500587 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588}
589
Marshall Clow990c70d2015-11-07 17:48:49 +0000590template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000591inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000592typename enable_if
593<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500594 __is_cpp17_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000595 _InputIter
596>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000597next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000598 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500600 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400601 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
Marshall Clow3d435212019-03-22 22:32:20 +0000602
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000603 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604 return __x;
605}
606
Marshall Clow3d435212019-03-22 22:32:20 +0000607template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000608inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000609typename enable_if
610<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500611 __is_cpp17_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000612 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000613>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000614prev(_InputIter __x,
615 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000616{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500617 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400618 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000619 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000620 return __x;
621}
622
Eric Fiselier883af112017-04-13 02:54:13 +0000623
624template <class _Tp, class = void>
625struct __is_stashing_iterator : false_type {};
626
627template <class _Tp>
628struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
629 : true_type {};
630
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000632class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633 : public iterator<typename iterator_traits<_Iter>::iterator_category,
634 typename iterator_traits<_Iter>::value_type,
635 typename iterator_traits<_Iter>::difference_type,
636 typename iterator_traits<_Iter>::pointer,
637 typename iterator_traits<_Iter>::reference>
638{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000639private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000640 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000641
642 static_assert(!__is_stashing_iterator<_Iter>::value,
643 "The specified iterator type cannot be used with reverse_iterator; "
644 "Using stashing iterators with reverse_iterator causes undefined behavior");
645
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000646protected:
647 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648public:
649 typedef _Iter iterator_type;
650 typedef typename iterator_traits<_Iter>::difference_type difference_type;
651 typedef typename iterator_traits<_Iter>::reference reference;
652 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500653 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
654 random_access_iterator_tag,
655 typename iterator_traits<_Iter>::iterator_category> iterator_category;
656#if _LIBCPP_STD_VER > 17
657 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
658 random_access_iterator_tag,
659 bidirectional_iterator_tag> iterator_concept;
660#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000661
Marshall Clow5ace5542016-10-19 15:12:50 +0000662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
663 reverse_iterator() : __t(), current() {}
664 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
665 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
666 template <class _Up>
667 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
668 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
669 template <class _Up>
670 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
671 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
672 { __t = current = __u.base(); return *this; }
673 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
674 _Iter base() const {return current;}
675 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
676 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
677 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
678 pointer operator->() const {return _VSTD::addressof(operator*());}
679 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
680 reverse_iterator& operator++() {--current; return *this;}
681 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
682 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
683 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
684 reverse_iterator& operator--() {++current; return *this;}
685 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
686 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
687 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
688 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
689 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
690 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
691 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
692 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
693 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
694 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
695 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
696 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697};
698
699template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000700inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701bool
702operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
703{
704 return __x.base() == __y.base();
705}
706
707template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000708inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709bool
710operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
711{
712 return __x.base() > __y.base();
713}
714
715template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000716inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717bool
718operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
719{
720 return __x.base() != __y.base();
721}
722
723template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000724inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725bool
726operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
727{
728 return __x.base() < __y.base();
729}
730
731template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000732inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733bool
734operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
735{
736 return __x.base() <= __y.base();
737}
738
739template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000740inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741bool
742operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
743{
744 return __x.base() >= __y.base();
745}
746
Marshall Clow476d3f42016-07-18 13:19:00 +0000747#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000748template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000749inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000750auto
751operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
752-> decltype(__y.base() - __x.base())
753{
754 return __y.base() - __x.base();
755}
756#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757template <class _Iter1, class _Iter2>
758inline _LIBCPP_INLINE_VISIBILITY
759typename reverse_iterator<_Iter1>::difference_type
760operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
761{
762 return __y.base() - __x.base();
763}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000764#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765
766template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000767inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768reverse_iterator<_Iter>
769operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
770{
771 return reverse_iterator<_Iter>(__x.base() - __n);
772}
773
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000774#if _LIBCPP_STD_VER > 11
775template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000776inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000777reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
778{
779 return reverse_iterator<_Iter>(__i);
780}
781#endif
782
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000784class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785 : public iterator<output_iterator_tag,
786 void,
787 void,
788 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000789 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790{
791protected:
792 _Container* container;
793public:
794 typedef _Container container_type;
795
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500796 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
797 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000798 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000799#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500800 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000801 {container->push_back(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400802#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500803 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
804 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
805 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806};
807
808template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500809inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810back_insert_iterator<_Container>
811back_inserter(_Container& __x)
812{
813 return back_insert_iterator<_Container>(__x);
814}
815
816template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000817class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818 : public iterator<output_iterator_tag,
819 void,
820 void,
821 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000822 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823{
824protected:
825 _Container* container;
826public:
827 typedef _Container container_type;
828
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500829 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
830 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000831 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000832#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500833 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000834 {container->push_front(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400835#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500836 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
837 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
838 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839};
840
841template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500842inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843front_insert_iterator<_Container>
844front_inserter(_Container& __x)
845{
846 return front_insert_iterator<_Container>(__x);
847}
848
849template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000850class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851 : public iterator<output_iterator_tag,
852 void,
853 void,
854 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000855 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856{
857protected:
858 _Container* container;
859 typename _Container::iterator iter;
860public:
861 typedef _Container container_type;
862
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500863 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000864 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500865 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000866 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000867#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500868 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000869 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400870#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500871 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
872 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
873 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874};
875
876template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500877inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000878insert_iterator<_Container>
879inserter(_Container& __x, typename _Container::iterator __i)
880{
881 return insert_iterator<_Container>(__x, __i);
882}
883
884template <class _Tp, class _CharT = char,
885 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000886class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
888{
889public:
890 typedef _CharT char_type;
891 typedef _Traits traits_type;
892 typedef basic_istream<_CharT,_Traits> istream_type;
893private:
894 istream_type* __in_stream_;
895 _Tp __value_;
896public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500897 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000898 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899 {
900 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500901 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902 }
903
904 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000905 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
907 {
908 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500909 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910 return *this;
911 }
912 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
913 {istream_iterator __t(*this); ++(*this); return __t;}
914
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000915 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000917 bool
918 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
919 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000921 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000923 bool
924 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
925 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000926};
927
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000928template <class _Tp, class _CharT, class _Traits, class _Distance>
929inline _LIBCPP_INLINE_VISIBILITY
930bool
931operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
932 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
933{
934 return __x.__in_stream_ == __y.__in_stream_;
935}
936
937template <class _Tp, class _CharT, class _Traits, class _Distance>
938inline _LIBCPP_INLINE_VISIBILITY
939bool
940operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
941 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
942{
943 return !(__x == __y);
944}
945
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000947class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948 : public iterator<output_iterator_tag, void, void, void, void>
949{
950public:
Louis Dionnea4d79522020-09-11 10:15:56 -0400951 typedef output_iterator_tag iterator_category;
952 typedef void value_type;
953#if _LIBCPP_STD_VER > 17
954 typedef std::ptrdiff_t difference_type;
955#else
956 typedef void difference_type;
957#endif
958 typedef void pointer;
959 typedef void reference;
960 typedef _CharT char_type;
961 typedef _Traits traits_type;
962 typedef basic_ostream<_CharT, _Traits> ostream_type;
963
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964private:
965 ostream_type* __out_stream_;
966 const char_type* __delim_;
967public:
Marshall Clow27a89512016-10-12 16:13:48 +0000968 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500969 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +0000970 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +0000971 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000972 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973 {
Howard Hinnantbf074022011-10-22 20:59:45 +0000974 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975 if (__delim_)
976 *__out_stream_ << __delim_;
977 return *this;
978 }
979
980 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
981 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
982 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
983};
984
985template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000986class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 : public iterator<input_iterator_tag, _CharT,
988 typename _Traits::off_type, _CharT*,
989 _CharT>
990{
991public:
992 typedef _CharT char_type;
993 typedef _Traits traits_type;
994 typedef typename _Traits::int_type int_type;
995 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
996 typedef basic_istream<_CharT,_Traits> istream_type;
997private:
Howard Hinnant3e57b272012-11-16 22:17:23 +0000998 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000999
1000 class __proxy
1001 {
1002 char_type __keep_;
1003 streambuf_type* __sbuf_;
1004 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
1005 : __keep_(__c), __sbuf_(__s) {}
1006 friend class istreambuf_iterator;
1007 public:
1008 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
1009 };
1010
Howard Hinnant756c69b2010-09-22 16:48:34 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +00001012 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013 {
1014 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001015 __sbuf_ = nullptr;
1016 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 }
1018public:
Bruce Mitchener170d8972020-11-24 12:53:53 -05001019 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001020 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001021 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001022 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001023 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001024 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 : __sbuf_(__p.__sbuf_) {}
1026
Howard Hinnant28b24882011-12-01 20:21:04 +00001027 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1028 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1030 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001031 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 return *this;
1033 }
1034 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1035 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001036 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001037 }
1038
1039 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001040 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001041};
1042
1043template <class _CharT, class _Traits>
1044inline _LIBCPP_INLINE_VISIBILITY
1045bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1046 const istreambuf_iterator<_CharT,_Traits>& __b)
1047 {return __a.equal(__b);}
1048
1049template <class _CharT, class _Traits>
1050inline _LIBCPP_INLINE_VISIBILITY
1051bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1052 const istreambuf_iterator<_CharT,_Traits>& __b)
1053 {return !__a.equal(__b);}
1054
1055template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001056class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 : public iterator<output_iterator_tag, void, void, void, void>
1058{
1059public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001060 typedef output_iterator_tag iterator_category;
1061 typedef void value_type;
1062#if _LIBCPP_STD_VER > 17
1063 typedef std::ptrdiff_t difference_type;
1064#else
1065 typedef void difference_type;
1066#endif
1067 typedef void pointer;
1068 typedef void reference;
1069 typedef _CharT char_type;
1070 typedef _Traits traits_type;
1071 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1072 typedef basic_ostream<_CharT, _Traits> ostream_type;
1073
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074private:
1075 streambuf_type* __sbuf_;
1076public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001077 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001079 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080 : __sbuf_(__s) {}
1081 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1082 {
1083 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001084 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 return *this;
1086 }
1087 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1088 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1089 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001090 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001091
1092 template <class _Ch, class _Tr>
1093 friend
1094 _LIBCPP_HIDDEN
1095 ostreambuf_iterator<_Ch, _Tr>
1096 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1097 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1098 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099};
1100
1101template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001102class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103{
1104private:
1105 _Iter __i;
1106public:
1107 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108 typedef typename iterator_traits<iterator_type>::value_type value_type;
1109 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001110 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001111 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1112 random_access_iterator_tag,
1113 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1114#if _LIBCPP_STD_VER > 17
1115 typedef input_iterator_tag iterator_concept;
1116#endif
1117
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001118#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001119 typedef typename iterator_traits<iterator_type>::reference __reference;
1120 typedef typename conditional<
1121 is_reference<__reference>::value,
1122 typename remove_reference<__reference>::type&&,
1123 __reference
1124 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001125#else
1126 typedef typename iterator_traits<iterator_type>::reference reference;
1127#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001128
Marshall Clowb5f99122016-11-02 15:30:26 +00001129 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1130 move_iterator() : __i() {}
1131 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1132 explicit move_iterator(_Iter __x) : __i(__x) {}
1133 template <class _Up>
1134 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1135 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1136 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001137 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001138 reference operator*() const { return static_cast<reference>(*__i); }
1139 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1140 pointer operator->() const { return __i;}
1141 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1142 move_iterator& operator++() {++__i; return *this;}
1143 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1144 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1145 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1146 move_iterator& operator--() {--__i; return *this;}
1147 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1148 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1149 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1150 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1151 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1152 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1153 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1154 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1155 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1156 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1157 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1158 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159};
1160
1161template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001162inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001163bool
1164operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1165{
1166 return __x.base() == __y.base();
1167}
1168
1169template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001170inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001171bool
1172operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1173{
1174 return __x.base() < __y.base();
1175}
1176
1177template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001178inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179bool
1180operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1181{
1182 return __x.base() != __y.base();
1183}
1184
1185template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001186inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001187bool
1188operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1189{
1190 return __x.base() > __y.base();
1191}
1192
1193template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001194inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195bool
1196operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1197{
1198 return __x.base() >= __y.base();
1199}
1200
1201template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001202inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203bool
1204operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1205{
1206 return __x.base() <= __y.base();
1207}
1208
Marshall Clow476d3f42016-07-18 13:19:00 +00001209#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001210template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001211inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001212auto
1213operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1214-> decltype(__x.base() - __y.base())
1215{
1216 return __x.base() - __y.base();
1217}
1218#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219template <class _Iter1, class _Iter2>
1220inline _LIBCPP_INLINE_VISIBILITY
1221typename move_iterator<_Iter1>::difference_type
1222operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1223{
1224 return __x.base() - __y.base();
1225}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001226#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227
1228template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001229inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230move_iterator<_Iter>
1231operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1232{
1233 return move_iterator<_Iter>(__x.base() + __n);
1234}
1235
1236template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001237inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001239make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240{
1241 return move_iterator<_Iter>(__i);
1242}
1243
1244// __wrap_iter
1245
1246template <class _Iter> class __wrap_iter;
1247
1248template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001249_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001251operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001252
1253template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001254_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001255bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001256operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257
1258template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001259_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001261operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262
1263template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001264_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001266operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267
1268template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001269_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001271operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272
1273template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001274_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001276operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277
Marshall Clow476d3f42016-07-18 13:19:00 +00001278#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001279template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001280_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001281auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001282operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001283-> decltype(__x.base() - __y.base());
1284#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001286_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001288operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001289#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290
1291template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001292_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001294operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001295
Louis Dionne65b433b2019-11-06 12:02:41 +00001296template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1297template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001298template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1299template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301template <class _Iter>
1302class __wrap_iter
1303{
1304public:
1305 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001306 typedef typename iterator_traits<iterator_type>::value_type value_type;
1307 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1308 typedef typename iterator_traits<iterator_type>::pointer pointer;
1309 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001310 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1311#if _LIBCPP_STD_VER > 17
Arthur O'Dwyer6eb8a5d2021-05-19 11:54:31 -04001312 typedef contiguous_iterator_tag iterator_concept;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001313#endif
1314
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315private:
1316 iterator_type __i;
1317public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001318 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001319#if _LIBCPP_STD_VER > 11
1320 : __i{}
1321#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001322 {
Louis Dionneba400782020-10-02 15:02:52 -04001323#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001324 __get_db()->__insert_i(this);
1325#endif
1326 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001327 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1328 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001329 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001330 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001331 {
Louis Dionneba400782020-10-02 15:02:52 -04001332#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001333 __get_db()->__iterator_copy(this, &__u);
1334#endif
1335 }
Louis Dionneba400782020-10-02 15:02:52 -04001336#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001337 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001338 __wrap_iter(const __wrap_iter& __x)
1339 : __i(__x.base())
1340 {
1341 __get_db()->__iterator_copy(this, &__x);
1342 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001343 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001344 __wrap_iter& operator=(const __wrap_iter& __x)
1345 {
1346 if (this != &__x)
1347 {
1348 __get_db()->__iterator_copy(this, &__x);
1349 __i = __x.__i;
1350 }
1351 return *this;
1352 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001353 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001354 ~__wrap_iter()
1355 {
1356 __get_db()->__erase_i(this);
1357 }
1358#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001360 {
Louis Dionneba400782020-10-02 15:02:52 -04001361#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001362 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1363 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001364#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001365 return *__i;
1366 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001367 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001368 {
Louis Dionneba400782020-10-02 15:02:52 -04001369#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001370 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1371 "Attempted to dereference a non-dereferenceable iterator");
1372#endif
Louis Dionne1c8315b2021-05-04 18:51:58 -04001373 return _VSTD::__to_address(__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001374 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001375 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001376 {
Louis Dionneba400782020-10-02 15:02:52 -04001377#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001378 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001379 "Attempted to increment a non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001380#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001381 ++__i;
1382 return *this;
1383 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001384 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001385 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001386
Eric Fiselier873b8d32019-03-18 21:50:12 +00001387 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _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()->__decrementable(this),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001391 "Attempted to decrement a non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001392#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001393 --__i;
1394 return *this;
1395 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001396 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001397 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001398 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001399 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001400 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001401 {
Louis Dionneba400782020-10-02 15:02:52 -04001402#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001403 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001404 "Attempted to add/subtract an iterator outside its valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001405#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001406 __i += __n;
1407 return *this;
1408 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001409 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001410 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001411 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001412 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001413 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001414 {
Louis Dionneba400782020-10-02 15:02:52 -04001415#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001416 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001417 "Attempted to subscript an iterator outside its valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001418#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001419 return __i[__n];
1420 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001421
Eric Fiselier873b8d32019-03-18 21:50:12 +00001422 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001423
1424private:
Louis Dionneba400782020-10-02 15:02:52 -04001425#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001426 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001427 {
1428 __get_db()->__insert_ic(this, __p);
1429 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001430#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001431 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001432#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433
1434 template <class _Up> friend class __wrap_iter;
1435 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001436 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001437 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001438
1439 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001440 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001441 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001442 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001443
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001445 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001447 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001448
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001450 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001451 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001452 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001453
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001455 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001457 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001458
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001460 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001462 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001463
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001465 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001466 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001467 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001468
Marshall Clow476d3f42016-07-18 13:19:00 +00001469#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001470 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001471 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001472 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001473 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001474 -> decltype(__x.base() - __y.base());
1475#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001476 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001477 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001479 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001480#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001481
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001483 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001485 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486};
1487
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001488#if _LIBCPP_STD_VER <= 17
1489template <class _It>
Arthur O'Dwyer6eb8a5d2021-05-19 11:54:31 -04001490struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001491#endif
1492
1493template <class _Iter>
1494_LIBCPP_CONSTEXPR
Arthur O'Dwyer6eb8a5d2021-05-19 11:54:31 -04001495decltype(_VSTD::__to_address(declval<_Iter>()))
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001496__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1497 return _VSTD::__to_address(__w.base());
1498}
1499
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001501inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001503operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504{
1505 return __x.base() == __y.base();
1506}
1507
1508template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001509inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001510bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001511operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512{
Louis Dionneba400782020-10-02 15:02:52 -04001513#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001514 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001515 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001516#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001517 return __x.base() < __y.base();
1518}
1519
1520template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001521inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001523operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001525 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526}
1527
1528template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001529inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001530bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001531operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001533 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534}
1535
1536template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001537inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001538bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001539operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001540{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001541 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001542}
1543
1544template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001545inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001547operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001548{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001549 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550}
1551
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001552template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001553inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001554bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001555operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001556{
1557 return !(__x == __y);
1558}
1559
1560template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001561inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001562bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001563operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001564{
1565 return __y < __x;
1566}
1567
1568template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001569inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001570bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001571operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001572{
1573 return !(__x < __y);
1574}
1575
1576template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001577inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001578bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001579operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001580{
1581 return !(__y < __x);
1582}
1583
Marshall Clow476d3f42016-07-18 13:19:00 +00001584#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001585template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001586inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001587auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001588operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001589-> decltype(__x.base() - __y.base())
1590{
Louis Dionneba400782020-10-02 15:02:52 -04001591#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001592 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1593 "Attempted to subtract incompatible iterators");
1594#endif
1595 return __x.base() - __y.base();
1596}
1597#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001599inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001601operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602{
Louis Dionneba400782020-10-02 15:02:52 -04001603#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001604 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001605 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001606#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607 return __x.base() - __y.base();
1608}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001609#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001610
1611template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001612inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613__wrap_iter<_Iter>
1614operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001615 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001616{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001617 __x += __n;
1618 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619}
1620
Marshall Clow8411ebf2013-12-02 03:24:33 +00001621template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001622_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001623_Tp*
1624begin(_Tp (&__array)[_Np])
1625{
1626 return __array;
1627}
1628
1629template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001630_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001631_Tp*
1632end(_Tp (&__array)[_Np])
1633{
1634 return __array + _Np;
1635}
1636
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001637#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001638
Howard Hinnantc834c512011-11-29 18:15:50 +00001639template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001640_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001642begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001643{
1644 return __c.begin();
1645}
1646
Howard Hinnantc834c512011-11-29 18:15:50 +00001647template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001648_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001649auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001650begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651{
1652 return __c.begin();
1653}
1654
Howard Hinnantc834c512011-11-29 18:15:50 +00001655template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001656_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001657auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001658end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659{
1660 return __c.end();
1661}
1662
Howard Hinnantc834c512011-11-29 18:15:50 +00001663template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001664_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001665auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001666end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001667{
1668 return __c.end();
1669}
1670
Marshall Clowb278e9c2013-08-30 01:17:07 +00001671#if _LIBCPP_STD_VER > 11
1672
Marshall Clow8411ebf2013-12-02 03:24:33 +00001673template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001674_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001675reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1676{
1677 return reverse_iterator<_Tp*>(__array + _Np);
1678}
1679
1680template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001681_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001682reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1683{
1684 return reverse_iterator<_Tp*>(__array);
1685}
1686
1687template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001688_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001689reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1690{
1691 return reverse_iterator<const _Ep*>(__il.end());
1692}
1693
1694template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001695_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001696reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1697{
1698 return reverse_iterator<const _Ep*>(__il.begin());
1699}
1700
Marshall Clowb278e9c2013-08-30 01:17:07 +00001701template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001702_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001703auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001704{
Marshall Clow3862f532016-08-10 20:04:46 +00001705 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001706}
1707
1708template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001709_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001710auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001711{
Marshall Clow3862f532016-08-10 20:04:46 +00001712 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001713}
1714
1715template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001716_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001717auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1718{
1719 return __c.rbegin();
1720}
1721
1722template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001723_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001724auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1725{
1726 return __c.rbegin();
1727}
1728
1729template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001730_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001731auto rend(_Cp& __c) -> decltype(__c.rend())
1732{
1733 return __c.rend();
1734}
1735
1736template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001737_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001738auto rend(const _Cp& __c) -> decltype(__c.rend())
1739{
1740 return __c.rend();
1741}
1742
1743template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001744_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001745auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001746{
Marshall Clow3862f532016-08-10 20:04:46 +00001747 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001748}
1749
1750template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001751_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001752auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001753{
Marshall Clow3862f532016-08-10 20:04:46 +00001754 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001755}
1756
1757#endif
1758
1759
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001760#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001761
Howard Hinnantc834c512011-11-29 18:15:50 +00001762template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001763_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001764typename _Cp::iterator
1765begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001766{
1767 return __c.begin();
1768}
1769
Howard Hinnantc834c512011-11-29 18:15:50 +00001770template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001771_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001772typename _Cp::const_iterator
1773begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001774{
1775 return __c.begin();
1776}
1777
Howard Hinnantc834c512011-11-29 18:15:50 +00001778template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001779_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001780typename _Cp::iterator
1781end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001782{
1783 return __c.end();
1784}
1785
Howard Hinnantc834c512011-11-29 18:15:50 +00001786template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001787_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001788typename _Cp::const_iterator
1789end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001790{
1791 return __c.end();
1792}
1793
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001794#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001795
Marshall Clowef357272014-11-19 19:43:23 +00001796#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001797
1798// #if _LIBCPP_STD_VER > 11
1799// template <>
1800// struct _LIBCPP_TEMPLATE_VIS plus<void>
1801// {
1802// template <class _T1, class _T2>
1803// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1804// auto operator()(_T1&& __t, _T2&& __u) const
1805// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1806// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1807// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1808// typedef void is_transparent;
1809// };
1810// #endif
1811
Marshall Clowc4b4a342015-02-11 16:14:01 +00001812template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001813_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001814constexpr auto size(const _Cont& __c)
1815_NOEXCEPT_(noexcept(__c.size()))
1816-> decltype (__c.size())
1817{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001818
Marshall Clowc4b4a342015-02-11 16:14:01 +00001819template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001820_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001821constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001822
Marshall Clow3c5363e2019-02-27 02:58:56 +00001823#if _LIBCPP_STD_VER > 17
1824template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001825_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001826constexpr auto ssize(const _Cont& __c)
1827_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1828-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1829{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1830
1831template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001832_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001833constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1834#endif
1835
Marshall Clowc4b4a342015-02-11 16:14:01 +00001836template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001837_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001838constexpr auto empty(const _Cont& __c)
1839_NOEXCEPT_(noexcept(__c.empty()))
1840-> decltype (__c.empty())
1841{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001842
Marshall Clowc4b4a342015-02-11 16:14:01 +00001843template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001844_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001845constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001846
1847template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001848_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001849constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1850
Marshall Clowc4b4a342015-02-11 16:14:01 +00001851template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001852_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001853auto data(_Cont& __c)
1854_NOEXCEPT_(noexcept(__c.data()))
1855-> decltype (__c.data())
1856{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001857
Marshall Clowc4b4a342015-02-11 16:14:01 +00001858template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001859_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001860auto data(const _Cont& __c)
1861_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001862-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001863{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001864
Marshall Clowc4b4a342015-02-11 16:14:01 +00001865template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001866_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001867constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001868
1869template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001870_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001871constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1872#endif
1873
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001874template <class _Container, class _Predicate>
1875typename _Container::size_type
1876__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
1877 typename _Container::size_type __old_size = __c.size();
1878
1879 const typename _Container::iterator __last = __c.end();
1880 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
1881 if (__pred(*__iter))
1882 __iter = __c.erase(__iter);
1883 else
1884 ++__iter;
1885 }
1886
1887 return __old_size - __c.size();
1888}
Marshall Clowef357272014-11-19 19:43:23 +00001889
Howard Hinnantc51e1022010-05-11 19:42:16 +00001890_LIBCPP_END_NAMESPACE_STD
1891
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001892#endif // _LIBCPP_ITERATOR