blob: 918c96d8cbefd889ce1ebd760696ee7a0704be00 [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
Howard Hinnantc51e1022010-05-11 19:42:16 +000078template<class Category, class T, class Distance = ptrdiff_t,
79 class Pointer = T*, class Reference = T&>
80struct iterator
81{
82 typedef T value_type;
83 typedef Distance difference_type;
84 typedef Pointer pointer;
85 typedef Reference reference;
86 typedef Category iterator_category;
87};
88
89struct input_iterator_tag {};
90struct output_iterator_tag {};
91struct forward_iterator_tag : public input_iterator_tag {};
92struct bidirectional_iterator_tag : public forward_iterator_tag {};
93struct random_access_iterator_tag : public bidirectional_iterator_tag {};
94
Marshall Clow75468e72017-05-17 18:51:36 +000095// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -040096template <class InputIterator, class Distance> // constexpr in C++17
97 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +000098
Marshall Clow75468e72017-05-17 18:51:36 +000099template <class InputIterator> // constexpr in C++17
100 constexpr typename iterator_traits<InputIterator>::difference_type
101 distance(InputIterator first, InputIterator last);
102
103template <class InputIterator> // constexpr in C++17
104 constexpr InputIterator next(InputIterator x,
105typename iterator_traits<InputIterator>::difference_type n = 1);
106
107template <class BidirectionalIterator> // constexpr in C++17
108 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +0000109 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110
111template <class Iterator>
112class reverse_iterator
113 : public iterator<typename iterator_traits<Iterator>::iterator_category,
114 typename iterator_traits<Iterator>::value_type,
115 typename iterator_traits<Iterator>::difference_type,
116 typename iterator_traits<Iterator>::pointer,
117 typename iterator_traits<Iterator>::reference>
118{
119protected:
120 Iterator current;
121public:
122 typedef Iterator iterator_type;
123 typedef typename iterator_traits<Iterator>::difference_type difference_type;
124 typedef typename iterator_traits<Iterator>::reference reference;
125 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000126
Marshall Clow5ace5542016-10-19 15:12:50 +0000127 constexpr reverse_iterator();
128 constexpr explicit reverse_iterator(Iterator x);
129 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
130 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
131 constexpr Iterator base() const;
132 constexpr reference operator*() const;
133 constexpr pointer operator->() const;
134 constexpr reverse_iterator& operator++();
135 constexpr reverse_iterator operator++(int);
136 constexpr reverse_iterator& operator--();
137 constexpr reverse_iterator operator--(int);
138 constexpr reverse_iterator operator+ (difference_type n) const;
139 constexpr reverse_iterator& operator+=(difference_type n);
140 constexpr reverse_iterator operator- (difference_type n) const;
141 constexpr reverse_iterator& operator-=(difference_type n);
142 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143};
144
145template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000146constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
148
149template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000150constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
152
153template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000154constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
156
157template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000158constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
160
161template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000162constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
164
165template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000166constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
168
169template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000170constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000171operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000172-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173
174template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000175constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000176operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000177 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178
Marshall Clow5ace5542016-10-19 15:12:50 +0000179template <class Iterator>
180constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000181
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182template <class Container>
183class back_insert_iterator
184{
185protected:
186 Container* container;
187public:
188 typedef Container container_type;
189 typedef void value_type;
190 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000191 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192 typedef void pointer;
193
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500194 explicit back_insert_iterator(Container& x); // constexpr in C++20
195 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
196 back_insert_iterator& operator*(); // constexpr in C++20
197 back_insert_iterator& operator++(); // constexpr in C++20
198 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000199};
200
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500201template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202
203template <class Container>
204class front_insert_iterator
205{
206protected:
207 Container* container;
208public:
209 typedef Container container_type;
210 typedef void value_type;
211 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000212 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213 typedef void pointer;
214
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500215 explicit front_insert_iterator(Container& x); // constexpr in C++20
216 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
217 front_insert_iterator& operator*(); // constexpr in C++20
218 front_insert_iterator& operator++(); // constexpr in C++20
219 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000220};
221
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500222template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000223
224template <class Container>
225class insert_iterator
226{
227protected:
228 Container* container;
229 typename Container::iterator iter;
230public:
231 typedef Container container_type;
232 typedef void value_type;
233 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000234 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235 typedef void pointer;
236
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500237 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
238 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
239 insert_iterator& operator*(); // constexpr in C++20
240 insert_iterator& operator++(); // constexpr in C++20
241 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242};
243
244template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500245insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000247template <class Iterator>
248class move_iterator {
249public:
250 typedef Iterator iterator_type;
251 typedef typename iterator_traits<Iterator>::difference_type difference_type;
252 typedef Iterator pointer;
253 typedef typename iterator_traits<Iterator>::value_type value_type;
254 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
255 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000256
Marshall Clowb5f99122016-11-02 15:30:26 +0000257 constexpr move_iterator(); // all the constexprs are in C++17
258 constexpr explicit move_iterator(Iterator i);
259 template <class U>
260 constexpr move_iterator(const move_iterator<U>& u);
261 template <class U>
262 constexpr move_iterator& operator=(const move_iterator<U>& u);
263 constexpr iterator_type base() const;
264 constexpr reference operator*() const;
265 constexpr pointer operator->() const;
266 constexpr move_iterator& operator++();
267 constexpr move_iterator operator++(int);
268 constexpr move_iterator& operator--();
269 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000270 constexpr move_iterator operator+(difference_type n) const;
271 constexpr move_iterator& operator+=(difference_type n);
272 constexpr move_iterator operator-(difference_type n) const;
273 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000274 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000275private:
276 Iterator current; // exposition only
277};
278
279template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000280constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000281operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
282
283template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000284constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000285operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
286
287template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000288constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000289operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
290
291template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000292constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000293operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
294
295template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000296constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000297operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
298
299template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000300constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000301operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
302
303template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000304constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000305operator-(const move_iterator<Iterator1>& x,
306 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
307
308template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000309constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000310 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000311 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000312
Marshall Clowb5f99122016-11-02 15:30:26 +0000313template <class Iterator> // constexpr in C++17
314constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000315
316
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
318class istream_iterator
319 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
320{
321public:
322 typedef charT char_type;
323 typedef traits traits_type;
324 typedef basic_istream<charT,traits> istream_type;
325
Marshall Clow0735e4e2015-04-16 21:36:54 +0000326 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 istream_iterator(istream_type& s);
328 istream_iterator(const istream_iterator& x);
329 ~istream_iterator();
330
331 const T& operator*() const;
332 const T* operator->() const;
333 istream_iterator& operator++();
334 istream_iterator operator++(int);
335};
336
337template <class T, class charT, class traits, class Distance>
338bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
339 const istream_iterator<T,charT,traits,Distance>& y);
340template <class T, class charT, class traits, class Distance>
341bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
342 const istream_iterator<T,charT,traits,Distance>& y);
343
344template <class T, class charT = char, class traits = char_traits<charT> >
345class ostream_iterator
346 : public iterator<output_iterator_tag, void, void, void ,void>
347{
348public:
349 typedef charT char_type;
350 typedef traits traits_type;
351 typedef basic_ostream<charT,traits> ostream_type;
352
353 ostream_iterator(ostream_type& s);
354 ostream_iterator(ostream_type& s, const charT* delimiter);
355 ostream_iterator(const ostream_iterator& x);
356 ~ostream_iterator();
357 ostream_iterator& operator=(const T& value);
358
359 ostream_iterator& operator*();
360 ostream_iterator& operator++();
361 ostream_iterator& operator++(int);
362};
363
364template<class charT, class traits = char_traits<charT> >
365class istreambuf_iterator
366 : public iterator<input_iterator_tag, charT,
367 typename traits::off_type, unspecified,
368 charT>
369{
370public:
371 typedef charT char_type;
372 typedef traits traits_type;
373 typedef typename traits::int_type int_type;
374 typedef basic_streambuf<charT,traits> streambuf_type;
375 typedef basic_istream<charT,traits> istream_type;
376
Howard Hinnant011138d2012-07-20 19:36:34 +0000377 istreambuf_iterator() noexcept;
378 istreambuf_iterator(istream_type& s) noexcept;
379 istreambuf_iterator(streambuf_type* s) noexcept;
380 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381
382 charT operator*() const;
383 pointer operator->() const;
384 istreambuf_iterator& operator++();
385 a-private-type operator++(int);
386
387 bool equal(const istreambuf_iterator& b) const;
388};
389
390template <class charT, class traits>
391bool operator==(const istreambuf_iterator<charT,traits>& a,
392 const istreambuf_iterator<charT,traits>& b);
393template <class charT, class traits>
394bool operator!=(const istreambuf_iterator<charT,traits>& a,
395 const istreambuf_iterator<charT,traits>& b);
396
397template <class charT, class traits = char_traits<charT> >
398class ostreambuf_iterator
399 : public iterator<output_iterator_tag, void, void, void, void>
400{
401public:
402 typedef charT char_type;
403 typedef traits traits_type;
404 typedef basic_streambuf<charT,traits> streambuf_type;
405 typedef basic_ostream<charT,traits> ostream_type;
406
Howard Hinnant011138d2012-07-20 19:36:34 +0000407 ostreambuf_iterator(ostream_type& s) noexcept;
408 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 ostreambuf_iterator& operator=(charT c);
410 ostreambuf_iterator& operator*();
411 ostreambuf_iterator& operator++();
412 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000413 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414};
415
Marshall Clow99ba0022017-01-04 17:58:17 +0000416template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
417template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
418template <class C> constexpr auto end(C& c) -> decltype(c.end());
419template <class C> constexpr auto end(const C& c) -> decltype(c.end());
420template <class T, size_t N> constexpr T* begin(T (&array)[N]);
421template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422
Marshall Clow99ba0022017-01-04 17:58:17 +0000423template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
424template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
425template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
426template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
427template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
428template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
429template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
430template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
431template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
432template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
433template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
434template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000435
Marshall Clowef357272014-11-19 19:43:23 +0000436// 24.8, container access:
437template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
438template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000439
440template <class C> constexpr auto ssize(const C& c)
Arthur O'Dwyer2fc9b5d2021-04-17 17:03:20 -0400441 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
Marshall Clow3c5363e2019-02-27 02:58:56 +0000442template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
443
Marshall Clowef357272014-11-19 19:43:23 +0000444template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
445template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
446template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
447template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
448template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
449template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
450template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
451
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452} // std
453
454*/
455
456#include <__config>
Eric Fiselier876c6862016-02-20 00:19:45 +0000457#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow3dc05502014-02-27 02:11:50 +0000458#include <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000459#include <type_traits>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400460#include <compare>
zoecarver5d41ff52021-04-19 14:44:42 -0700461#include <concepts> // Mandated by the Standard.
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462#include <cstddef>
Marshall Clowb278e9c2013-08-30 01:17:07 +0000463#include <initializer_list>
Louis Dionne463afb82021-04-22 11:05:30 -0400464#include <__iterator/concepts.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400465#include <__iterator/incrementable_traits.h>
Louis Dionneca989a52021-04-20 14:40:43 -0400466#include <__iterator/iter_move.h>
zoecarver5d41ff52021-04-19 14:44:42 -0700467#include <__iterator/iterator_traits.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400468#include <__iterator/readable_traits.h>
zoecarver11391bc2021-04-26 09:35:47 -0700469#include <__iterator/concepts.h>
Louis Dionne735bc462021-04-14 13:59:03 -0400470#include <__memory/addressof.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500471#include <__memory/pointer_traits.h>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000472#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000473
Eric Fiselier14b6de92014-08-10 23:53:08 +0000474#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000476#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000478#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479
480_LIBCPP_BEGIN_NAMESPACE_STD
Christopher Di Bella490fe402021-03-23 03:55:52 +0000481
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482template<class _Category, class _Tp, class _Distance = ptrdiff_t,
483 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000484struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485{
486 typedef _Tp value_type;
487 typedef _Distance difference_type;
488 typedef _Pointer pointer;
489 typedef _Reference reference;
490 typedef _Category iterator_category;
491};
492
493template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000494inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495void __advance(_InputIter& __i,
496 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
497{
498 for (; __n > 0; --__n)
499 ++__i;
500}
501
502template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000503inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504void __advance(_BiDirIter& __i,
505 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
506{
507 if (__n >= 0)
508 for (; __n > 0; --__n)
509 ++__i;
510 else
511 for (; __n < 0; ++__n)
512 --__i;
513}
514
515template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000516inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517void __advance(_RandIter& __i,
518 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
519{
520 __i += __n;
521}
522
Louis Dionne45768662020-06-08 16:16:01 -0400523template <class _InputIter, class _Distance>
Marshall Clow75468e72017-05-17 18:51:36 +0000524inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Louis Dionne45768662020-06-08 16:16:01 -0400525void advance(_InputIter& __i, _Distance __orig_n)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526{
Louis Dionne45768662020-06-08 16:16:01 -0400527 _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
528 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500529 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
Louis Dionne45768662020-06-08 16:16:01 -0400530 _IntegralSize __n = __orig_n;
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500531 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532}
533
534template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000535inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536typename iterator_traits<_InputIter>::difference_type
537__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
538{
539 typename iterator_traits<_InputIter>::difference_type __r(0);
540 for (; __first != __last; ++__first)
541 ++__r;
542 return __r;
543}
544
545template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000546inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547typename iterator_traits<_RandIter>::difference_type
548__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
549{
550 return __last - __first;
551}
552
553template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000554inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555typename iterator_traits<_InputIter>::difference_type
556distance(_InputIter __first, _InputIter __last)
557{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500558 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559}
560
Marshall Clow990c70d2015-11-07 17:48:49 +0000561template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000562inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000563typename enable_if
564<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500565 __is_cpp17_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000566 _InputIter
567>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000568next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000569 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500571 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400572 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
Marshall Clow3d435212019-03-22 22:32:20 +0000573
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000574 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000575 return __x;
576}
577
Marshall Clow3d435212019-03-22 22:32:20 +0000578template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000579inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000580typename enable_if
581<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500582 __is_cpp17_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000583 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000584>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000585prev(_InputIter __x,
586 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500588 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400589 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000590 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591 return __x;
592}
593
Eric Fiselier883af112017-04-13 02:54:13 +0000594
595template <class _Tp, class = void>
596struct __is_stashing_iterator : false_type {};
597
598template <class _Tp>
599struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
600 : true_type {};
601
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000603class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604 : public iterator<typename iterator_traits<_Iter>::iterator_category,
605 typename iterator_traits<_Iter>::value_type,
606 typename iterator_traits<_Iter>::difference_type,
607 typename iterator_traits<_Iter>::pointer,
608 typename iterator_traits<_Iter>::reference>
609{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000610private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000611 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000612
613 static_assert(!__is_stashing_iterator<_Iter>::value,
614 "The specified iterator type cannot be used with reverse_iterator; "
615 "Using stashing iterators with reverse_iterator causes undefined behavior");
616
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000617protected:
618 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619public:
620 typedef _Iter iterator_type;
621 typedef typename iterator_traits<_Iter>::difference_type difference_type;
622 typedef typename iterator_traits<_Iter>::reference reference;
623 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500624 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
625 random_access_iterator_tag,
626 typename iterator_traits<_Iter>::iterator_category> iterator_category;
627#if _LIBCPP_STD_VER > 17
628 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
629 random_access_iterator_tag,
630 bidirectional_iterator_tag> iterator_concept;
631#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000632
Marshall Clow5ace5542016-10-19 15:12:50 +0000633 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
634 reverse_iterator() : __t(), current() {}
635 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
636 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
637 template <class _Up>
638 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
639 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
640 template <class _Up>
641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
642 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
643 { __t = current = __u.base(); return *this; }
644 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
645 _Iter base() const {return current;}
646 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
647 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
648 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
649 pointer operator->() const {return _VSTD::addressof(operator*());}
650 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
651 reverse_iterator& operator++() {--current; return *this;}
652 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
653 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
654 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
655 reverse_iterator& operator--() {++current; return *this;}
656 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
657 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
658 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
659 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
660 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
661 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
663 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
664 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
665 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
667 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668};
669
670template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000671inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672bool
673operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
674{
675 return __x.base() == __y.base();
676}
677
678template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000679inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680bool
681operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
682{
683 return __x.base() > __y.base();
684}
685
686template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000687inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688bool
689operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
690{
691 return __x.base() != __y.base();
692}
693
694template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000695inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696bool
697operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
698{
699 return __x.base() < __y.base();
700}
701
702template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000703inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704bool
705operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
706{
707 return __x.base() <= __y.base();
708}
709
710template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000711inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712bool
713operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
714{
715 return __x.base() >= __y.base();
716}
717
Marshall Clow476d3f42016-07-18 13:19:00 +0000718#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000719template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000720inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000721auto
722operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
723-> decltype(__y.base() - __x.base())
724{
725 return __y.base() - __x.base();
726}
727#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000728template <class _Iter1, class _Iter2>
729inline _LIBCPP_INLINE_VISIBILITY
730typename reverse_iterator<_Iter1>::difference_type
731operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
732{
733 return __y.base() - __x.base();
734}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000735#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736
737template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000738inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739reverse_iterator<_Iter>
740operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
741{
742 return reverse_iterator<_Iter>(__x.base() - __n);
743}
744
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000745#if _LIBCPP_STD_VER > 11
746template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000747inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000748reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
749{
750 return reverse_iterator<_Iter>(__i);
751}
752#endif
753
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000755class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000756 : public iterator<output_iterator_tag,
757 void,
758 void,
759 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000760 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761{
762protected:
763 _Container* container;
764public:
765 typedef _Container container_type;
766
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500767 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
768 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000769 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000770#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500771 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000772 {container->push_back(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400773#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500774 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
775 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
776 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777};
778
779template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500780inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781back_insert_iterator<_Container>
782back_inserter(_Container& __x)
783{
784 return back_insert_iterator<_Container>(__x);
785}
786
787template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000788class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789 : public iterator<output_iterator_tag,
790 void,
791 void,
792 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000793 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794{
795protected:
796 _Container* container;
797public:
798 typedef _Container container_type;
799
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500800 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
801 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000802 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000803#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500804 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000805 {container->push_front(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400806#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500807 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
808 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
809 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810};
811
812template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500813inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814front_insert_iterator<_Container>
815front_inserter(_Container& __x)
816{
817 return front_insert_iterator<_Container>(__x);
818}
819
820template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000821class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822 : public iterator<output_iterator_tag,
823 void,
824 void,
825 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000826 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827{
828protected:
829 _Container* container;
830 typename _Container::iterator iter;
831public:
832 typedef _Container container_type;
833
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500834 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000835 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500836 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000837 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000838#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500839 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000840 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400841#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500842 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
843 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
844 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845};
846
847template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500848inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849insert_iterator<_Container>
850inserter(_Container& __x, typename _Container::iterator __i)
851{
852 return insert_iterator<_Container>(__x, __i);
853}
854
855template <class _Tp, class _CharT = char,
856 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000857class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
859{
860public:
861 typedef _CharT char_type;
862 typedef _Traits traits_type;
863 typedef basic_istream<_CharT,_Traits> istream_type;
864private:
865 istream_type* __in_stream_;
866 _Tp __value_;
867public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500868 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000869 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000870 {
871 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500872 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873 }
874
875 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000876 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
878 {
879 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500880 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881 return *this;
882 }
883 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
884 {istream_iterator __t(*this); ++(*this); return __t;}
885
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000886 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000888 bool
889 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
890 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000892 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000894 bool
895 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
896 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897};
898
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000899template <class _Tp, class _CharT, class _Traits, class _Distance>
900inline _LIBCPP_INLINE_VISIBILITY
901bool
902operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
903 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
904{
905 return __x.__in_stream_ == __y.__in_stream_;
906}
907
908template <class _Tp, class _CharT, class _Traits, class _Distance>
909inline _LIBCPP_INLINE_VISIBILITY
910bool
911operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
912 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
913{
914 return !(__x == __y);
915}
916
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000918class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919 : public iterator<output_iterator_tag, void, void, void, void>
920{
921public:
Louis Dionnea4d79522020-09-11 10:15:56 -0400922 typedef output_iterator_tag iterator_category;
923 typedef void value_type;
924#if _LIBCPP_STD_VER > 17
925 typedef std::ptrdiff_t difference_type;
926#else
927 typedef void difference_type;
928#endif
929 typedef void pointer;
930 typedef void reference;
931 typedef _CharT char_type;
932 typedef _Traits traits_type;
933 typedef basic_ostream<_CharT, _Traits> ostream_type;
934
Howard Hinnantc51e1022010-05-11 19:42:16 +0000935private:
936 ostream_type* __out_stream_;
937 const char_type* __delim_;
938public:
Marshall Clow27a89512016-10-12 16:13:48 +0000939 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500940 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +0000941 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +0000942 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000943 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944 {
Howard Hinnantbf074022011-10-22 20:59:45 +0000945 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946 if (__delim_)
947 *__out_stream_ << __delim_;
948 return *this;
949 }
950
951 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
952 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
953 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
954};
955
956template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000957class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000958 : public iterator<input_iterator_tag, _CharT,
959 typename _Traits::off_type, _CharT*,
960 _CharT>
961{
962public:
963 typedef _CharT char_type;
964 typedef _Traits traits_type;
965 typedef typename _Traits::int_type int_type;
966 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
967 typedef basic_istream<_CharT,_Traits> istream_type;
968private:
Howard Hinnant3e57b272012-11-16 22:17:23 +0000969 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970
971 class __proxy
972 {
973 char_type __keep_;
974 streambuf_type* __sbuf_;
975 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
976 : __keep_(__c), __sbuf_(__s) {}
977 friend class istreambuf_iterator;
978 public:
979 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
980 };
981
Howard Hinnant756c69b2010-09-22 16:48:34 +0000982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +0000983 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 {
985 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500986 __sbuf_ = nullptr;
987 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988 }
989public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500990 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000991 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +0000992 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000993 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +0000994 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000995 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 : __sbuf_(__p.__sbuf_) {}
997
Howard Hinnant28b24882011-12-01 20:21:04 +0000998 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
999 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1001 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001002 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003 return *this;
1004 }
1005 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1006 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001007 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001008 }
1009
1010 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001011 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012};
1013
1014template <class _CharT, class _Traits>
1015inline _LIBCPP_INLINE_VISIBILITY
1016bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1017 const istreambuf_iterator<_CharT,_Traits>& __b)
1018 {return __a.equal(__b);}
1019
1020template <class _CharT, class _Traits>
1021inline _LIBCPP_INLINE_VISIBILITY
1022bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1023 const istreambuf_iterator<_CharT,_Traits>& __b)
1024 {return !__a.equal(__b);}
1025
1026template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001027class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001028 : public iterator<output_iterator_tag, void, void, void, void>
1029{
1030public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001031 typedef output_iterator_tag iterator_category;
1032 typedef void value_type;
1033#if _LIBCPP_STD_VER > 17
1034 typedef std::ptrdiff_t difference_type;
1035#else
1036 typedef void difference_type;
1037#endif
1038 typedef void pointer;
1039 typedef void reference;
1040 typedef _CharT char_type;
1041 typedef _Traits traits_type;
1042 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1043 typedef basic_ostream<_CharT, _Traits> ostream_type;
1044
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045private:
1046 streambuf_type* __sbuf_;
1047public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001048 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001050 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051 : __sbuf_(__s) {}
1052 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1053 {
1054 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001055 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056 return *this;
1057 }
1058 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1059 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1060 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001061 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001062
1063 template <class _Ch, class _Tr>
1064 friend
1065 _LIBCPP_HIDDEN
1066 ostreambuf_iterator<_Ch, _Tr>
1067 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1068 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1069 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070};
1071
1072template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001073class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074{
1075private:
1076 _Iter __i;
1077public:
1078 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079 typedef typename iterator_traits<iterator_type>::value_type value_type;
1080 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001081 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001082 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1083 random_access_iterator_tag,
1084 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1085#if _LIBCPP_STD_VER > 17
1086 typedef input_iterator_tag iterator_concept;
1087#endif
1088
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001089#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001090 typedef typename iterator_traits<iterator_type>::reference __reference;
1091 typedef typename conditional<
1092 is_reference<__reference>::value,
1093 typename remove_reference<__reference>::type&&,
1094 __reference
1095 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096#else
1097 typedef typename iterator_traits<iterator_type>::reference reference;
1098#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001099
Marshall Clowb5f99122016-11-02 15:30:26 +00001100 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1101 move_iterator() : __i() {}
1102 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1103 explicit move_iterator(_Iter __x) : __i(__x) {}
1104 template <class _Up>
1105 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1106 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1107 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001108 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001109 reference operator*() const { return static_cast<reference>(*__i); }
1110 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1111 pointer operator->() const { return __i;}
1112 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1113 move_iterator& operator++() {++__i; return *this;}
1114 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1115 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1116 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1117 move_iterator& operator--() {--__i; return *this;}
1118 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1119 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1120 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1121 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1122 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1123 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1124 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1125 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1126 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1127 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1128 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1129 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130};
1131
1132template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001133inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134bool
1135operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1136{
1137 return __x.base() == __y.base();
1138}
1139
1140template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001141inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142bool
1143operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1144{
1145 return __x.base() < __y.base();
1146}
1147
1148template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001149inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001150bool
1151operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1152{
1153 return __x.base() != __y.base();
1154}
1155
1156template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001157inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158bool
1159operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1160{
1161 return __x.base() > __y.base();
1162}
1163
1164template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001165inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166bool
1167operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1168{
1169 return __x.base() >= __y.base();
1170}
1171
1172template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001173inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174bool
1175operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1176{
1177 return __x.base() <= __y.base();
1178}
1179
Marshall Clow476d3f42016-07-18 13:19:00 +00001180#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001181template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001182inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001183auto
1184operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1185-> decltype(__x.base() - __y.base())
1186{
1187 return __x.base() - __y.base();
1188}
1189#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190template <class _Iter1, class _Iter2>
1191inline _LIBCPP_INLINE_VISIBILITY
1192typename move_iterator<_Iter1>::difference_type
1193operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1194{
1195 return __x.base() - __y.base();
1196}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001197#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198
1199template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001200inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001201move_iterator<_Iter>
1202operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1203{
1204 return move_iterator<_Iter>(__x.base() + __n);
1205}
1206
1207template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001208inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001210make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001211{
1212 return move_iterator<_Iter>(__i);
1213}
1214
1215// __wrap_iter
1216
1217template <class _Iter> class __wrap_iter;
1218
1219template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001220_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001222operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223
1224template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001225_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001226bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001227operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228
1229template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001230_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001232operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233
1234template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001235_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001236bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001237operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238
1239template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001240_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001241bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001242operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001243
1244template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001245_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001246bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001247operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248
Marshall Clow476d3f42016-07-18 13:19:00 +00001249#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001250template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001251_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001252auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001253operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001254-> decltype(__x.base() - __y.base());
1255#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001256template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001257_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001259operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001260#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001261
1262template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001263_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001265operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266
Louis Dionne65b433b2019-11-06 12:02:41 +00001267template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1268template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001269template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1270template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001271
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272template <class _Iter>
1273class __wrap_iter
1274{
1275public:
1276 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277 typedef typename iterator_traits<iterator_type>::value_type value_type;
1278 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1279 typedef typename iterator_traits<iterator_type>::pointer pointer;
1280 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001281 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1282#if _LIBCPP_STD_VER > 17
1283 typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1284 contiguous_iterator_tag, iterator_category> iterator_concept;
1285#endif
1286
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287private:
1288 iterator_type __i;
1289public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001290 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001291#if _LIBCPP_STD_VER > 11
1292 : __i{}
1293#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001294 {
Louis Dionneba400782020-10-02 15:02:52 -04001295#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001296 __get_db()->__insert_i(this);
1297#endif
1298 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001299 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1300 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001301 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001302 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001303 {
Louis Dionneba400782020-10-02 15:02:52 -04001304#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001305 __get_db()->__iterator_copy(this, &__u);
1306#endif
1307 }
Louis Dionneba400782020-10-02 15:02:52 -04001308#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001309 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001310 __wrap_iter(const __wrap_iter& __x)
1311 : __i(__x.base())
1312 {
1313 __get_db()->__iterator_copy(this, &__x);
1314 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001315 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001316 __wrap_iter& operator=(const __wrap_iter& __x)
1317 {
1318 if (this != &__x)
1319 {
1320 __get_db()->__iterator_copy(this, &__x);
1321 __i = __x.__i;
1322 }
1323 return *this;
1324 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001325 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001326 ~__wrap_iter()
1327 {
1328 __get_db()->__erase_i(this);
1329 }
1330#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001331 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001332 {
Louis Dionneba400782020-10-02 15:02:52 -04001333#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001334 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1335 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001336#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001337 return *__i;
1338 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001339 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001340 {
Louis Dionneba400782020-10-02 15:02:52 -04001341#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001342 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1343 "Attempted to dereference a non-dereferenceable iterator");
1344#endif
Marshall Clowd85a0562016-04-11 03:54:53 +00001345 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001346 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001347 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001348 {
Louis Dionneba400782020-10-02 15:02:52 -04001349#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001350 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1351 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001352#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001353 ++__i;
1354 return *this;
1355 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001356 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001357 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001358
Eric Fiselier873b8d32019-03-18 21:50:12 +00001359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001360 {
Louis Dionneba400782020-10-02 15:02:52 -04001361#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001362 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1363 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001364#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001365 --__i;
1366 return *this;
1367 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001368 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001369 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001371 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001372 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001373 {
Louis Dionneba400782020-10-02 15:02:52 -04001374#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001375 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1376 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001377#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001378 __i += __n;
1379 return *this;
1380 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001381 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001382 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001383 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001384 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001385 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001386 {
Louis Dionneba400782020-10-02 15:02:52 -04001387#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001388 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1389 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001390#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001391 return __i[__n];
1392 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393
Eric Fiselier873b8d32019-03-18 21:50:12 +00001394 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395
1396private:
Louis Dionneba400782020-10-02 15:02:52 -04001397#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001398 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001399 {
1400 __get_db()->__insert_ic(this, __p);
1401 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001402#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001403 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001404#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001405
1406 template <class _Up> friend class __wrap_iter;
1407 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001408 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001409 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001410
1411 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001412 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001414 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001415
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001417 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001418 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001419 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001420
Howard Hinnantc51e1022010-05-11 19:42:16 +00001421 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001422 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001423 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001424 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001425
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001427 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001429 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001430
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001432 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001434 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001435
Howard Hinnantc51e1022010-05-11 19:42:16 +00001436 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001437 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001438 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001439 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001440
Marshall Clow476d3f42016-07-18 13:19:00 +00001441#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001442 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001443 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001444 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001445 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001446 -> decltype(__x.base() - __y.base());
1447#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001448 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001449 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001451 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001452#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001453
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001455 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001457 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458
Louis Dionne65b433b2019-11-06 12:02:41 +00001459 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op);
1460 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001461 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op move(_Ip, _Ip, _Op);
1462 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463};
1464
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001465#if _LIBCPP_STD_VER <= 17
1466template <class _It>
1467struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1468#endif
1469
1470template <class _Iter>
1471_LIBCPP_CONSTEXPR
1472_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1473__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1474 return _VSTD::__to_address(__w.base());
1475}
1476
Howard Hinnantc51e1022010-05-11 19:42:16 +00001477template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001478inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001480operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001481{
1482 return __x.base() == __y.base();
1483}
1484
1485template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001486inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001488operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001489{
Louis Dionneba400782020-10-02 15:02:52 -04001490#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001491 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001492 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001493#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001494 return __x.base() < __y.base();
1495}
1496
1497template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001498inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001499bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001500operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001502 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503}
1504
1505template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001506inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001508operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001510 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511}
1512
1513template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001514inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001515bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001516operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001517{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001518 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001519}
1520
1521template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001522inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001524operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001525{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001526 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001527}
1528
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001529template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001530inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001531bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001532operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001533{
1534 return !(__x == __y);
1535}
1536
1537template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001538inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001539bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001540operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001541{
1542 return __y < __x;
1543}
1544
1545template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001546inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001547bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001548operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001549{
1550 return !(__x < __y);
1551}
1552
1553template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001554inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001555bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001556operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001557{
1558 return !(__y < __x);
1559}
1560
Marshall Clow476d3f42016-07-18 13:19:00 +00001561#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001562template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001563inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001564auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001565operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001566-> decltype(__x.base() - __y.base())
1567{
Louis Dionneba400782020-10-02 15:02:52 -04001568#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001569 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1570 "Attempted to subtract incompatible iterators");
1571#endif
1572 return __x.base() - __y.base();
1573}
1574#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001575template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001576inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001578operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001579{
Louis Dionneba400782020-10-02 15:02:52 -04001580#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001581 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001582 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001583#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584 return __x.base() - __y.base();
1585}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001586#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587
1588template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001589inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590__wrap_iter<_Iter>
1591operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001592 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001593{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001594 __x += __n;
1595 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001596}
1597
Marshall Clow8411ebf2013-12-02 03:24:33 +00001598template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001599_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001600_Tp*
1601begin(_Tp (&__array)[_Np])
1602{
1603 return __array;
1604}
1605
1606template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001607_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001608_Tp*
1609end(_Tp (&__array)[_Np])
1610{
1611 return __array + _Np;
1612}
1613
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001614#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001615
Howard Hinnantc834c512011-11-29 18:15:50 +00001616template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001617_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001619begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620{
1621 return __c.begin();
1622}
1623
Howard Hinnantc834c512011-11-29 18:15:50 +00001624template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001625_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001626auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001627begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001628{
1629 return __c.begin();
1630}
1631
Howard Hinnantc834c512011-11-29 18:15:50 +00001632template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001633_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001634auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001635end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001636{
1637 return __c.end();
1638}
1639
Howard Hinnantc834c512011-11-29 18:15:50 +00001640template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001641_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001643end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644{
1645 return __c.end();
1646}
1647
Marshall Clowb278e9c2013-08-30 01:17:07 +00001648#if _LIBCPP_STD_VER > 11
1649
Marshall Clow8411ebf2013-12-02 03:24:33 +00001650template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001651_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001652reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1653{
1654 return reverse_iterator<_Tp*>(__array + _Np);
1655}
1656
1657template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001658_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001659reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1660{
1661 return reverse_iterator<_Tp*>(__array);
1662}
1663
1664template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001665_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001666reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1667{
1668 return reverse_iterator<const _Ep*>(__il.end());
1669}
1670
1671template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001672_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001673reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1674{
1675 return reverse_iterator<const _Ep*>(__il.begin());
1676}
1677
Marshall Clowb278e9c2013-08-30 01:17:07 +00001678template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001679_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001680auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001681{
Marshall Clow3862f532016-08-10 20:04:46 +00001682 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001683}
1684
1685template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001686_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001687auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001688{
Marshall Clow3862f532016-08-10 20:04:46 +00001689 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001690}
1691
1692template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001693_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001694auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1695{
1696 return __c.rbegin();
1697}
1698
1699template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001700_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001701auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1702{
1703 return __c.rbegin();
1704}
1705
1706template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001707_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001708auto rend(_Cp& __c) -> decltype(__c.rend())
1709{
1710 return __c.rend();
1711}
1712
1713template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001714_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001715auto rend(const _Cp& __c) -> decltype(__c.rend())
1716{
1717 return __c.rend();
1718}
1719
1720template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001721_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001722auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001723{
Marshall Clow3862f532016-08-10 20:04:46 +00001724 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001725}
1726
1727template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001728_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001729auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001730{
Marshall Clow3862f532016-08-10 20:04:46 +00001731 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001732}
1733
1734#endif
1735
1736
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001737#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001738
Howard Hinnantc834c512011-11-29 18:15:50 +00001739template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001740_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001741typename _Cp::iterator
1742begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001743{
1744 return __c.begin();
1745}
1746
Howard Hinnantc834c512011-11-29 18:15:50 +00001747template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001748_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001749typename _Cp::const_iterator
1750begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001751{
1752 return __c.begin();
1753}
1754
Howard Hinnantc834c512011-11-29 18:15:50 +00001755template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001756_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001757typename _Cp::iterator
1758end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001759{
1760 return __c.end();
1761}
1762
Howard Hinnantc834c512011-11-29 18:15:50 +00001763template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001764_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001765typename _Cp::const_iterator
1766end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001767{
1768 return __c.end();
1769}
1770
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001771#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001772
Marshall Clowef357272014-11-19 19:43:23 +00001773#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001774
1775// #if _LIBCPP_STD_VER > 11
1776// template <>
1777// struct _LIBCPP_TEMPLATE_VIS plus<void>
1778// {
1779// template <class _T1, class _T2>
1780// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1781// auto operator()(_T1&& __t, _T2&& __u) const
1782// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1783// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1784// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1785// typedef void is_transparent;
1786// };
1787// #endif
1788
Marshall Clowc4b4a342015-02-11 16:14:01 +00001789template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001790_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001791constexpr auto size(const _Cont& __c)
1792_NOEXCEPT_(noexcept(__c.size()))
1793-> decltype (__c.size())
1794{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001795
Marshall Clowc4b4a342015-02-11 16:14:01 +00001796template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001797_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001798constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001799
Marshall Clow3c5363e2019-02-27 02:58:56 +00001800#if _LIBCPP_STD_VER > 17
1801template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001802_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001803constexpr auto ssize(const _Cont& __c)
1804_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1805-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1806{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1807
1808template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001809_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001810constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1811#endif
1812
Marshall Clowc4b4a342015-02-11 16:14:01 +00001813template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001814_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001815constexpr auto empty(const _Cont& __c)
1816_NOEXCEPT_(noexcept(__c.empty()))
1817-> decltype (__c.empty())
1818{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001819
Marshall Clowc4b4a342015-02-11 16:14:01 +00001820template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001821_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001822constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001823
1824template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001825_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001826constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1827
Marshall Clowc4b4a342015-02-11 16:14:01 +00001828template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001829_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001830auto data(_Cont& __c)
1831_NOEXCEPT_(noexcept(__c.data()))
1832-> decltype (__c.data())
1833{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001834
Marshall Clowc4b4a342015-02-11 16:14:01 +00001835template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001836_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001837auto data(const _Cont& __c)
1838_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001839-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001840{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001841
Marshall Clowc4b4a342015-02-11 16:14:01 +00001842template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001843_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001844constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001845
1846template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001847_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001848constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1849#endif
1850
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001851template <class _Container, class _Predicate>
1852typename _Container::size_type
1853__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
1854 typename _Container::size_type __old_size = __c.size();
1855
1856 const typename _Container::iterator __last = __c.end();
1857 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
1858 if (__pred(*__iter))
1859 __iter = __c.erase(__iter);
1860 else
1861 ++__iter;
1862 }
1863
1864 return __old_size - __c.size();
1865}
Marshall Clowef357272014-11-19 19:43:23 +00001866
Howard Hinnantc51e1022010-05-11 19:42:16 +00001867_LIBCPP_END_NAMESPACE_STD
1868
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001869#endif // _LIBCPP_ITERATOR