blob: f69a135e7a7e8ae2b37ee387adc9bcf468a7a685 [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
Howard Hinnantc51e1022010-05-11 19:42:16 +000055template<class Category, class T, class Distance = ptrdiff_t,
56 class Pointer = T*, class Reference = T&>
57struct iterator
58{
59 typedef T value_type;
60 typedef Distance difference_type;
61 typedef Pointer pointer;
62 typedef Reference reference;
63 typedef Category iterator_category;
64};
65
66struct input_iterator_tag {};
67struct output_iterator_tag {};
68struct forward_iterator_tag : public input_iterator_tag {};
69struct bidirectional_iterator_tag : public forward_iterator_tag {};
70struct random_access_iterator_tag : public bidirectional_iterator_tag {};
71
Marshall Clow75468e72017-05-17 18:51:36 +000072// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -040073template <class InputIterator, class Distance> // constexpr in C++17
74 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +000075
Marshall Clow75468e72017-05-17 18:51:36 +000076template <class InputIterator> // constexpr in C++17
77 constexpr typename iterator_traits<InputIterator>::difference_type
78 distance(InputIterator first, InputIterator last);
79
80template <class InputIterator> // constexpr in C++17
81 constexpr InputIterator next(InputIterator x,
82typename iterator_traits<InputIterator>::difference_type n = 1);
83
84template <class BidirectionalIterator> // constexpr in C++17
85 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +000086 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +000087
88template <class Iterator>
89class reverse_iterator
90 : public iterator<typename iterator_traits<Iterator>::iterator_category,
91 typename iterator_traits<Iterator>::value_type,
92 typename iterator_traits<Iterator>::difference_type,
93 typename iterator_traits<Iterator>::pointer,
94 typename iterator_traits<Iterator>::reference>
95{
96protected:
97 Iterator current;
98public:
99 typedef Iterator iterator_type;
100 typedef typename iterator_traits<Iterator>::difference_type difference_type;
101 typedef typename iterator_traits<Iterator>::reference reference;
102 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000103
Marshall Clow5ace5542016-10-19 15:12:50 +0000104 constexpr reverse_iterator();
105 constexpr explicit reverse_iterator(Iterator x);
106 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
107 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
108 constexpr Iterator base() const;
109 constexpr reference operator*() const;
110 constexpr pointer operator->() const;
111 constexpr reverse_iterator& operator++();
112 constexpr reverse_iterator operator++(int);
113 constexpr reverse_iterator& operator--();
114 constexpr reverse_iterator operator--(int);
115 constexpr reverse_iterator operator+ (difference_type n) const;
116 constexpr reverse_iterator& operator+=(difference_type n);
117 constexpr reverse_iterator operator- (difference_type n) const;
118 constexpr reverse_iterator& operator-=(difference_type n);
119 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120};
121
122template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000123constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000124operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
125
126template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000127constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000128operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
129
130template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000131constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
133
134template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000135constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
137
138template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000139constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
141
142template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000143constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
145
146template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000147constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000148operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000149-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150
151template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000152constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000153operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000154 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155
Marshall Clow5ace5542016-10-19 15:12:50 +0000156template <class Iterator>
157constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000158
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159template <class Container>
160class back_insert_iterator
161{
162protected:
163 Container* container;
164public:
165 typedef Container container_type;
166 typedef void value_type;
167 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000168 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169 typedef void pointer;
170
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500171 explicit back_insert_iterator(Container& x); // constexpr in C++20
172 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
173 back_insert_iterator& operator*(); // constexpr in C++20
174 back_insert_iterator& operator++(); // constexpr in C++20
175 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176};
177
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500178template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179
180template <class Container>
181class front_insert_iterator
182{
183protected:
184 Container* container;
185public:
186 typedef Container container_type;
187 typedef void value_type;
188 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000189 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190 typedef void pointer;
191
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500192 explicit front_insert_iterator(Container& x); // constexpr in C++20
193 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
194 front_insert_iterator& operator*(); // constexpr in C++20
195 front_insert_iterator& operator++(); // constexpr in C++20
196 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000197};
198
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500199template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200
201template <class Container>
202class insert_iterator
203{
204protected:
205 Container* container;
206 typename Container::iterator iter;
207public:
208 typedef Container container_type;
209 typedef void value_type;
210 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000211 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212 typedef void pointer;
213
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500214 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
215 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
216 insert_iterator& operator*(); // constexpr in C++20
217 insert_iterator& operator++(); // constexpr in C++20
218 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219};
220
221template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500222insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000223
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000224template <class Iterator>
225class move_iterator {
226public:
227 typedef Iterator iterator_type;
228 typedef typename iterator_traits<Iterator>::difference_type difference_type;
229 typedef Iterator pointer;
230 typedef typename iterator_traits<Iterator>::value_type value_type;
231 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
232 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000233
Marshall Clowb5f99122016-11-02 15:30:26 +0000234 constexpr move_iterator(); // all the constexprs are in C++17
235 constexpr explicit move_iterator(Iterator i);
236 template <class U>
237 constexpr move_iterator(const move_iterator<U>& u);
238 template <class U>
239 constexpr move_iterator& operator=(const move_iterator<U>& u);
240 constexpr iterator_type base() const;
241 constexpr reference operator*() const;
242 constexpr pointer operator->() const;
243 constexpr move_iterator& operator++();
244 constexpr move_iterator operator++(int);
245 constexpr move_iterator& operator--();
246 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000247 constexpr move_iterator operator+(difference_type n) const;
248 constexpr move_iterator& operator+=(difference_type n);
249 constexpr move_iterator operator-(difference_type n) const;
250 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000251 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000252private:
253 Iterator current; // exposition only
254};
255
256template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000257constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000258operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
259
260template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000261constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000262operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
263
264template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000265constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000266operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
267
268template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000269constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000270operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
271
272template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000273constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000274operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
275
276template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000277constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000278operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
279
280template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000281constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000282operator-(const move_iterator<Iterator1>& x,
283 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
284
285template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000286constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000287 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000288 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000289
Marshall Clowb5f99122016-11-02 15:30:26 +0000290template <class Iterator> // constexpr in C++17
291constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000292
293
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
295class istream_iterator
296 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
297{
298public:
299 typedef charT char_type;
300 typedef traits traits_type;
301 typedef basic_istream<charT,traits> istream_type;
302
Marshall Clow0735e4e2015-04-16 21:36:54 +0000303 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304 istream_iterator(istream_type& s);
305 istream_iterator(const istream_iterator& x);
306 ~istream_iterator();
307
308 const T& operator*() const;
309 const T* operator->() const;
310 istream_iterator& operator++();
311 istream_iterator operator++(int);
312};
313
314template <class T, class charT, class traits, class Distance>
315bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
316 const istream_iterator<T,charT,traits,Distance>& y);
317template <class T, class charT, class traits, class Distance>
318bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
319 const istream_iterator<T,charT,traits,Distance>& y);
320
321template <class T, class charT = char, class traits = char_traits<charT> >
322class ostream_iterator
323 : public iterator<output_iterator_tag, void, void, void ,void>
324{
325public:
326 typedef charT char_type;
327 typedef traits traits_type;
328 typedef basic_ostream<charT,traits> ostream_type;
329
330 ostream_iterator(ostream_type& s);
331 ostream_iterator(ostream_type& s, const charT* delimiter);
332 ostream_iterator(const ostream_iterator& x);
333 ~ostream_iterator();
334 ostream_iterator& operator=(const T& value);
335
336 ostream_iterator& operator*();
337 ostream_iterator& operator++();
338 ostream_iterator& operator++(int);
339};
340
341template<class charT, class traits = char_traits<charT> >
342class istreambuf_iterator
343 : public iterator<input_iterator_tag, charT,
344 typename traits::off_type, unspecified,
345 charT>
346{
347public:
348 typedef charT char_type;
349 typedef traits traits_type;
350 typedef typename traits::int_type int_type;
351 typedef basic_streambuf<charT,traits> streambuf_type;
352 typedef basic_istream<charT,traits> istream_type;
353
Howard Hinnant011138d2012-07-20 19:36:34 +0000354 istreambuf_iterator() noexcept;
355 istreambuf_iterator(istream_type& s) noexcept;
356 istreambuf_iterator(streambuf_type* s) noexcept;
357 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358
359 charT operator*() const;
360 pointer operator->() const;
361 istreambuf_iterator& operator++();
362 a-private-type operator++(int);
363
364 bool equal(const istreambuf_iterator& b) const;
365};
366
367template <class charT, class traits>
368bool operator==(const istreambuf_iterator<charT,traits>& a,
369 const istreambuf_iterator<charT,traits>& b);
370template <class charT, class traits>
371bool operator!=(const istreambuf_iterator<charT,traits>& a,
372 const istreambuf_iterator<charT,traits>& b);
373
374template <class charT, class traits = char_traits<charT> >
375class ostreambuf_iterator
376 : public iterator<output_iterator_tag, void, void, void, void>
377{
378public:
379 typedef charT char_type;
380 typedef traits traits_type;
381 typedef basic_streambuf<charT,traits> streambuf_type;
382 typedef basic_ostream<charT,traits> ostream_type;
383
Howard Hinnant011138d2012-07-20 19:36:34 +0000384 ostreambuf_iterator(ostream_type& s) noexcept;
385 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386 ostreambuf_iterator& operator=(charT c);
387 ostreambuf_iterator& operator*();
388 ostreambuf_iterator& operator++();
389 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000390 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391};
392
Marshall Clow99ba0022017-01-04 17:58:17 +0000393template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
394template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
395template <class C> constexpr auto end(C& c) -> decltype(c.end());
396template <class C> constexpr auto end(const C& c) -> decltype(c.end());
397template <class T, size_t N> constexpr T* begin(T (&array)[N]);
398template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399
Marshall Clow99ba0022017-01-04 17:58:17 +0000400template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
401template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
402template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
403template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
404template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
405template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
406template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
407template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
408template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
409template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
410template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
411template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000412
Marshall Clowef357272014-11-19 19:43:23 +0000413// 24.8, container access:
414template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
415template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000416
417template <class C> constexpr auto ssize(const C& c)
Arthur O'Dwyer2fc9b5d2021-04-17 17:03:20 -0400418 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
Marshall Clow3c5363e2019-02-27 02:58:56 +0000419template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
420
Marshall Clowef357272014-11-19 19:43:23 +0000421template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
422template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
423template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
424template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
425template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
426template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
427template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
428
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429} // std
430
431*/
432
433#include <__config>
Eric Fiselier876c6862016-02-20 00:19:45 +0000434#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow3dc05502014-02-27 02:11:50 +0000435#include <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436#include <type_traits>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400437#include <compare>
zoecarver5d41ff52021-04-19 14:44:42 -0700438#include <concepts> // Mandated by the Standard.
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439#include <cstddef>
Marshall Clowb278e9c2013-08-30 01:17:07 +0000440#include <initializer_list>
Louis Dionne463afb82021-04-22 11:05:30 -0400441#include <__iterator/concepts.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400442#include <__iterator/incrementable_traits.h>
Louis Dionneca989a52021-04-20 14:40:43 -0400443#include <__iterator/iter_move.h>
zoecarver5d41ff52021-04-19 14:44:42 -0700444#include <__iterator/iterator_traits.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400445#include <__iterator/readable_traits.h>
Louis Dionne735bc462021-04-14 13:59:03 -0400446#include <__memory/addressof.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500447#include <__memory/pointer_traits.h>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000448#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000449
Eric Fiselier14b6de92014-08-10 23:53:08 +0000450#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000452#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000453#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000454#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455
456_LIBCPP_BEGIN_NAMESPACE_STD
Christopher Di Bella490fe402021-03-23 03:55:52 +0000457
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458template<class _Category, class _Tp, class _Distance = ptrdiff_t,
459 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000460struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461{
462 typedef _Tp value_type;
463 typedef _Distance difference_type;
464 typedef _Pointer pointer;
465 typedef _Reference reference;
466 typedef _Category iterator_category;
467};
468
469template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000470inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471void __advance(_InputIter& __i,
472 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
473{
474 for (; __n > 0; --__n)
475 ++__i;
476}
477
478template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000479inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480void __advance(_BiDirIter& __i,
481 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
482{
483 if (__n >= 0)
484 for (; __n > 0; --__n)
485 ++__i;
486 else
487 for (; __n < 0; ++__n)
488 --__i;
489}
490
491template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000492inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493void __advance(_RandIter& __i,
494 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
495{
496 __i += __n;
497}
498
Louis Dionne45768662020-06-08 16:16:01 -0400499template <class _InputIter, class _Distance>
Marshall Clow75468e72017-05-17 18:51:36 +0000500inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Louis Dionne45768662020-06-08 16:16:01 -0400501void advance(_InputIter& __i, _Distance __orig_n)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502{
Louis Dionne45768662020-06-08 16:16:01 -0400503 _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
504 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500505 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
Louis Dionne45768662020-06-08 16:16:01 -0400506 _IntegralSize __n = __orig_n;
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500507 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508}
509
510template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000511inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512typename iterator_traits<_InputIter>::difference_type
513__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
514{
515 typename iterator_traits<_InputIter>::difference_type __r(0);
516 for (; __first != __last; ++__first)
517 ++__r;
518 return __r;
519}
520
521template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000522inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523typename iterator_traits<_RandIter>::difference_type
524__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
525{
526 return __last - __first;
527}
528
529template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000530inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531typename iterator_traits<_InputIter>::difference_type
532distance(_InputIter __first, _InputIter __last)
533{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500534 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000535}
536
Marshall Clow990c70d2015-11-07 17:48:49 +0000537template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000538inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000539typename enable_if
540<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500541 __is_cpp17_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000542 _InputIter
543>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000544next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000545 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500547 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400548 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
Marshall Clow3d435212019-03-22 22:32:20 +0000549
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000550 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551 return __x;
552}
553
Marshall Clow3d435212019-03-22 22:32:20 +0000554template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000555inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000556typename enable_if
557<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500558 __is_cpp17_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000559 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000560>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000561prev(_InputIter __x,
562 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500564 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400565 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000566 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 return __x;
568}
569
Eric Fiselier883af112017-04-13 02:54:13 +0000570
571template <class _Tp, class = void>
572struct __is_stashing_iterator : false_type {};
573
574template <class _Tp>
575struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
576 : true_type {};
577
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000579class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 : public iterator<typename iterator_traits<_Iter>::iterator_category,
581 typename iterator_traits<_Iter>::value_type,
582 typename iterator_traits<_Iter>::difference_type,
583 typename iterator_traits<_Iter>::pointer,
584 typename iterator_traits<_Iter>::reference>
585{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000586private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000587 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000588
589 static_assert(!__is_stashing_iterator<_Iter>::value,
590 "The specified iterator type cannot be used with reverse_iterator; "
591 "Using stashing iterators with reverse_iterator causes undefined behavior");
592
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000593protected:
594 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595public:
596 typedef _Iter iterator_type;
597 typedef typename iterator_traits<_Iter>::difference_type difference_type;
598 typedef typename iterator_traits<_Iter>::reference reference;
599 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500600 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
601 random_access_iterator_tag,
602 typename iterator_traits<_Iter>::iterator_category> iterator_category;
603#if _LIBCPP_STD_VER > 17
604 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
605 random_access_iterator_tag,
606 bidirectional_iterator_tag> iterator_concept;
607#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000608
Marshall Clow5ace5542016-10-19 15:12:50 +0000609 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
610 reverse_iterator() : __t(), current() {}
611 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
612 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
613 template <class _Up>
614 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
615 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
616 template <class _Up>
617 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
618 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
619 { __t = current = __u.base(); return *this; }
620 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
621 _Iter base() const {return current;}
622 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
623 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
624 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
625 pointer operator->() const {return _VSTD::addressof(operator*());}
626 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
627 reverse_iterator& operator++() {--current; return *this;}
628 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
629 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
630 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
631 reverse_iterator& operator--() {++current; return *this;}
632 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
633 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
634 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
635 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
636 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
637 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
638 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
639 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
640 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
641 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
642 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
643 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644};
645
646template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000647inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648bool
649operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
650{
651 return __x.base() == __y.base();
652}
653
654template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000655inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656bool
657operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
658{
659 return __x.base() > __y.base();
660}
661
662template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000663inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664bool
665operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
666{
667 return __x.base() != __y.base();
668}
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
Marshall Clow476d3f42016-07-18 13:19:00 +0000694#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000695template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000696inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000697auto
698operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
699-> decltype(__y.base() - __x.base())
700{
701 return __y.base() - __x.base();
702}
703#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704template <class _Iter1, class _Iter2>
705inline _LIBCPP_INLINE_VISIBILITY
706typename reverse_iterator<_Iter1>::difference_type
707operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
708{
709 return __y.base() - __x.base();
710}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000711#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712
713template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000714inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000715reverse_iterator<_Iter>
716operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
717{
718 return reverse_iterator<_Iter>(__x.base() - __n);
719}
720
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000721#if _LIBCPP_STD_VER > 11
722template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000723inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000724reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
725{
726 return reverse_iterator<_Iter>(__i);
727}
728#endif
729
Howard Hinnantc51e1022010-05-11 19:42:16 +0000730template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000731class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732 : public iterator<output_iterator_tag,
733 void,
734 void,
735 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000736 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737{
738protected:
739 _Container* container;
740public:
741 typedef _Container container_type;
742
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500743 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
744 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000745 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000746#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500747 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000748 {container->push_back(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400749#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500750 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
751 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
752 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753};
754
755template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500756inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757back_insert_iterator<_Container>
758back_inserter(_Container& __x)
759{
760 return back_insert_iterator<_Container>(__x);
761}
762
763template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000764class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765 : public iterator<output_iterator_tag,
766 void,
767 void,
768 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000769 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770{
771protected:
772 _Container* container;
773public:
774 typedef _Container container_type;
775
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500776 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
777 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000778 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000779#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500780 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000781 {container->push_front(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400782#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500783 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
784 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
785 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000786};
787
788template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500789inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790front_insert_iterator<_Container>
791front_inserter(_Container& __x)
792{
793 return front_insert_iterator<_Container>(__x);
794}
795
796template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000797class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798 : public iterator<output_iterator_tag,
799 void,
800 void,
801 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000802 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803{
804protected:
805 _Container* container;
806 typename _Container::iterator iter;
807public:
808 typedef _Container container_type;
809
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500810 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000811 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500812 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000813 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000814#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500815 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000816 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400817#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500818 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
819 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
820 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000821};
822
823template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500824inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825insert_iterator<_Container>
826inserter(_Container& __x, typename _Container::iterator __i)
827{
828 return insert_iterator<_Container>(__x, __i);
829}
830
831template <class _Tp, class _CharT = char,
832 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000833class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
835{
836public:
837 typedef _CharT char_type;
838 typedef _Traits traits_type;
839 typedef basic_istream<_CharT,_Traits> istream_type;
840private:
841 istream_type* __in_stream_;
842 _Tp __value_;
843public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500844 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000845 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846 {
847 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500848 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849 }
850
851 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000852 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
854 {
855 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500856 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 return *this;
858 }
859 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
860 {istream_iterator __t(*this); ++(*this); return __t;}
861
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000862 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000864 bool
865 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
866 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000868 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000870 bool
871 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
872 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873};
874
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000875template <class _Tp, class _CharT, class _Traits, class _Distance>
876inline _LIBCPP_INLINE_VISIBILITY
877bool
878operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
879 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
880{
881 return __x.__in_stream_ == __y.__in_stream_;
882}
883
884template <class _Tp, class _CharT, class _Traits, class _Distance>
885inline _LIBCPP_INLINE_VISIBILITY
886bool
887operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
888 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
889{
890 return !(__x == __y);
891}
892
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000894class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895 : public iterator<output_iterator_tag, void, void, void, void>
896{
897public:
Louis Dionnea4d79522020-09-11 10:15:56 -0400898 typedef output_iterator_tag iterator_category;
899 typedef void value_type;
900#if _LIBCPP_STD_VER > 17
901 typedef std::ptrdiff_t difference_type;
902#else
903 typedef void difference_type;
904#endif
905 typedef void pointer;
906 typedef void reference;
907 typedef _CharT char_type;
908 typedef _Traits traits_type;
909 typedef basic_ostream<_CharT, _Traits> ostream_type;
910
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911private:
912 ostream_type* __out_stream_;
913 const char_type* __delim_;
914public:
Marshall Clow27a89512016-10-12 16:13:48 +0000915 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500916 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +0000917 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +0000918 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000919 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920 {
Howard Hinnantbf074022011-10-22 20:59:45 +0000921 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922 if (__delim_)
923 *__out_stream_ << __delim_;
924 return *this;
925 }
926
927 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
928 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
929 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
930};
931
932template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000933class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934 : public iterator<input_iterator_tag, _CharT,
935 typename _Traits::off_type, _CharT*,
936 _CharT>
937{
938public:
939 typedef _CharT char_type;
940 typedef _Traits traits_type;
941 typedef typename _Traits::int_type int_type;
942 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
943 typedef basic_istream<_CharT,_Traits> istream_type;
944private:
Howard Hinnant3e57b272012-11-16 22:17:23 +0000945 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946
947 class __proxy
948 {
949 char_type __keep_;
950 streambuf_type* __sbuf_;
951 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
952 : __keep_(__c), __sbuf_(__s) {}
953 friend class istreambuf_iterator;
954 public:
955 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
956 };
957
Howard Hinnant756c69b2010-09-22 16:48:34 +0000958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +0000959 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960 {
961 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500962 __sbuf_ = nullptr;
963 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964 }
965public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500966 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000967 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +0000968 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000969 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +0000970 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000971 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 : __sbuf_(__p.__sbuf_) {}
973
Howard Hinnant28b24882011-12-01 20:21:04 +0000974 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
975 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
977 {
Howard Hinnant3e57b272012-11-16 22:17:23 +0000978 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979 return *this;
980 }
981 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
982 {
Howard Hinnant3e57b272012-11-16 22:17:23 +0000983 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 }
985
986 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +0000987 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988};
989
990template <class _CharT, class _Traits>
991inline _LIBCPP_INLINE_VISIBILITY
992bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
993 const istreambuf_iterator<_CharT,_Traits>& __b)
994 {return __a.equal(__b);}
995
996template <class _CharT, class _Traits>
997inline _LIBCPP_INLINE_VISIBILITY
998bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
999 const istreambuf_iterator<_CharT,_Traits>& __b)
1000 {return !__a.equal(__b);}
1001
1002template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001003class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004 : public iterator<output_iterator_tag, void, void, void, void>
1005{
1006public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001007 typedef output_iterator_tag iterator_category;
1008 typedef void value_type;
1009#if _LIBCPP_STD_VER > 17
1010 typedef std::ptrdiff_t difference_type;
1011#else
1012 typedef void difference_type;
1013#endif
1014 typedef void pointer;
1015 typedef void reference;
1016 typedef _CharT char_type;
1017 typedef _Traits traits_type;
1018 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1019 typedef basic_ostream<_CharT, _Traits> ostream_type;
1020
Howard Hinnantc51e1022010-05-11 19:42:16 +00001021private:
1022 streambuf_type* __sbuf_;
1023public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001024 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001026 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027 : __sbuf_(__s) {}
1028 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1029 {
1030 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001031 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 return *this;
1033 }
1034 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1035 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1036 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001037 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001038
1039 template <class _Ch, class _Tr>
1040 friend
1041 _LIBCPP_HIDDEN
1042 ostreambuf_iterator<_Ch, _Tr>
1043 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1044 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1045 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046};
1047
1048template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001049class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050{
1051private:
1052 _Iter __i;
1053public:
1054 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055 typedef typename iterator_traits<iterator_type>::value_type value_type;
1056 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001057 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001058 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1059 random_access_iterator_tag,
1060 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1061#if _LIBCPP_STD_VER > 17
1062 typedef input_iterator_tag iterator_concept;
1063#endif
1064
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001065#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001066 typedef typename iterator_traits<iterator_type>::reference __reference;
1067 typedef typename conditional<
1068 is_reference<__reference>::value,
1069 typename remove_reference<__reference>::type&&,
1070 __reference
1071 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001072#else
1073 typedef typename iterator_traits<iterator_type>::reference reference;
1074#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001075
Marshall Clowb5f99122016-11-02 15:30:26 +00001076 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1077 move_iterator() : __i() {}
1078 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1079 explicit move_iterator(_Iter __x) : __i(__x) {}
1080 template <class _Up>
1081 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1082 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1083 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001084 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001085 reference operator*() const { return static_cast<reference>(*__i); }
1086 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1087 pointer operator->() const { return __i;}
1088 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1089 move_iterator& operator++() {++__i; return *this;}
1090 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1091 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1092 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1093 move_iterator& operator--() {--__i; return *this;}
1094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1095 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1096 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1097 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1098 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1099 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1100 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1101 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1102 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1103 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1104 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1105 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001106};
1107
1108template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001109inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110bool
1111operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1112{
1113 return __x.base() == __y.base();
1114}
1115
1116template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001117inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001118bool
1119operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1120{
1121 return __x.base() < __y.base();
1122}
1123
1124template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001125inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126bool
1127operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1128{
1129 return __x.base() != __y.base();
1130}
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
Marshall Clow476d3f42016-07-18 13:19:00 +00001156#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001157template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001158inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001159auto
1160operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1161-> decltype(__x.base() - __y.base())
1162{
1163 return __x.base() - __y.base();
1164}
1165#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166template <class _Iter1, class _Iter2>
1167inline _LIBCPP_INLINE_VISIBILITY
1168typename move_iterator<_Iter1>::difference_type
1169operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1170{
1171 return __x.base() - __y.base();
1172}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001173#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174
1175template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001176inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001177move_iterator<_Iter>
1178operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1179{
1180 return move_iterator<_Iter>(__x.base() + __n);
1181}
1182
1183template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001184inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001186make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001187{
1188 return move_iterator<_Iter>(__i);
1189}
1190
1191// __wrap_iter
1192
1193template <class _Iter> class __wrap_iter;
1194
1195template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001196_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001197bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001198operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199
1200template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001201_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001202bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001203operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204
1205template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001206_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001207bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001208operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209
1210template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001211_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001212bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001213operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001214
1215template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001216_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001217bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001218operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219
1220template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001221_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001222bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001223operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224
Marshall Clow476d3f42016-07-18 13:19:00 +00001225#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001226template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001227_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001228auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001229operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001230-> decltype(__x.base() - __y.base());
1231#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001233_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001235operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001236#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001237
1238template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001239_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001241operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001242
Louis Dionne65b433b2019-11-06 12:02:41 +00001243template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1244template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001245template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1246template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248template <class _Iter>
1249class __wrap_iter
1250{
1251public:
1252 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253 typedef typename iterator_traits<iterator_type>::value_type value_type;
1254 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1255 typedef typename iterator_traits<iterator_type>::pointer pointer;
1256 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001257 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1258#if _LIBCPP_STD_VER > 17
1259 typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1260 contiguous_iterator_tag, iterator_category> iterator_concept;
1261#endif
1262
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263private:
1264 iterator_type __i;
1265public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001266 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001267#if _LIBCPP_STD_VER > 11
1268 : __i{}
1269#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001270 {
Louis Dionneba400782020-10-02 15:02:52 -04001271#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001272 __get_db()->__insert_i(this);
1273#endif
1274 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001275 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1276 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001277 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001278 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001279 {
Louis Dionneba400782020-10-02 15:02:52 -04001280#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001281 __get_db()->__iterator_copy(this, &__u);
1282#endif
1283 }
Louis Dionneba400782020-10-02 15:02:52 -04001284#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001286 __wrap_iter(const __wrap_iter& __x)
1287 : __i(__x.base())
1288 {
1289 __get_db()->__iterator_copy(this, &__x);
1290 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001292 __wrap_iter& operator=(const __wrap_iter& __x)
1293 {
1294 if (this != &__x)
1295 {
1296 __get_db()->__iterator_copy(this, &__x);
1297 __i = __x.__i;
1298 }
1299 return *this;
1300 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001301 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001302 ~__wrap_iter()
1303 {
1304 __get_db()->__erase_i(this);
1305 }
1306#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001307 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001308 {
Louis Dionneba400782020-10-02 15:02:52 -04001309#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001310 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1311 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001312#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001313 return *__i;
1314 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001315 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001316 {
Louis Dionneba400782020-10-02 15:02:52 -04001317#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001318 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1319 "Attempted to dereference a non-dereferenceable iterator");
1320#endif
Marshall Clowd85a0562016-04-11 03:54:53 +00001321 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001322 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001323 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001324 {
Louis Dionneba400782020-10-02 15:02:52 -04001325#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001326 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1327 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001328#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001329 ++__i;
1330 return *this;
1331 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001332 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001333 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001334
Eric Fiselier873b8d32019-03-18 21:50:12 +00001335 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001336 {
Louis Dionneba400782020-10-02 15:02:52 -04001337#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001338 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1339 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001340#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001341 --__i;
1342 return *this;
1343 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001344 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001345 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001346 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001347 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001348 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001349 {
Louis Dionneba400782020-10-02 15:02:52 -04001350#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001351 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1352 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001353#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001354 __i += __n;
1355 return *this;
1356 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001357 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001358 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001360 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001361 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001362 {
Louis Dionneba400782020-10-02 15:02:52 -04001363#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001364 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1365 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001366#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001367 return __i[__n];
1368 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369
Eric Fiselier873b8d32019-03-18 21:50:12 +00001370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371
1372private:
Louis Dionneba400782020-10-02 15:02:52 -04001373#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001375 {
1376 __get_db()->__insert_ic(this, __p);
1377 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001378#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001379 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001380#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381
1382 template <class _Up> friend class __wrap_iter;
1383 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001384 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001385 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001386
1387 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001388 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001390 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001391
Howard Hinnantc51e1022010-05-11 19:42:16 +00001392 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001393 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001395 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001396
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001398 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001400 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001401
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001403 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001404 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001405 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001406
Howard Hinnantc51e1022010-05-11 19:42:16 +00001407 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001408 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001409 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001410 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001411
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001413 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001415 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001416
Marshall Clow476d3f42016-07-18 13:19:00 +00001417#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001418 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001419 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001420 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001421 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001422 -> decltype(__x.base() - __y.base());
1423#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001425 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001427 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001428#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001429
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001431 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001433 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434
Louis Dionne65b433b2019-11-06 12:02:41 +00001435 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op);
1436 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001437 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op move(_Ip, _Ip, _Op);
1438 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001439};
1440
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001441#if _LIBCPP_STD_VER <= 17
1442template <class _It>
1443struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1444#endif
1445
1446template <class _Iter>
1447_LIBCPP_CONSTEXPR
1448_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1449__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1450 return _VSTD::__to_address(__w.base());
1451}
1452
Howard Hinnantc51e1022010-05-11 19:42:16 +00001453template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001454inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001456operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457{
1458 return __x.base() == __y.base();
1459}
1460
1461template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001462inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001464operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001465{
Louis Dionneba400782020-10-02 15:02:52 -04001466#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001467 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001468 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001469#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470 return __x.base() < __y.base();
1471}
1472
1473template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001474inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001476operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001477{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001478 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479}
1480
1481template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001482inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001483bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001484operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001486 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487}
1488
1489template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001490inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001492operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001494 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001495}
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 !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503}
1504
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001505template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001506inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001507bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001508operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001509{
1510 return !(__x == __y);
1511}
1512
1513template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001514inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001515bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001516operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001517{
1518 return __y < __x;
1519}
1520
1521template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001522inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001523bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001524operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001525{
1526 return !(__x < __y);
1527}
1528
1529template <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 !(__y < __x);
1535}
1536
Marshall Clow476d3f42016-07-18 13:19:00 +00001537#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001538template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001539inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001540auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001541operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001542-> decltype(__x.base() - __y.base())
1543{
Louis Dionneba400782020-10-02 15:02:52 -04001544#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001545 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1546 "Attempted to subtract incompatible iterators");
1547#endif
1548 return __x.base() - __y.base();
1549}
1550#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001552inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001553typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001554operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555{
Louis Dionneba400782020-10-02 15:02:52 -04001556#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001557 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001558 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001559#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560 return __x.base() - __y.base();
1561}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001562#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563
1564template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001565inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001566__wrap_iter<_Iter>
1567operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001568 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001570 __x += __n;
1571 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001572}
1573
Marshall Clow039b2f02016-01-13 21:54:34 +00001574template <class _Iter>
1575struct __libcpp_is_trivial_iterator
Marshall Clowb5f99122016-11-02 15:30:26 +00001576 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
Louis Dionne173f29e2019-05-29 16:01:36 +00001577
Marshall Clow039b2f02016-01-13 21:54:34 +00001578template <class _Iter>
1579struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001580 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001581
1582template <class _Iter>
1583struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001584 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001585
1586template <class _Iter>
1587struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001588 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001589
1590
Marshall Clow8411ebf2013-12-02 03:24:33 +00001591template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001592_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001593_Tp*
1594begin(_Tp (&__array)[_Np])
1595{
1596 return __array;
1597}
1598
1599template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001600_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001601_Tp*
1602end(_Tp (&__array)[_Np])
1603{
1604 return __array + _Np;
1605}
1606
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001607#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001608
Howard Hinnantc834c512011-11-29 18:15:50 +00001609template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001610_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001611auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001612begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613{
1614 return __c.begin();
1615}
1616
Howard Hinnantc834c512011-11-29 18:15:50 +00001617template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001618_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001620begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001621{
1622 return __c.begin();
1623}
1624
Howard Hinnantc834c512011-11-29 18:15:50 +00001625template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001626_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001627auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001628end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629{
1630 return __c.end();
1631}
1632
Howard Hinnantc834c512011-11-29 18:15:50 +00001633template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001634_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001636end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637{
1638 return __c.end();
1639}
1640
Marshall Clowb278e9c2013-08-30 01:17:07 +00001641#if _LIBCPP_STD_VER > 11
1642
Marshall Clow8411ebf2013-12-02 03:24:33 +00001643template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001644_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001645reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1646{
1647 return reverse_iterator<_Tp*>(__array + _Np);
1648}
1649
1650template <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*> rend(_Tp (&__array)[_Np])
1653{
1654 return reverse_iterator<_Tp*>(__array);
1655}
1656
1657template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001658_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001659reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1660{
1661 return reverse_iterator<const _Ep*>(__il.end());
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*> rend(initializer_list<_Ep> __il)
1667{
1668 return reverse_iterator<const _Ep*>(__il.begin());
1669}
1670
Marshall Clowb278e9c2013-08-30 01:17:07 +00001671template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001672_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001673auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001674{
Marshall Clow3862f532016-08-10 20:04:46 +00001675 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001676}
1677
1678template <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 cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001681{
Marshall Clow3862f532016-08-10 20:04:46 +00001682 return _VSTD::end(__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_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001687auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1688{
1689 return __c.rbegin();
1690}
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(const _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 rend(_Cp& __c) -> decltype(__c.rend())
1702{
1703 return __c.rend();
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(const _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 Clow3862f532016-08-10 20:04:46 +00001715auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001716{
Marshall Clow3862f532016-08-10 20:04:46 +00001717 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001718}
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 crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001723{
Marshall Clow3862f532016-08-10 20:04:46 +00001724 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001725}
1726
1727#endif
1728
1729
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001730#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001731
Howard Hinnantc834c512011-11-29 18:15:50 +00001732template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001733_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001734typename _Cp::iterator
1735begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001736{
1737 return __c.begin();
1738}
1739
Howard Hinnantc834c512011-11-29 18:15:50 +00001740template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001741_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001742typename _Cp::const_iterator
1743begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001744{
1745 return __c.begin();
1746}
1747
Howard Hinnantc834c512011-11-29 18:15:50 +00001748template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001749_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001750typename _Cp::iterator
1751end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752{
1753 return __c.end();
1754}
1755
Howard Hinnantc834c512011-11-29 18:15:50 +00001756template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001757_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001758typename _Cp::const_iterator
1759end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001760{
1761 return __c.end();
1762}
1763
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001764#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001765
Marshall Clowef357272014-11-19 19:43:23 +00001766#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001767
1768// #if _LIBCPP_STD_VER > 11
1769// template <>
1770// struct _LIBCPP_TEMPLATE_VIS plus<void>
1771// {
1772// template <class _T1, class _T2>
1773// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1774// auto operator()(_T1&& __t, _T2&& __u) const
1775// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1776// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1777// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1778// typedef void is_transparent;
1779// };
1780// #endif
1781
Marshall Clowc4b4a342015-02-11 16:14:01 +00001782template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001783_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001784constexpr auto size(const _Cont& __c)
1785_NOEXCEPT_(noexcept(__c.size()))
1786-> decltype (__c.size())
1787{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001788
Marshall Clowc4b4a342015-02-11 16:14:01 +00001789template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001790_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001791constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001792
Marshall Clow3c5363e2019-02-27 02:58:56 +00001793#if _LIBCPP_STD_VER > 17
1794template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001795_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001796constexpr auto ssize(const _Cont& __c)
1797_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1798-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1799{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1800
1801template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001802_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001803constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1804#endif
1805
Marshall Clowc4b4a342015-02-11 16:14:01 +00001806template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001807_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001808constexpr auto empty(const _Cont& __c)
1809_NOEXCEPT_(noexcept(__c.empty()))
1810-> decltype (__c.empty())
1811{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001812
Marshall Clowc4b4a342015-02-11 16:14:01 +00001813template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001814_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001815constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001816
1817template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001818_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001819constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1820
Marshall Clowc4b4a342015-02-11 16:14:01 +00001821template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001822_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001823auto data(_Cont& __c)
1824_NOEXCEPT_(noexcept(__c.data()))
1825-> decltype (__c.data())
1826{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001827
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(const _Cont& __c)
1831_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001832-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001833{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001834
Marshall Clowc4b4a342015-02-11 16:14:01 +00001835template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001836_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001837constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001838
1839template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001840_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001841constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1842#endif
1843
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001844template <class _Container, class _Predicate>
1845typename _Container::size_type
1846__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
1847 typename _Container::size_type __old_size = __c.size();
1848
1849 const typename _Container::iterator __last = __c.end();
1850 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
1851 if (__pred(*__iter))
1852 __iter = __c.erase(__iter);
1853 else
1854 ++__iter;
1855 }
1856
1857 return __old_size - __c.size();
1858}
Marshall Clowef357272014-11-19 19:43:23 +00001859
Howard Hinnantc51e1022010-05-11 19:42:16 +00001860_LIBCPP_END_NAMESPACE_STD
1861
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001862#endif // _LIBCPP_ITERATOR