blob: ad98d8ca7b7040d0f8f4cc37dabc2f66145d57f4 [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
127template <class Iterator>
128class reverse_iterator
129 : public iterator<typename iterator_traits<Iterator>::iterator_category,
130 typename iterator_traits<Iterator>::value_type,
131 typename iterator_traits<Iterator>::difference_type,
132 typename iterator_traits<Iterator>::pointer,
133 typename iterator_traits<Iterator>::reference>
134{
135protected:
136 Iterator current;
137public:
138 typedef Iterator iterator_type;
139 typedef typename iterator_traits<Iterator>::difference_type difference_type;
140 typedef typename iterator_traits<Iterator>::reference reference;
141 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000142
Marshall Clow5ace5542016-10-19 15:12:50 +0000143 constexpr reverse_iterator();
144 constexpr explicit reverse_iterator(Iterator x);
145 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
146 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
147 constexpr Iterator base() const;
148 constexpr reference operator*() const;
149 constexpr pointer operator->() const;
150 constexpr reverse_iterator& operator++();
151 constexpr reverse_iterator operator++(int);
152 constexpr reverse_iterator& operator--();
153 constexpr reverse_iterator operator--(int);
154 constexpr reverse_iterator operator+ (difference_type n) const;
155 constexpr reverse_iterator& operator+=(difference_type n);
156 constexpr reverse_iterator operator- (difference_type n) const;
157 constexpr reverse_iterator& operator-=(difference_type n);
158 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159};
160
161template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000162constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
164
165template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000166constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
168
169template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000170constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
172
173template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000174constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
176
177template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000178constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
180
181template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000182constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
184
185template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000186constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000187operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000188-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189
190template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000191constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000192operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000193 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194
Marshall Clow5ace5542016-10-19 15:12:50 +0000195template <class Iterator>
196constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000197
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198template <class Container>
199class back_insert_iterator
200{
201protected:
202 Container* container;
203public:
204 typedef Container container_type;
205 typedef void value_type;
206 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000207 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208 typedef void pointer;
209
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500210 explicit back_insert_iterator(Container& x); // constexpr in C++20
211 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
212 back_insert_iterator& operator*(); // constexpr in C++20
213 back_insert_iterator& operator++(); // constexpr in C++20
214 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215};
216
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500217template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218
219template <class Container>
220class front_insert_iterator
221{
222protected:
223 Container* container;
224public:
225 typedef Container container_type;
226 typedef void value_type;
227 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000228 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000229 typedef void pointer;
230
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500231 explicit front_insert_iterator(Container& x); // constexpr in C++20
232 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
233 front_insert_iterator& operator*(); // constexpr in C++20
234 front_insert_iterator& operator++(); // constexpr in C++20
235 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000236};
237
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500238template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239
240template <class Container>
241class insert_iterator
242{
243protected:
244 Container* container;
245 typename Container::iterator iter;
246public:
247 typedef Container container_type;
248 typedef void value_type;
249 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000250 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 typedef void pointer;
252
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500253 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
254 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
255 insert_iterator& operator*(); // constexpr in C++20
256 insert_iterator& operator++(); // constexpr in C++20
257 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000258};
259
260template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500261insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000263template <class Iterator>
264class move_iterator {
265public:
266 typedef Iterator iterator_type;
267 typedef typename iterator_traits<Iterator>::difference_type difference_type;
268 typedef Iterator pointer;
269 typedef typename iterator_traits<Iterator>::value_type value_type;
270 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
271 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000272
Marshall Clowb5f99122016-11-02 15:30:26 +0000273 constexpr move_iterator(); // all the constexprs are in C++17
274 constexpr explicit move_iterator(Iterator i);
275 template <class U>
276 constexpr move_iterator(const move_iterator<U>& u);
277 template <class U>
278 constexpr move_iterator& operator=(const move_iterator<U>& u);
279 constexpr iterator_type base() const;
280 constexpr reference operator*() const;
281 constexpr pointer operator->() const;
282 constexpr move_iterator& operator++();
283 constexpr move_iterator operator++(int);
284 constexpr move_iterator& operator--();
285 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000286 constexpr move_iterator operator+(difference_type n) const;
287 constexpr move_iterator& operator+=(difference_type n);
288 constexpr move_iterator operator-(difference_type n) const;
289 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000290 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000291private:
292 Iterator current; // exposition only
293};
294
295template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000296constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000297operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
298
299template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000300constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000301operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
302
303template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000304constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000305operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
306
307template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000308constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000309operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
310
311template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000312constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000313operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
314
315template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000316constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000317operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
318
319template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000320constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000321operator-(const move_iterator<Iterator1>& x,
322 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
323
324template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000325constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000326 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000327 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000328
Marshall Clowb5f99122016-11-02 15:30:26 +0000329template <class Iterator> // constexpr in C++17
330constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000331
332
Howard Hinnantc51e1022010-05-11 19:42:16 +0000333template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
334class istream_iterator
335 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
336{
337public:
338 typedef charT char_type;
339 typedef traits traits_type;
340 typedef basic_istream<charT,traits> istream_type;
341
Marshall Clow0735e4e2015-04-16 21:36:54 +0000342 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000343 istream_iterator(istream_type& s);
344 istream_iterator(const istream_iterator& x);
345 ~istream_iterator();
346
347 const T& operator*() const;
348 const T* operator->() const;
349 istream_iterator& operator++();
350 istream_iterator operator++(int);
351};
352
353template <class T, class charT, class traits, class Distance>
354bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
355 const istream_iterator<T,charT,traits,Distance>& y);
356template <class T, class charT, class traits, class Distance>
357bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
358 const istream_iterator<T,charT,traits,Distance>& y);
359
360template <class T, class charT = char, class traits = char_traits<charT> >
361class ostream_iterator
362 : public iterator<output_iterator_tag, void, void, void ,void>
363{
364public:
365 typedef charT char_type;
366 typedef traits traits_type;
367 typedef basic_ostream<charT,traits> ostream_type;
368
369 ostream_iterator(ostream_type& s);
370 ostream_iterator(ostream_type& s, const charT* delimiter);
371 ostream_iterator(const ostream_iterator& x);
372 ~ostream_iterator();
373 ostream_iterator& operator=(const T& value);
374
375 ostream_iterator& operator*();
376 ostream_iterator& operator++();
377 ostream_iterator& operator++(int);
378};
379
380template<class charT, class traits = char_traits<charT> >
381class istreambuf_iterator
382 : public iterator<input_iterator_tag, charT,
383 typename traits::off_type, unspecified,
384 charT>
385{
386public:
387 typedef charT char_type;
388 typedef traits traits_type;
389 typedef typename traits::int_type int_type;
390 typedef basic_streambuf<charT,traits> streambuf_type;
391 typedef basic_istream<charT,traits> istream_type;
392
Howard Hinnant011138d2012-07-20 19:36:34 +0000393 istreambuf_iterator() noexcept;
394 istreambuf_iterator(istream_type& s) noexcept;
395 istreambuf_iterator(streambuf_type* s) noexcept;
396 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397
398 charT operator*() const;
399 pointer operator->() const;
400 istreambuf_iterator& operator++();
401 a-private-type operator++(int);
402
403 bool equal(const istreambuf_iterator& b) const;
404};
405
406template <class charT, class traits>
407bool operator==(const istreambuf_iterator<charT,traits>& a,
408 const istreambuf_iterator<charT,traits>& b);
409template <class charT, class traits>
410bool operator!=(const istreambuf_iterator<charT,traits>& a,
411 const istreambuf_iterator<charT,traits>& b);
412
413template <class charT, class traits = char_traits<charT> >
414class ostreambuf_iterator
415 : public iterator<output_iterator_tag, void, void, void, void>
416{
417public:
418 typedef charT char_type;
419 typedef traits traits_type;
420 typedef basic_streambuf<charT,traits> streambuf_type;
421 typedef basic_ostream<charT,traits> ostream_type;
422
Howard Hinnant011138d2012-07-20 19:36:34 +0000423 ostreambuf_iterator(ostream_type& s) noexcept;
424 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 ostreambuf_iterator& operator=(charT c);
426 ostreambuf_iterator& operator*();
427 ostreambuf_iterator& operator++();
428 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000429 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430};
431
Marshall Clow99ba0022017-01-04 17:58:17 +0000432template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
433template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
434template <class C> constexpr auto end(C& c) -> decltype(c.end());
435template <class C> constexpr auto end(const C& c) -> decltype(c.end());
436template <class T, size_t N> constexpr T* begin(T (&array)[N]);
437template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438
Marshall Clow99ba0022017-01-04 17:58:17 +0000439template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
440template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
441template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
442template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
443template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
444template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
445template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
446template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
447template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
448template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
449template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
450template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000451
Marshall Clowef357272014-11-19 19:43:23 +0000452// 24.8, container access:
453template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
454template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000455
456template <class C> constexpr auto ssize(const C& c)
Arthur O'Dwyer2fc9b5d2021-04-17 17:03:20 -0400457 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
Marshall Clow3c5363e2019-02-27 02:58:56 +0000458template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
459
Marshall Clowef357272014-11-19 19:43:23 +0000460template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
461template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
462template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
463template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
464template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
465template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
466template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
467
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468} // std
469
470*/
471
472#include <__config>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400473#include <__debug>
Marshall Clow3dc05502014-02-27 02:11:50 +0000474#include <__functional_base>
Louis Dionne463afb82021-04-22 11:05:30 -0400475#include <__iterator/concepts.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400476#include <__iterator/incrementable_traits.h>
Louis Dionneca989a52021-04-20 14:40:43 -0400477#include <__iterator/iter_move.h>
zoecarver5d41ff52021-04-19 14:44:42 -0700478#include <__iterator/iterator_traits.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400479#include <__iterator/readable_traits.h>
Louis Dionne735bc462021-04-14 13:59:03 -0400480#include <__memory/addressof.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500481#include <__memory/pointer_traits.h>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400482#include <compare>
483#include <concepts> // Mandated by the Standard.
484#include <cstddef>
485#include <initializer_list>
486#include <iosfwd> // for forward declarations of vector and string
487#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000488#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000489
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000490#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000492#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493
494_LIBCPP_BEGIN_NAMESPACE_STD
Christopher Di Bella490fe402021-03-23 03:55:52 +0000495
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496template<class _Category, class _Tp, class _Distance = ptrdiff_t,
497 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000498struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499{
500 typedef _Tp value_type;
501 typedef _Distance difference_type;
502 typedef _Pointer pointer;
503 typedef _Reference reference;
504 typedef _Category iterator_category;
505};
506
507template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000508inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509void __advance(_InputIter& __i,
510 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
511{
512 for (; __n > 0; --__n)
513 ++__i;
514}
515
516template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000517inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518void __advance(_BiDirIter& __i,
519 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
520{
521 if (__n >= 0)
522 for (; __n > 0; --__n)
523 ++__i;
524 else
525 for (; __n < 0; ++__n)
526 --__i;
527}
528
529template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000530inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531void __advance(_RandIter& __i,
532 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
533{
534 __i += __n;
535}
536
Louis Dionne45768662020-06-08 16:16:01 -0400537template <class _InputIter, class _Distance>
Marshall Clow75468e72017-05-17 18:51:36 +0000538inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Louis Dionne45768662020-06-08 16:16:01 -0400539void advance(_InputIter& __i, _Distance __orig_n)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540{
Louis Dionne45768662020-06-08 16:16:01 -0400541 _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
542 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500543 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
Louis Dionne45768662020-06-08 16:16:01 -0400544 _IntegralSize __n = __orig_n;
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500545 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546}
547
548template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000549inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550typename iterator_traits<_InputIter>::difference_type
551__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
552{
553 typename iterator_traits<_InputIter>::difference_type __r(0);
554 for (; __first != __last; ++__first)
555 ++__r;
556 return __r;
557}
558
559template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000560inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561typename iterator_traits<_RandIter>::difference_type
562__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
563{
564 return __last - __first;
565}
566
567template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000568inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000569typename iterator_traits<_InputIter>::difference_type
570distance(_InputIter __first, _InputIter __last)
571{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500572 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000573}
574
Marshall Clow990c70d2015-11-07 17:48:49 +0000575template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000576inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000577typename enable_if
578<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500579 __is_cpp17_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000580 _InputIter
581>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000582next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000583 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500585 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400586 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
Marshall Clow3d435212019-03-22 22:32:20 +0000587
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000588 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589 return __x;
590}
591
Marshall Clow3d435212019-03-22 22:32:20 +0000592template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000593inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000594typename enable_if
595<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500596 __is_cpp17_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000597 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000598>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000599prev(_InputIter __x,
600 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500602 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400603 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000604 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605 return __x;
606}
607
Eric Fiselier883af112017-04-13 02:54:13 +0000608
609template <class _Tp, class = void>
610struct __is_stashing_iterator : false_type {};
611
612template <class _Tp>
613struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
614 : true_type {};
615
Howard Hinnantc51e1022010-05-11 19:42:16 +0000616template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000617class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618 : public iterator<typename iterator_traits<_Iter>::iterator_category,
619 typename iterator_traits<_Iter>::value_type,
620 typename iterator_traits<_Iter>::difference_type,
621 typename iterator_traits<_Iter>::pointer,
622 typename iterator_traits<_Iter>::reference>
623{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000624private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000625 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000626
627 static_assert(!__is_stashing_iterator<_Iter>::value,
628 "The specified iterator type cannot be used with reverse_iterator; "
629 "Using stashing iterators with reverse_iterator causes undefined behavior");
630
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000631protected:
632 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633public:
634 typedef _Iter iterator_type;
635 typedef typename iterator_traits<_Iter>::difference_type difference_type;
636 typedef typename iterator_traits<_Iter>::reference reference;
637 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500638 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
639 random_access_iterator_tag,
640 typename iterator_traits<_Iter>::iterator_category> iterator_category;
641#if _LIBCPP_STD_VER > 17
642 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
643 random_access_iterator_tag,
644 bidirectional_iterator_tag> iterator_concept;
645#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000646
Marshall Clow5ace5542016-10-19 15:12:50 +0000647 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
648 reverse_iterator() : __t(), current() {}
649 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
650 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
651 template <class _Up>
652 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
653 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
654 template <class _Up>
655 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
656 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
657 { __t = current = __u.base(); return *this; }
658 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
659 _Iter base() const {return current;}
660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
661 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
663 pointer operator->() const {return _VSTD::addressof(operator*());}
664 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
665 reverse_iterator& operator++() {--current; return *this;}
666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
667 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
668 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
669 reverse_iterator& operator--() {++current; return *this;}
670 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
671 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
672 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
673 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
674 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
675 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
676 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
677 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
678 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
679 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
681 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682};
683
684template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000685inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686bool
687operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
688{
689 return __x.base() == __y.base();
690}
691
692template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000693inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694bool
695operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
696{
697 return __x.base() > __y.base();
698}
699
700template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000701inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702bool
703operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
704{
705 return __x.base() != __y.base();
706}
707
708template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000709inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710bool
711operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
712{
713 return __x.base() < __y.base();
714}
715
716template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000717inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718bool
719operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
720{
721 return __x.base() <= __y.base();
722}
723
724template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000725inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000726bool
727operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
728{
729 return __x.base() >= __y.base();
730}
731
Marshall Clow476d3f42016-07-18 13:19:00 +0000732#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000733template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000734inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000735auto
736operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
737-> decltype(__y.base() - __x.base())
738{
739 return __y.base() - __x.base();
740}
741#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742template <class _Iter1, class _Iter2>
743inline _LIBCPP_INLINE_VISIBILITY
744typename reverse_iterator<_Iter1>::difference_type
745operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
746{
747 return __y.base() - __x.base();
748}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000749#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750
751template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000752inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753reverse_iterator<_Iter>
754operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
755{
756 return reverse_iterator<_Iter>(__x.base() - __n);
757}
758
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000759#if _LIBCPP_STD_VER > 11
760template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000761inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000762reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
763{
764 return reverse_iterator<_Iter>(__i);
765}
766#endif
767
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000769class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770 : public iterator<output_iterator_tag,
771 void,
772 void,
773 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000774 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775{
776protected:
777 _Container* container;
778public:
779 typedef _Container container_type;
780
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500781 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
782 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000783 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000784#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500785 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000786 {container->push_back(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400787#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500788 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
789 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
790 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791};
792
793template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500794inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795back_insert_iterator<_Container>
796back_inserter(_Container& __x)
797{
798 return back_insert_iterator<_Container>(__x);
799}
800
801template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000802class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803 : public iterator<output_iterator_tag,
804 void,
805 void,
806 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000807 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808{
809protected:
810 _Container* container;
811public:
812 typedef _Container container_type;
813
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500814 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
815 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000816 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000817#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500818 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000819 {container->push_front(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400820#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500821 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
822 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
823 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824};
825
826template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500827inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828front_insert_iterator<_Container>
829front_inserter(_Container& __x)
830{
831 return front_insert_iterator<_Container>(__x);
832}
833
834template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000835class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836 : public iterator<output_iterator_tag,
837 void,
838 void,
839 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000840 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841{
842protected:
843 _Container* container;
844 typename _Container::iterator iter;
845public:
846 typedef _Container container_type;
847
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500848 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000849 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500850 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000851 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000852#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500853 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000854 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400855#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500856 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
857 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
858 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859};
860
861template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500862inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863insert_iterator<_Container>
864inserter(_Container& __x, typename _Container::iterator __i)
865{
866 return insert_iterator<_Container>(__x, __i);
867}
868
869template <class _Tp, class _CharT = char,
870 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000871class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
873{
874public:
875 typedef _CharT char_type;
876 typedef _Traits traits_type;
877 typedef basic_istream<_CharT,_Traits> istream_type;
878private:
879 istream_type* __in_stream_;
880 _Tp __value_;
881public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500882 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000883 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884 {
885 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500886 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887 }
888
889 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000890 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
892 {
893 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500894 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895 return *this;
896 }
897 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
898 {istream_iterator __t(*this); ++(*this); return __t;}
899
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000900 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000902 bool
903 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
904 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000906 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000908 bool
909 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
910 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911};
912
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000913template <class _Tp, class _CharT, class _Traits, class _Distance>
914inline _LIBCPP_INLINE_VISIBILITY
915bool
916operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
917 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
918{
919 return __x.__in_stream_ == __y.__in_stream_;
920}
921
922template <class _Tp, class _CharT, class _Traits, class _Distance>
923inline _LIBCPP_INLINE_VISIBILITY
924bool
925operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
926 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
927{
928 return !(__x == __y);
929}
930
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000932class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933 : public iterator<output_iterator_tag, void, void, void, void>
934{
935public:
Louis Dionnea4d79522020-09-11 10:15:56 -0400936 typedef output_iterator_tag iterator_category;
937 typedef void value_type;
938#if _LIBCPP_STD_VER > 17
939 typedef std::ptrdiff_t difference_type;
940#else
941 typedef void difference_type;
942#endif
943 typedef void pointer;
944 typedef void reference;
945 typedef _CharT char_type;
946 typedef _Traits traits_type;
947 typedef basic_ostream<_CharT, _Traits> ostream_type;
948
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949private:
950 ostream_type* __out_stream_;
951 const char_type* __delim_;
952public:
Marshall Clow27a89512016-10-12 16:13:48 +0000953 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500954 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +0000955 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +0000956 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000957 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000958 {
Howard Hinnantbf074022011-10-22 20:59:45 +0000959 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960 if (__delim_)
961 *__out_stream_ << __delim_;
962 return *this;
963 }
964
965 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
966 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
967 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
968};
969
970template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000971class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 : public iterator<input_iterator_tag, _CharT,
973 typename _Traits::off_type, _CharT*,
974 _CharT>
975{
976public:
977 typedef _CharT char_type;
978 typedef _Traits traits_type;
979 typedef typename _Traits::int_type int_type;
980 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
981 typedef basic_istream<_CharT,_Traits> istream_type;
982private:
Howard Hinnant3e57b272012-11-16 22:17:23 +0000983 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984
985 class __proxy
986 {
987 char_type __keep_;
988 streambuf_type* __sbuf_;
989 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
990 : __keep_(__c), __sbuf_(__s) {}
991 friend class istreambuf_iterator;
992 public:
993 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
994 };
995
Howard Hinnant756c69b2010-09-22 16:48:34 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +0000997 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998 {
999 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001000 __sbuf_ = nullptr;
1001 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002 }
1003public:
Bruce Mitchener170d8972020-11-24 12:53:53 -05001004 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001005 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001006 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001007 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001008 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001009 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010 : __sbuf_(__p.__sbuf_) {}
1011
Howard Hinnant28b24882011-12-01 20:21:04 +00001012 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1013 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1015 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001016 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 return *this;
1018 }
1019 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1020 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001021 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022 }
1023
1024 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001025 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001026};
1027
1028template <class _CharT, class _Traits>
1029inline _LIBCPP_INLINE_VISIBILITY
1030bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1031 const istreambuf_iterator<_CharT,_Traits>& __b)
1032 {return __a.equal(__b);}
1033
1034template <class _CharT, class _Traits>
1035inline _LIBCPP_INLINE_VISIBILITY
1036bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1037 const istreambuf_iterator<_CharT,_Traits>& __b)
1038 {return !__a.equal(__b);}
1039
1040template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001041class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 : public iterator<output_iterator_tag, void, void, void, void>
1043{
1044public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001045 typedef output_iterator_tag iterator_category;
1046 typedef void value_type;
1047#if _LIBCPP_STD_VER > 17
1048 typedef std::ptrdiff_t difference_type;
1049#else
1050 typedef void difference_type;
1051#endif
1052 typedef void pointer;
1053 typedef void reference;
1054 typedef _CharT char_type;
1055 typedef _Traits traits_type;
1056 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1057 typedef basic_ostream<_CharT, _Traits> ostream_type;
1058
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059private:
1060 streambuf_type* __sbuf_;
1061public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001062 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001063 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001064 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001065 : __sbuf_(__s) {}
1066 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1067 {
1068 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001069 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070 return *this;
1071 }
1072 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1073 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1074 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001075 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001076
1077 template <class _Ch, class _Tr>
1078 friend
1079 _LIBCPP_HIDDEN
1080 ostreambuf_iterator<_Ch, _Tr>
1081 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1082 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1083 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084};
1085
1086template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001087class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088{
1089private:
1090 _Iter __i;
1091public:
1092 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001093 typedef typename iterator_traits<iterator_type>::value_type value_type;
1094 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001095 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001096 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1097 random_access_iterator_tag,
1098 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1099#if _LIBCPP_STD_VER > 17
1100 typedef input_iterator_tag iterator_concept;
1101#endif
1102
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001103#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001104 typedef typename iterator_traits<iterator_type>::reference __reference;
1105 typedef typename conditional<
1106 is_reference<__reference>::value,
1107 typename remove_reference<__reference>::type&&,
1108 __reference
1109 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110#else
1111 typedef typename iterator_traits<iterator_type>::reference reference;
1112#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001113
Marshall Clowb5f99122016-11-02 15:30:26 +00001114 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1115 move_iterator() : __i() {}
1116 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1117 explicit move_iterator(_Iter __x) : __i(__x) {}
1118 template <class _Up>
1119 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1120 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1121 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001122 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001123 reference operator*() const { return static_cast<reference>(*__i); }
1124 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1125 pointer operator->() const { return __i;}
1126 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1127 move_iterator& operator++() {++__i; return *this;}
1128 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1129 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1130 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1131 move_iterator& operator--() {--__i; return *this;}
1132 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1133 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1134 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1135 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1136 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1137 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1138 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1139 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1140 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1141 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1142 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1143 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144};
1145
1146template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001147inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001148bool
1149operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1150{
1151 return __x.base() == __y.base();
1152}
1153
1154template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001155inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156bool
1157operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1158{
1159 return __x.base() < __y.base();
1160}
1161
1162template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001163inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164bool
1165operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1166{
1167 return __x.base() != __y.base();
1168}
1169
1170template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001171inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172bool
1173operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1174{
1175 return __x.base() > __y.base();
1176}
1177
1178template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001179inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180bool
1181operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1182{
1183 return __x.base() >= __y.base();
1184}
1185
1186template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001187inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188bool
1189operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1190{
1191 return __x.base() <= __y.base();
1192}
1193
Marshall Clow476d3f42016-07-18 13:19:00 +00001194#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001195template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001196inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001197auto
1198operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1199-> decltype(__x.base() - __y.base())
1200{
1201 return __x.base() - __y.base();
1202}
1203#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204template <class _Iter1, class _Iter2>
1205inline _LIBCPP_INLINE_VISIBILITY
1206typename move_iterator<_Iter1>::difference_type
1207operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1208{
1209 return __x.base() - __y.base();
1210}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001211#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001212
1213template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001214inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215move_iterator<_Iter>
1216operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1217{
1218 return move_iterator<_Iter>(__x.base() + __n);
1219}
1220
1221template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001222inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001224make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001225{
1226 return move_iterator<_Iter>(__i);
1227}
1228
1229// __wrap_iter
1230
1231template <class _Iter> class __wrap_iter;
1232
1233template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001234_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001235bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001236operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001237
1238template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001239_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001241operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001242
1243template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001244_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001245bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001246operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247
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
Marshall Clow476d3f42016-07-18 13:19:00 +00001263#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001264template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001265_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001266auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001267operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001268-> decltype(__x.base() - __y.base());
1269#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001271_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001273operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001274#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275
1276template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001277_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001279operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280
Louis Dionne65b433b2019-11-06 12:02:41 +00001281template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1282template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001283template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1284template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286template <class _Iter>
1287class __wrap_iter
1288{
1289public:
1290 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001291 typedef typename iterator_traits<iterator_type>::value_type value_type;
1292 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1293 typedef typename iterator_traits<iterator_type>::pointer pointer;
1294 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001295 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1296#if _LIBCPP_STD_VER > 17
1297 typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1298 contiguous_iterator_tag, iterator_category> iterator_concept;
1299#endif
1300
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301private:
1302 iterator_type __i;
1303public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001304 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001305#if _LIBCPP_STD_VER > 11
1306 : __i{}
1307#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001308 {
Louis Dionneba400782020-10-02 15:02:52 -04001309#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001310 __get_db()->__insert_i(this);
1311#endif
1312 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001313 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1314 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001315 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001316 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001317 {
Louis Dionneba400782020-10-02 15:02:52 -04001318#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001319 __get_db()->__iterator_copy(this, &__u);
1320#endif
1321 }
Louis Dionneba400782020-10-02 15:02:52 -04001322#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001323 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001324 __wrap_iter(const __wrap_iter& __x)
1325 : __i(__x.base())
1326 {
1327 __get_db()->__iterator_copy(this, &__x);
1328 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001329 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001330 __wrap_iter& operator=(const __wrap_iter& __x)
1331 {
1332 if (this != &__x)
1333 {
1334 __get_db()->__iterator_copy(this, &__x);
1335 __i = __x.__i;
1336 }
1337 return *this;
1338 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001339 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001340 ~__wrap_iter()
1341 {
1342 __get_db()->__erase_i(this);
1343 }
1344#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001345 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001346 {
Louis Dionneba400782020-10-02 15:02:52 -04001347#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001348 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1349 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001350#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001351 return *__i;
1352 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001353 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001354 {
Louis Dionneba400782020-10-02 15:02:52 -04001355#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001356 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1357 "Attempted to dereference a non-dereferenceable iterator");
1358#endif
Louis Dionnebbff1f72021-05-04 18:48:16 -04001359 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001360 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001361 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001362 {
Louis Dionneba400782020-10-02 15:02:52 -04001363#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001364 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1365 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001366#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001367 ++__i;
1368 return *this;
1369 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001371 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001372
Eric Fiselier873b8d32019-03-18 21:50:12 +00001373 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001374 {
Louis Dionneba400782020-10-02 15:02:52 -04001375#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001376 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1377 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001378#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001379 --__i;
1380 return *this;
1381 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001382 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001383 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001384 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001385 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001386 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001387 {
Louis Dionneba400782020-10-02 15:02:52 -04001388#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001389 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1390 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001391#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001392 __i += __n;
1393 return *this;
1394 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001395 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001396 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001397 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001398 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001399 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001400 {
Louis Dionneba400782020-10-02 15:02:52 -04001401#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001402 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1403 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001404#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001405 return __i[__n];
1406 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001407
Eric Fiselier873b8d32019-03-18 21:50:12 +00001408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001409
1410private:
Louis Dionneba400782020-10-02 15:02:52 -04001411#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001412 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001413 {
1414 __get_db()->__insert_ic(this, __p);
1415 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001416#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001417 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001418#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419
1420 template <class _Up> friend class __wrap_iter;
1421 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001422 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001423 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424
1425 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001426 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001428 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001429
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001431 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001433 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001434
Howard Hinnantc51e1022010-05-11 19:42:16 +00001435 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001436 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001438 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001439
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001441 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001443 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001444
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001446 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001448 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001449
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001451 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001452 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001453 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001454
Marshall Clow476d3f42016-07-18 13:19:00 +00001455#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001456 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001457 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001458 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001459 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001460 -> decltype(__x.base() - __y.base());
1461#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001463 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001465 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001466#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001467
Howard Hinnantc51e1022010-05-11 19:42:16 +00001468 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001469 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001471 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472};
1473
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001474#if _LIBCPP_STD_VER <= 17
1475template <class _It>
1476struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1477#endif
1478
1479template <class _Iter>
1480_LIBCPP_CONSTEXPR
1481_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1482__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1483 return _VSTD::__to_address(__w.base());
1484}
1485
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001487inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001489operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001490{
1491 return __x.base() == __y.base();
1492}
1493
1494template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001495inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001496bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001497operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498{
Louis Dionneba400782020-10-02 15:02:52 -04001499#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001500 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001501 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001502#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503 return __x.base() < __y.base();
1504}
1505
1506template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001507inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001509operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001510{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001511 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512}
1513
1514template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001515inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001517operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001519 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520}
1521
1522template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001523inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001525operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001527 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528}
1529
1530template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001531inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001533operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001535 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001536}
1537
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001538template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001539inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001540bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001541operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001542{
1543 return !(__x == __y);
1544}
1545
1546template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001547inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001548bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001549operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001550{
1551 return __y < __x;
1552}
1553
1554template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001555inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001556bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001557operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001558{
1559 return !(__x < __y);
1560}
1561
1562template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001563inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001564bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001565operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001566{
1567 return !(__y < __x);
1568}
1569
Marshall Clow476d3f42016-07-18 13:19:00 +00001570#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001571template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001572inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001573auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001574operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001575-> decltype(__x.base() - __y.base())
1576{
Louis Dionneba400782020-10-02 15:02:52 -04001577#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001578 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1579 "Attempted to subtract incompatible iterators");
1580#endif
1581 return __x.base() - __y.base();
1582}
1583#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001585inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001587operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588{
Louis Dionneba400782020-10-02 15:02:52 -04001589#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001590 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001591 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001592#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001593 return __x.base() - __y.base();
1594}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001595#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001596
1597template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001598inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001599__wrap_iter<_Iter>
1600operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001601 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001603 __x += __n;
1604 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605}
1606
Marshall Clow8411ebf2013-12-02 03:24:33 +00001607template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001608_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001609_Tp*
1610begin(_Tp (&__array)[_Np])
1611{
1612 return __array;
1613}
1614
1615template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001616_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001617_Tp*
1618end(_Tp (&__array)[_Np])
1619{
1620 return __array + _Np;
1621}
1622
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001623#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001624
Howard Hinnantc834c512011-11-29 18:15:50 +00001625template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001626_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001627auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001628begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629{
1630 return __c.begin();
1631}
1632
Howard Hinnantc834c512011-11-29 18:15:50 +00001633template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001634_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001636begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637{
1638 return __c.begin();
1639}
1640
Howard Hinnantc834c512011-11-29 18:15:50 +00001641template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001642_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001643auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001644end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001645{
1646 return __c.end();
1647}
1648
Howard Hinnantc834c512011-11-29 18:15:50 +00001649template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001650_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001652end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653{
1654 return __c.end();
1655}
1656
Marshall Clowb278e9c2013-08-30 01:17:07 +00001657#if _LIBCPP_STD_VER > 11
1658
Marshall Clow8411ebf2013-12-02 03:24:33 +00001659template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001660_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001661reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1662{
1663 return reverse_iterator<_Tp*>(__array + _Np);
1664}
1665
1666template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001667_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001668reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1669{
1670 return reverse_iterator<_Tp*>(__array);
1671}
1672
1673template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001674_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001675reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1676{
1677 return reverse_iterator<const _Ep*>(__il.end());
1678}
1679
1680template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001681_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001682reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1683{
1684 return reverse_iterator<const _Ep*>(__il.begin());
1685}
1686
Marshall Clowb278e9c2013-08-30 01:17:07 +00001687template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001688_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001689auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001690{
Marshall Clow3862f532016-08-10 20:04:46 +00001691 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001692}
1693
1694template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001695_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001696auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001697{
Marshall Clow3862f532016-08-10 20:04:46 +00001698 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001699}
1700
1701template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001702_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001703auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1704{
1705 return __c.rbegin();
1706}
1707
1708template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001709_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001710auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1711{
1712 return __c.rbegin();
1713}
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 rend(_Cp& __c) -> decltype(__c.rend())
1718{
1719 return __c.rend();
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 rend(const _Cp& __c) -> decltype(__c.rend())
1725{
1726 return __c.rend();
1727}
1728
1729template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001730_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001731auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001732{
Marshall Clow3862f532016-08-10 20:04:46 +00001733 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001734}
1735
1736template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001737_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001738auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001739{
Marshall Clow3862f532016-08-10 20:04:46 +00001740 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001741}
1742
1743#endif
1744
1745
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001746#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001747
Howard Hinnantc834c512011-11-29 18:15:50 +00001748template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001749_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001750typename _Cp::iterator
1751begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752{
1753 return __c.begin();
1754}
1755
Howard Hinnantc834c512011-11-29 18:15:50 +00001756template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001757_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001758typename _Cp::const_iterator
1759begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001760{
1761 return __c.begin();
1762}
1763
Howard Hinnantc834c512011-11-29 18:15:50 +00001764template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001765_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001766typename _Cp::iterator
1767end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768{
1769 return __c.end();
1770}
1771
Howard Hinnantc834c512011-11-29 18:15:50 +00001772template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001773_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001774typename _Cp::const_iterator
1775end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776{
1777 return __c.end();
1778}
1779
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001780#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001781
Marshall Clowef357272014-11-19 19:43:23 +00001782#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001783
1784// #if _LIBCPP_STD_VER > 11
1785// template <>
1786// struct _LIBCPP_TEMPLATE_VIS plus<void>
1787// {
1788// template <class _T1, class _T2>
1789// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1790// auto operator()(_T1&& __t, _T2&& __u) const
1791// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1792// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1793// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1794// typedef void is_transparent;
1795// };
1796// #endif
1797
Marshall Clowc4b4a342015-02-11 16:14:01 +00001798template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001799_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001800constexpr auto size(const _Cont& __c)
1801_NOEXCEPT_(noexcept(__c.size()))
1802-> decltype (__c.size())
1803{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001804
Marshall Clowc4b4a342015-02-11 16:14:01 +00001805template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001806_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001807constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001808
Marshall Clow3c5363e2019-02-27 02:58:56 +00001809#if _LIBCPP_STD_VER > 17
1810template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001811_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001812constexpr auto ssize(const _Cont& __c)
1813_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1814-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1815{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1816
1817template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001818_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001819constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1820#endif
1821
Marshall Clowc4b4a342015-02-11 16:14:01 +00001822template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001823_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001824constexpr auto empty(const _Cont& __c)
1825_NOEXCEPT_(noexcept(__c.empty()))
1826-> decltype (__c.empty())
1827{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001828
Marshall Clowc4b4a342015-02-11 16:14:01 +00001829template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001830_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001831constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001832
1833template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001834_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001835constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1836
Marshall Clowc4b4a342015-02-11 16:14:01 +00001837template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001838_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001839auto data(_Cont& __c)
1840_NOEXCEPT_(noexcept(__c.data()))
1841-> decltype (__c.data())
1842{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001843
Marshall Clowc4b4a342015-02-11 16:14:01 +00001844template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001845_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001846auto data(const _Cont& __c)
1847_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001848-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001849{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001850
Marshall Clowc4b4a342015-02-11 16:14:01 +00001851template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001852_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001853constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001854
1855template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001856_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001857constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1858#endif
1859
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001860template <class _Container, class _Predicate>
1861typename _Container::size_type
1862__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
1863 typename _Container::size_type __old_size = __c.size();
1864
1865 const typename _Container::iterator __last = __c.end();
1866 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
1867 if (__pred(*__iter))
1868 __iter = __c.erase(__iter);
1869 else
1870 ++__iter;
1871 }
1872
1873 return __old_size - __c.size();
1874}
Marshall Clowef357272014-11-19 19:43:23 +00001875
Howard Hinnantc51e1022010-05-11 19:42:16 +00001876_LIBCPP_END_NAMESPACE_STD
1877
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001878#endif // _LIBCPP_ITERATOR