blob: 54ea2aab1325feea37ec213bd276a3798e06f642 [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
16namespace std
17{
18
19template<class Iterator>
20struct iterator_traits
21{
22 typedef typename Iterator::difference_type difference_type;
23 typedef typename Iterator::value_type value_type;
24 typedef typename Iterator::pointer pointer;
25 typedef typename Iterator::reference reference;
26 typedef typename Iterator::iterator_category iterator_category;
27};
28
29template<class T>
30struct iterator_traits<T*>
31{
32 typedef ptrdiff_t difference_type;
33 typedef T value_type;
34 typedef T* pointer;
35 typedef T& reference;
36 typedef random_access_iterator_tag iterator_category;
37};
38
Howard Hinnantc51e1022010-05-11 19:42:16 +000039template<class Category, class T, class Distance = ptrdiff_t,
40 class Pointer = T*, class Reference = T&>
41struct iterator
42{
43 typedef T value_type;
44 typedef Distance difference_type;
45 typedef Pointer pointer;
46 typedef Reference reference;
47 typedef Category iterator_category;
48};
49
50struct input_iterator_tag {};
51struct output_iterator_tag {};
52struct forward_iterator_tag : public input_iterator_tag {};
53struct bidirectional_iterator_tag : public forward_iterator_tag {};
54struct random_access_iterator_tag : public bidirectional_iterator_tag {};
55
Marshall Clow75468e72017-05-17 18:51:36 +000056// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -040057template <class InputIterator, class Distance> // constexpr in C++17
58 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +000059
Marshall Clow75468e72017-05-17 18:51:36 +000060template <class InputIterator> // constexpr in C++17
61 constexpr typename iterator_traits<InputIterator>::difference_type
62 distance(InputIterator first, InputIterator last);
63
64template <class InputIterator> // constexpr in C++17
65 constexpr InputIterator next(InputIterator x,
66typename iterator_traits<InputIterator>::difference_type n = 1);
67
68template <class BidirectionalIterator> // constexpr in C++17
69 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +000070 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +000071
72template <class Iterator>
73class reverse_iterator
74 : public iterator<typename iterator_traits<Iterator>::iterator_category,
75 typename iterator_traits<Iterator>::value_type,
76 typename iterator_traits<Iterator>::difference_type,
77 typename iterator_traits<Iterator>::pointer,
78 typename iterator_traits<Iterator>::reference>
79{
80protected:
81 Iterator current;
82public:
83 typedef Iterator iterator_type;
84 typedef typename iterator_traits<Iterator>::difference_type difference_type;
85 typedef typename iterator_traits<Iterator>::reference reference;
86 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000087
Marshall Clow5ace5542016-10-19 15:12:50 +000088 constexpr reverse_iterator();
89 constexpr explicit reverse_iterator(Iterator x);
90 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
91 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
92 constexpr Iterator base() const;
93 constexpr reference operator*() const;
94 constexpr pointer operator->() const;
95 constexpr reverse_iterator& operator++();
96 constexpr reverse_iterator operator++(int);
97 constexpr reverse_iterator& operator--();
98 constexpr reverse_iterator operator--(int);
99 constexpr reverse_iterator operator+ (difference_type n) const;
100 constexpr reverse_iterator& operator+=(difference_type n);
101 constexpr reverse_iterator operator- (difference_type n) const;
102 constexpr reverse_iterator& operator-=(difference_type n);
103 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000104};
105
106template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000107constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
109
110template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000111constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000112operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
113
114template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000115constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000116operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
117
118template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000119constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
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 auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000132operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000133-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000134
135template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000136constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000137operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000138 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000139
Marshall Clow5ace5542016-10-19 15:12:50 +0000140template <class Iterator>
141constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000142
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143template <class Container>
144class back_insert_iterator
145{
146protected:
147 Container* container;
148public:
149 typedef Container container_type;
150 typedef void value_type;
151 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000152 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000153 typedef void pointer;
154
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500155 explicit back_insert_iterator(Container& x); // constexpr in C++20
156 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
157 back_insert_iterator& operator*(); // constexpr in C++20
158 back_insert_iterator& operator++(); // constexpr in C++20
159 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160};
161
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500162template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163
164template <class Container>
165class front_insert_iterator
166{
167protected:
168 Container* container;
169public:
170 typedef Container container_type;
171 typedef void value_type;
172 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000173 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174 typedef void pointer;
175
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500176 explicit front_insert_iterator(Container& x); // constexpr in C++20
177 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
178 front_insert_iterator& operator*(); // constexpr in C++20
179 front_insert_iterator& operator++(); // constexpr in C++20
180 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181};
182
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500183template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184
185template <class Container>
186class insert_iterator
187{
188protected:
189 Container* container;
190 typename Container::iterator iter;
191public:
192 typedef Container container_type;
193 typedef void value_type;
194 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000195 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196 typedef void pointer;
197
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500198 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
199 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
200 insert_iterator& operator*(); // constexpr in C++20
201 insert_iterator& operator++(); // constexpr in C++20
202 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203};
204
205template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500206insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000208template <class Iterator>
209class move_iterator {
210public:
211 typedef Iterator iterator_type;
212 typedef typename iterator_traits<Iterator>::difference_type difference_type;
213 typedef Iterator pointer;
214 typedef typename iterator_traits<Iterator>::value_type value_type;
215 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
216 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000217
Marshall Clowb5f99122016-11-02 15:30:26 +0000218 constexpr move_iterator(); // all the constexprs are in C++17
219 constexpr explicit move_iterator(Iterator i);
220 template <class U>
221 constexpr move_iterator(const move_iterator<U>& u);
222 template <class U>
223 constexpr move_iterator& operator=(const move_iterator<U>& u);
224 constexpr iterator_type base() const;
225 constexpr reference operator*() const;
226 constexpr pointer operator->() const;
227 constexpr move_iterator& operator++();
228 constexpr move_iterator operator++(int);
229 constexpr move_iterator& operator--();
230 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000231 constexpr move_iterator operator+(difference_type n) const;
232 constexpr move_iterator& operator+=(difference_type n);
233 constexpr move_iterator operator-(difference_type n) const;
234 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000235 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000236private:
237 Iterator current; // exposition only
238};
239
240template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000241constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000242operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
243
244template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000245constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000246operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
247
248template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000249constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000250operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
251
252template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000253constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000254operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
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 auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000266operator-(const move_iterator<Iterator1>& x,
267 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
268
269template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000270constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000271 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000272 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000273
Marshall Clowb5f99122016-11-02 15:30:26 +0000274template <class Iterator> // constexpr in C++17
275constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000276
277
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
279class istream_iterator
280 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
281{
282public:
283 typedef charT char_type;
284 typedef traits traits_type;
285 typedef basic_istream<charT,traits> istream_type;
286
Marshall Clow0735e4e2015-04-16 21:36:54 +0000287 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288 istream_iterator(istream_type& s);
289 istream_iterator(const istream_iterator& x);
290 ~istream_iterator();
291
292 const T& operator*() const;
293 const T* operator->() const;
294 istream_iterator& operator++();
295 istream_iterator operator++(int);
296};
297
298template <class T, class charT, class traits, class Distance>
299bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
300 const istream_iterator<T,charT,traits,Distance>& y);
301template <class T, class charT, class traits, class Distance>
302bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
303 const istream_iterator<T,charT,traits,Distance>& y);
304
305template <class T, class charT = char, class traits = char_traits<charT> >
306class ostream_iterator
307 : public iterator<output_iterator_tag, void, void, void ,void>
308{
309public:
310 typedef charT char_type;
311 typedef traits traits_type;
312 typedef basic_ostream<charT,traits> ostream_type;
313
314 ostream_iterator(ostream_type& s);
315 ostream_iterator(ostream_type& s, const charT* delimiter);
316 ostream_iterator(const ostream_iterator& x);
317 ~ostream_iterator();
318 ostream_iterator& operator=(const T& value);
319
320 ostream_iterator& operator*();
321 ostream_iterator& operator++();
322 ostream_iterator& operator++(int);
323};
324
325template<class charT, class traits = char_traits<charT> >
326class istreambuf_iterator
327 : public iterator<input_iterator_tag, charT,
328 typename traits::off_type, unspecified,
329 charT>
330{
331public:
332 typedef charT char_type;
333 typedef traits traits_type;
334 typedef typename traits::int_type int_type;
335 typedef basic_streambuf<charT,traits> streambuf_type;
336 typedef basic_istream<charT,traits> istream_type;
337
Howard Hinnant011138d2012-07-20 19:36:34 +0000338 istreambuf_iterator() noexcept;
339 istreambuf_iterator(istream_type& s) noexcept;
340 istreambuf_iterator(streambuf_type* s) noexcept;
341 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342
343 charT operator*() const;
344 pointer operator->() const;
345 istreambuf_iterator& operator++();
346 a-private-type operator++(int);
347
348 bool equal(const istreambuf_iterator& b) const;
349};
350
351template <class charT, class traits>
352bool operator==(const istreambuf_iterator<charT,traits>& a,
353 const istreambuf_iterator<charT,traits>& b);
354template <class charT, class traits>
355bool operator!=(const istreambuf_iterator<charT,traits>& a,
356 const istreambuf_iterator<charT,traits>& b);
357
358template <class charT, class traits = char_traits<charT> >
359class ostreambuf_iterator
360 : public iterator<output_iterator_tag, void, void, void, void>
361{
362public:
363 typedef charT char_type;
364 typedef traits traits_type;
365 typedef basic_streambuf<charT,traits> streambuf_type;
366 typedef basic_ostream<charT,traits> ostream_type;
367
Howard Hinnant011138d2012-07-20 19:36:34 +0000368 ostreambuf_iterator(ostream_type& s) noexcept;
369 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 ostreambuf_iterator& operator=(charT c);
371 ostreambuf_iterator& operator*();
372 ostreambuf_iterator& operator++();
373 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000374 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375};
376
Marshall Clow99ba0022017-01-04 17:58:17 +0000377template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
378template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
379template <class C> constexpr auto end(C& c) -> decltype(c.end());
380template <class C> constexpr auto end(const C& c) -> decltype(c.end());
381template <class T, size_t N> constexpr T* begin(T (&array)[N]);
382template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383
Marshall Clow99ba0022017-01-04 17:58:17 +0000384template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
385template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
386template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
387template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
388template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
389template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
390template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
391template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
392template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
393template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
394template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
395template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000396
Marshall Clowef357272014-11-19 19:43:23 +0000397// 24.8, container access:
398template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
399template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000400
401template <class C> constexpr auto ssize(const C& c)
402 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
403template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
404
Marshall Clowef357272014-11-19 19:43:23 +0000405template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
406template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
407template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
408template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
409template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
410template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
411template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
412
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413} // std
414
415*/
416
417#include <__config>
Eric Fiselier876c6862016-02-20 00:19:45 +0000418#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow3dc05502014-02-27 02:11:50 +0000419#include <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420#include <type_traits>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400421#include <compare>
422#include <concepts>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423#include <cstddef>
Marshall Clowb278e9c2013-08-30 01:17:07 +0000424#include <initializer_list>
Louis Dionnefa621d72020-12-10 18:28:13 -0500425#include <__memory/base.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500426#include <__memory/pointer_traits.h>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000427#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000428
Eric Fiselier14b6de92014-08-10 23:53:08 +0000429#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000431#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000433#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434
435_LIBCPP_BEGIN_NAMESPACE_STD
Eric Fiselier7b2a34f2019-11-16 20:24:39 -0500436template <class _Iter>
437struct _LIBCPP_TEMPLATE_VIS iterator_traits;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000439struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
440struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
441struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
442struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
443struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
Eric Fiselier30005a92019-11-16 20:12:48 -0500444#if _LIBCPP_STD_VER > 17
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500445struct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag : public random_access_iterator_tag {};
Eric Fiselier30005a92019-11-16 20:12:48 -0500446#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447
Eric Fiselier7b2a34f2019-11-16 20:24:39 -0500448template <class _Iter>
449struct __iter_traits_cache {
450 using type = _If<
451 __is_primary_template<iterator_traits<_Iter> >::value,
452 _Iter,
453 iterator_traits<_Iter>
454 >;
455};
456template <class _Iter>
457using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type;
458
459struct __iter_concept_concept_test {
460 template <class _Iter>
461 using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept;
462};
463struct __iter_concept_category_test {
464 template <class _Iter>
465 using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category;
466};
467struct __iter_concept_random_fallback {
468 template <class _Iter>
469 using _Apply = _EnableIf<
470 __is_primary_template<iterator_traits<_Iter> >::value,
471 random_access_iterator_tag
472 >;
473};
474
475template <class _Iter, class _Tester> struct __test_iter_concept
476 : _IsValidExpansion<_Tester::template _Apply, _Iter>,
477 _Tester
478{
479};
480
481template <class _Iter>
482struct __iter_concept_cache {
483 using type = _Or<
484 __test_iter_concept<_Iter, __iter_concept_concept_test>,
485 __test_iter_concept<_Iter, __iter_concept_category_test>,
486 __test_iter_concept<_Iter, __iter_concept_random_fallback>
487 >;
488};
489
490template <class _Iter>
491using _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
492
493
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494template <class _Tp>
Marshall Clow50abbe42018-11-13 05:33:31 +0000495struct __has_iterator_typedefs
496{
497private:
498 struct __two {char __lx; char __lxx;};
499 template <class _Up> static __two __test(...);
Arthur O'Dwyer07b22492020-11-27 11:02:06 -0500500 template <class _Up> static char __test(typename __void_t<typename _Up::iterator_category>::type* = 0,
501 typename __void_t<typename _Up::difference_type>::type* = 0,
502 typename __void_t<typename _Up::value_type>::type* = 0,
503 typename __void_t<typename _Up::reference>::type* = 0,
504 typename __void_t<typename _Up::pointer>::type* = 0);
Marshall Clow50abbe42018-11-13 05:33:31 +0000505public:
506 static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1;
507};
508
509
510template <class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511struct __has_iterator_category
512{
513private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000514 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515 template <class _Up> static __two __test(...);
Bruce Mitchener170d8972020-11-24 12:53:53 -0500516 template <class _Up> static char __test(typename _Up::iterator_category* = nullptr);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500518 static const bool value = sizeof(__test<_Tp>(nullptr)) == 1;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519};
520
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500521template <class _Tp>
522struct __has_iterator_concept
523{
524private:
525 struct __two {char __lx; char __lxx;};
526 template <class _Up> static __two __test(...);
527 template <class _Up> static char __test(typename _Up::iterator_concept* = nullptr);
528public:
529 static const bool value = sizeof(__test<_Tp>(nullptr)) == 1;
530};
531
Marshall Clow75533b02014-01-03 22:55:49 +0000532template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533
534template <class _Iter>
Marshall Clow75533b02014-01-03 22:55:49 +0000535struct __iterator_traits_impl<_Iter, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536{
537 typedef typename _Iter::difference_type difference_type;
538 typedef typename _Iter::value_type value_type;
539 typedef typename _Iter::pointer pointer;
540 typedef typename _Iter::reference reference;
541 typedef typename _Iter::iterator_category iterator_category;
542};
543
544template <class _Iter, bool> struct __iterator_traits {};
545
546template <class _Iter>
547struct __iterator_traits<_Iter, true>
Marshall Clow75533b02014-01-03 22:55:49 +0000548 : __iterator_traits_impl
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549 <
550 _Iter,
551 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
552 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
553 >
554{};
555
556// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
557// exists. Else iterator_traits<Iterator> will be an empty class. This is a
558// conforming extension which allows some programs to compile and behave as
559// the client expects instead of failing at compile time.
560
561template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000562struct _LIBCPP_TEMPLATE_VIS iterator_traits
Eric Fiselier7b2a34f2019-11-16 20:24:39 -0500563 : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {
564
565 using __primary_template = iterator_traits;
566};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567
568template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000569struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570{
571 typedef ptrdiff_t difference_type;
Marshall Clow56d53522017-11-14 00:03:10 +0000572 typedef typename remove_cv<_Tp>::type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000573 typedef _Tp* pointer;
574 typedef _Tp& reference;
575 typedef random_access_iterator_tag iterator_category;
Eric Fiselier30005a92019-11-16 20:12:48 -0500576#if _LIBCPP_STD_VER > 17
577 typedef contiguous_iterator_tag iterator_concept;
578#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579};
580
581template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
582struct __has_iterator_category_convertible_to
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500583 : _BoolConstant<is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584{};
585
586template <class _Tp, class _Up>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500587struct __has_iterator_category_convertible_to<_Tp, _Up, false> : false_type {};
588
589template <class _Tp, class _Up, bool = __has_iterator_concept<_Tp>::value>
590struct __has_iterator_concept_convertible_to
591 : _BoolConstant<is_convertible<typename _Tp::iterator_concept, _Up>::value>
592{};
593
594template <class _Tp, class _Up>
595struct __has_iterator_concept_convertible_to<_Tp, _Up, false> : false_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596
597template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500598struct __is_cpp17_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599
600template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500601struct __is_cpp17_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602
603template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500604struct __is_cpp17_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605
606template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500607struct __is_cpp17_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500609// __is_cpp17_contiguous_iterator determines if an iterator is contiguous,
610// either because it advertises itself as such (in C++20) or because it
611// is a pointer type or a known trivial wrapper around a pointer type,
612// such as __wrap_iter<T*>.
613//
Eric Fiselier30005a92019-11-16 20:12:48 -0500614#if _LIBCPP_STD_VER > 17
615template <class _Tp>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500616struct __is_cpp17_contiguous_iterator : _Or<
617 __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag>,
618 __has_iterator_concept_convertible_to<_Tp, contiguous_iterator_tag>
619> {};
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500620#else
621template <class _Tp>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500622struct __is_cpp17_contiguous_iterator : false_type {};
Eric Fiselier30005a92019-11-16 20:12:48 -0500623#endif
624
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500625// Any native pointer which is an iterator is also a contiguous iterator.
626template <class _Up>
627struct __is_cpp17_contiguous_iterator<_Up*> : true_type {};
628
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500629
Marshall Clow039b2f02016-01-13 21:54:34 +0000630template <class _Tp>
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500631struct __is_exactly_cpp17_input_iterator
Louis Dionne173f29e2019-05-29 16:01:36 +0000632 : public integral_constant<bool,
633 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
Marshall Clowb5f99122016-11-02 15:30:26 +0000634 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
Marshall Clow039b2f02016-01-13 21:54:34 +0000635
Louis Dionned23a5f22019-06-20 19:32:00 +0000636#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
637template<class _InputIterator>
638using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
639
640template<class _InputIterator>
641using __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
642
643template<class _InputIterator>
644using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
645
646template<class _InputIterator>
647using __iter_to_alloc_type = pair<
648 add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
649 typename iterator_traits<_InputIterator>::value_type::second_type>;
650#endif
651
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652template<class _Category, class _Tp, class _Distance = ptrdiff_t,
653 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000654struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655{
656 typedef _Tp value_type;
657 typedef _Distance difference_type;
658 typedef _Pointer pointer;
659 typedef _Reference reference;
660 typedef _Category iterator_category;
661};
662
663template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000664inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665void __advance(_InputIter& __i,
666 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
667{
668 for (; __n > 0; --__n)
669 ++__i;
670}
671
672template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000673inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674void __advance(_BiDirIter& __i,
675 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
676{
677 if (__n >= 0)
678 for (; __n > 0; --__n)
679 ++__i;
680 else
681 for (; __n < 0; ++__n)
682 --__i;
683}
684
685template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000686inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000687void __advance(_RandIter& __i,
688 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
689{
690 __i += __n;
691}
692
Louis Dionne45768662020-06-08 16:16:01 -0400693template <class _InputIter, class _Distance>
Marshall Clow75468e72017-05-17 18:51:36 +0000694inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Louis Dionne45768662020-06-08 16:16:01 -0400695void advance(_InputIter& __i, _Distance __orig_n)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696{
Louis Dionne45768662020-06-08 16:16:01 -0400697 _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
698 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500699 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
Louis Dionne45768662020-06-08 16:16:01 -0400700 _IntegralSize __n = __orig_n;
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500701 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702}
703
704template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000705inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706typename iterator_traits<_InputIter>::difference_type
707__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
708{
709 typename iterator_traits<_InputIter>::difference_type __r(0);
710 for (; __first != __last; ++__first)
711 ++__r;
712 return __r;
713}
714
715template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000716inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717typename iterator_traits<_RandIter>::difference_type
718__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
719{
720 return __last - __first;
721}
722
723template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000724inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725typename iterator_traits<_InputIter>::difference_type
726distance(_InputIter __first, _InputIter __last)
727{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500728 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729}
730
Marshall Clow990c70d2015-11-07 17:48:49 +0000731template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000732inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000733typename enable_if
734<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500735 __is_cpp17_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000736 _InputIter
737>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000738next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000739 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000740{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500741 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400742 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
Marshall Clow3d435212019-03-22 22:32:20 +0000743
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000744 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745 return __x;
746}
747
Marshall Clow3d435212019-03-22 22:32:20 +0000748template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000749inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000750typename enable_if
751<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500752 __is_cpp17_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000753 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000754>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000755prev(_InputIter __x,
756 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500758 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400759 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000760 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761 return __x;
762}
763
Eric Fiselier883af112017-04-13 02:54:13 +0000764
765template <class _Tp, class = void>
766struct __is_stashing_iterator : false_type {};
767
768template <class _Tp>
769struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
770 : true_type {};
771
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000773class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 : public iterator<typename iterator_traits<_Iter>::iterator_category,
775 typename iterator_traits<_Iter>::value_type,
776 typename iterator_traits<_Iter>::difference_type,
777 typename iterator_traits<_Iter>::pointer,
778 typename iterator_traits<_Iter>::reference>
779{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000780private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000781 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000782
783 static_assert(!__is_stashing_iterator<_Iter>::value,
784 "The specified iterator type cannot be used with reverse_iterator; "
785 "Using stashing iterators with reverse_iterator causes undefined behavior");
786
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000787protected:
788 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789public:
790 typedef _Iter iterator_type;
791 typedef typename iterator_traits<_Iter>::difference_type difference_type;
792 typedef typename iterator_traits<_Iter>::reference reference;
793 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500794 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
795 random_access_iterator_tag,
796 typename iterator_traits<_Iter>::iterator_category> iterator_category;
797#if _LIBCPP_STD_VER > 17
798 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
799 random_access_iterator_tag,
800 bidirectional_iterator_tag> iterator_concept;
801#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000802
Marshall Clow5ace5542016-10-19 15:12:50 +0000803 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
804 reverse_iterator() : __t(), current() {}
805 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
806 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
807 template <class _Up>
808 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
809 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
810 template <class _Up>
811 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
812 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
813 { __t = current = __u.base(); return *this; }
814 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
815 _Iter base() const {return current;}
816 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
817 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
818 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
819 pointer operator->() const {return _VSTD::addressof(operator*());}
820 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
821 reverse_iterator& operator++() {--current; return *this;}
822 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
823 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
824 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
825 reverse_iterator& operator--() {++current; return *this;}
826 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
827 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
828 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
829 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
830 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
831 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
832 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
833 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
834 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
835 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
836 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
837 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838};
839
840template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000841inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842bool
843operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
844{
845 return __x.base() == __y.base();
846}
847
848template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000849inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850bool
851operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
852{
853 return __x.base() > __y.base();
854}
855
856template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000857inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858bool
859operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
860{
861 return __x.base() != __y.base();
862}
863
864template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000865inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866bool
867operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
868{
869 return __x.base() < __y.base();
870}
871
872template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000873inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874bool
875operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
876{
877 return __x.base() <= __y.base();
878}
879
880template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000881inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882bool
883operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
884{
885 return __x.base() >= __y.base();
886}
887
Marshall Clow476d3f42016-07-18 13:19:00 +0000888#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000889template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000890inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000891auto
892operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
893-> decltype(__y.base() - __x.base())
894{
895 return __y.base() - __x.base();
896}
897#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898template <class _Iter1, class _Iter2>
899inline _LIBCPP_INLINE_VISIBILITY
900typename reverse_iterator<_Iter1>::difference_type
901operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
902{
903 return __y.base() - __x.base();
904}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000905#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906
907template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000908inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909reverse_iterator<_Iter>
910operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
911{
912 return reverse_iterator<_Iter>(__x.base() - __n);
913}
914
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000915#if _LIBCPP_STD_VER > 11
916template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000917inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000918reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
919{
920 return reverse_iterator<_Iter>(__i);
921}
922#endif
923
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000925class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000926 : public iterator<output_iterator_tag,
927 void,
928 void,
929 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000930 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931{
932protected:
933 _Container* container;
934public:
935 typedef _Container container_type;
936
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500937 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
938 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000939 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000940#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500941 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000942 {container->push_back(_VSTD::move(__value_)); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000943#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500944 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
945 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
946 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000947};
948
949template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500950inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951back_insert_iterator<_Container>
952back_inserter(_Container& __x)
953{
954 return back_insert_iterator<_Container>(__x);
955}
956
957template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000958class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959 : public iterator<output_iterator_tag,
960 void,
961 void,
962 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000963 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964{
965protected:
966 _Container* container;
967public:
968 typedef _Container container_type;
969
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500970 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
971 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000972 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000973#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500974 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000975 {container->push_front(_VSTD::move(__value_)); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000976#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500977 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
978 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
979 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000980};
981
982template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500983inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984front_insert_iterator<_Container>
985front_inserter(_Container& __x)
986{
987 return front_insert_iterator<_Container>(__x);
988}
989
990template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000991class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 : public iterator<output_iterator_tag,
993 void,
994 void,
995 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000996 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997{
998protected:
999 _Container* container;
1000 typename _Container::iterator iter;
1001public:
1002 typedef _Container container_type;
1003
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001004 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +00001005 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001006 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +00001007 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001008#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001009 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +00001010 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001011#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001012 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
1013 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
1014 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015};
1016
1017template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -05001018inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019insert_iterator<_Container>
1020inserter(_Container& __x, typename _Container::iterator __i)
1021{
1022 return insert_iterator<_Container>(__x, __i);
1023}
1024
1025template <class _Tp, class _CharT = char,
1026 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001027class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001028 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
1029{
1030public:
1031 typedef _CharT char_type;
1032 typedef _Traits traits_type;
1033 typedef basic_istream<_CharT,_Traits> istream_type;
1034private:
1035 istream_type* __in_stream_;
1036 _Tp __value_;
1037public:
Bruce Mitchener170d8972020-11-24 12:53:53 -05001038 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +00001039 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001040 {
1041 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001042 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043 }
1044
1045 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +00001046 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
1048 {
1049 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001050 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051 return *this;
1052 }
1053 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
1054 {istream_iterator __t(*this); ++(*this); return __t;}
1055
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001056 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001058 bool
1059 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
1060 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001062 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001063 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001064 bool
1065 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
1066 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067};
1068
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001069template <class _Tp, class _CharT, class _Traits, class _Distance>
1070inline _LIBCPP_INLINE_VISIBILITY
1071bool
1072operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
1073 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
1074{
1075 return __x.__in_stream_ == __y.__in_stream_;
1076}
1077
1078template <class _Tp, class _CharT, class _Traits, class _Distance>
1079inline _LIBCPP_INLINE_VISIBILITY
1080bool
1081operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
1082 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
1083{
1084 return !(__x == __y);
1085}
1086
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001088class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001089 : public iterator<output_iterator_tag, void, void, void, void>
1090{
1091public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001092 typedef output_iterator_tag iterator_category;
1093 typedef void value_type;
1094#if _LIBCPP_STD_VER > 17
1095 typedef std::ptrdiff_t difference_type;
1096#else
1097 typedef void difference_type;
1098#endif
1099 typedef void pointer;
1100 typedef void reference;
1101 typedef _CharT char_type;
1102 typedef _Traits traits_type;
1103 typedef basic_ostream<_CharT, _Traits> ostream_type;
1104
Howard Hinnantc51e1022010-05-11 19:42:16 +00001105private:
1106 ostream_type* __out_stream_;
1107 const char_type* __delim_;
1108public:
Marshall Clow27a89512016-10-12 16:13:48 +00001109 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -05001110 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +00001111 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +00001112 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +00001113 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001114 {
Howard Hinnantbf074022011-10-22 20:59:45 +00001115 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 if (__delim_)
1117 *__out_stream_ << __delim_;
1118 return *this;
1119 }
1120
1121 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
1122 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
1123 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
1124};
1125
1126template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001127class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128 : public iterator<input_iterator_tag, _CharT,
1129 typename _Traits::off_type, _CharT*,
1130 _CharT>
1131{
1132public:
1133 typedef _CharT char_type;
1134 typedef _Traits traits_type;
1135 typedef typename _Traits::int_type int_type;
1136 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1137 typedef basic_istream<_CharT,_Traits> istream_type;
1138private:
Howard Hinnant3e57b272012-11-16 22:17:23 +00001139 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140
1141 class __proxy
1142 {
1143 char_type __keep_;
1144 streambuf_type* __sbuf_;
1145 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
1146 : __keep_(__c), __sbuf_(__s) {}
1147 friend class istreambuf_iterator;
1148 public:
1149 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
1150 };
1151
Howard Hinnant756c69b2010-09-22 16:48:34 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +00001153 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001154 {
1155 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001156 __sbuf_ = nullptr;
1157 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158 }
1159public:
Bruce Mitchener170d8972020-11-24 12:53:53 -05001160 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001161 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001162 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001163 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001164 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001165 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166 : __sbuf_(__p.__sbuf_) {}
1167
Howard Hinnant28b24882011-12-01 20:21:04 +00001168 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1169 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1171 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001172 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001173 return *this;
1174 }
1175 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1176 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001177 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178 }
1179
1180 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001181 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182};
1183
1184template <class _CharT, class _Traits>
1185inline _LIBCPP_INLINE_VISIBILITY
1186bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1187 const istreambuf_iterator<_CharT,_Traits>& __b)
1188 {return __a.equal(__b);}
1189
1190template <class _CharT, class _Traits>
1191inline _LIBCPP_INLINE_VISIBILITY
1192bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1193 const istreambuf_iterator<_CharT,_Traits>& __b)
1194 {return !__a.equal(__b);}
1195
1196template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001197class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198 : public iterator<output_iterator_tag, void, void, void, void>
1199{
1200public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001201 typedef output_iterator_tag iterator_category;
1202 typedef void value_type;
1203#if _LIBCPP_STD_VER > 17
1204 typedef std::ptrdiff_t difference_type;
1205#else
1206 typedef void difference_type;
1207#endif
1208 typedef void pointer;
1209 typedef void reference;
1210 typedef _CharT char_type;
1211 typedef _Traits traits_type;
1212 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1213 typedef basic_ostream<_CharT, _Traits> ostream_type;
1214
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215private:
1216 streambuf_type* __sbuf_;
1217public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001218 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001220 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221 : __sbuf_(__s) {}
1222 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1223 {
1224 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001225 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001226 return *this;
1227 }
1228 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1229 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1230 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001231 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001232
1233 template <class _Ch, class _Tr>
1234 friend
1235 _LIBCPP_HIDDEN
1236 ostreambuf_iterator<_Ch, _Tr>
1237 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1238 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1239 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240};
1241
1242template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001243class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244{
1245private:
1246 _Iter __i;
1247public:
1248 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001249 typedef typename iterator_traits<iterator_type>::value_type value_type;
1250 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001251 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001252 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1253 random_access_iterator_tag,
1254 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1255#if _LIBCPP_STD_VER > 17
1256 typedef input_iterator_tag iterator_concept;
1257#endif
1258
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001259#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001260 typedef typename iterator_traits<iterator_type>::reference __reference;
1261 typedef typename conditional<
1262 is_reference<__reference>::value,
1263 typename remove_reference<__reference>::type&&,
1264 __reference
1265 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266#else
1267 typedef typename iterator_traits<iterator_type>::reference reference;
1268#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001269
Marshall Clowb5f99122016-11-02 15:30:26 +00001270 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1271 move_iterator() : __i() {}
1272 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1273 explicit move_iterator(_Iter __x) : __i(__x) {}
1274 template <class _Up>
1275 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1276 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1277 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001278 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001279 reference operator*() const { return static_cast<reference>(*__i); }
1280 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1281 pointer operator->() const { return __i;}
1282 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1283 move_iterator& operator++() {++__i; return *this;}
1284 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1285 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1286 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1287 move_iterator& operator--() {--__i; return *this;}
1288 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1289 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1290 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1291 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1292 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1293 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1294 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1295 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1296 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1297 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1298 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1299 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300};
1301
1302template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001303inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304bool
1305operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1306{
1307 return __x.base() == __y.base();
1308}
1309
1310template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001311inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001312bool
1313operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1314{
1315 return __x.base() < __y.base();
1316}
1317
1318template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001319inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320bool
1321operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1322{
1323 return __x.base() != __y.base();
1324}
1325
1326template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001327inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001328bool
1329operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1330{
1331 return __x.base() > __y.base();
1332}
1333
1334template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001335inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001336bool
1337operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1338{
1339 return __x.base() >= __y.base();
1340}
1341
1342template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001343inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001344bool
1345operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1346{
1347 return __x.base() <= __y.base();
1348}
1349
Marshall Clow476d3f42016-07-18 13:19:00 +00001350#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001351template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001352inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001353auto
1354operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1355-> decltype(__x.base() - __y.base())
1356{
1357 return __x.base() - __y.base();
1358}
1359#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360template <class _Iter1, class _Iter2>
1361inline _LIBCPP_INLINE_VISIBILITY
1362typename move_iterator<_Iter1>::difference_type
1363operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1364{
1365 return __x.base() - __y.base();
1366}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001367#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368
1369template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001370inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371move_iterator<_Iter>
1372operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1373{
1374 return move_iterator<_Iter>(__x.base() + __n);
1375}
1376
1377template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001378inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001380make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381{
1382 return move_iterator<_Iter>(__i);
1383}
1384
1385// __wrap_iter
1386
1387template <class _Iter> class __wrap_iter;
1388
1389template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001390_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001391bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001392operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393
1394template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001395_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001396bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001397operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398
1399template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001400_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001401bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001402operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001403
1404template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001405_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001406bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001407operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001408
1409template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001410_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001412operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413
1414template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001415_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001417operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001418
Marshall Clow476d3f42016-07-18 13:19:00 +00001419#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001420template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001421_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001422auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001423operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001424-> decltype(__x.base() - __y.base());
1425#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001427_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001429operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001430#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431
1432template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001433_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001435operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001436
Louis Dionne65b433b2019-11-06 12:02:41 +00001437template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1438template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001439template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1440template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001441
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442template <class _Iter>
1443class __wrap_iter
1444{
1445public:
1446 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447 typedef typename iterator_traits<iterator_type>::value_type value_type;
1448 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1449 typedef typename iterator_traits<iterator_type>::pointer pointer;
1450 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001451 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1452#if _LIBCPP_STD_VER > 17
1453 typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1454 contiguous_iterator_tag, iterator_category> iterator_concept;
1455#endif
1456
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457private:
1458 iterator_type __i;
1459public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001460 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001461#if _LIBCPP_STD_VER > 11
1462 : __i{}
1463#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001464 {
Louis Dionneba400782020-10-02 15:02:52 -04001465#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001466 __get_db()->__insert_i(this);
1467#endif
1468 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001469 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1470 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001471 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001472 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001473 {
Louis Dionneba400782020-10-02 15:02:52 -04001474#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001475 __get_db()->__iterator_copy(this, &__u);
1476#endif
1477 }
Louis Dionneba400782020-10-02 15:02:52 -04001478#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001479 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001480 __wrap_iter(const __wrap_iter& __x)
1481 : __i(__x.base())
1482 {
1483 __get_db()->__iterator_copy(this, &__x);
1484 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001485 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001486 __wrap_iter& operator=(const __wrap_iter& __x)
1487 {
1488 if (this != &__x)
1489 {
1490 __get_db()->__iterator_copy(this, &__x);
1491 __i = __x.__i;
1492 }
1493 return *this;
1494 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001495 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001496 ~__wrap_iter()
1497 {
1498 __get_db()->__erase_i(this);
1499 }
1500#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001501 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001502 {
Louis Dionneba400782020-10-02 15:02:52 -04001503#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001504 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1505 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001506#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001507 return *__i;
1508 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001509 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001510 {
Louis Dionneba400782020-10-02 15:02:52 -04001511#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001512 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1513 "Attempted to dereference a non-dereferenceable iterator");
1514#endif
Marshall Clowd85a0562016-04-11 03:54:53 +00001515 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001516 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001517 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001518 {
Louis Dionneba400782020-10-02 15:02:52 -04001519#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001520 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1521 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001522#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001523 ++__i;
1524 return *this;
1525 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001526 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001527 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001528
Eric Fiselier873b8d32019-03-18 21:50:12 +00001529 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001530 {
Louis Dionneba400782020-10-02 15:02:52 -04001531#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001532 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1533 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001534#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001535 --__i;
1536 return *this;
1537 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001538 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001539 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001540 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001541 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001542 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001543 {
Louis Dionneba400782020-10-02 15:02:52 -04001544#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001545 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1546 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001547#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001548 __i += __n;
1549 return *this;
1550 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001551 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001552 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001553 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001554 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001555 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001556 {
Louis Dionneba400782020-10-02 15:02:52 -04001557#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001558 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1559 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001560#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001561 return __i[__n];
1562 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563
Eric Fiselier873b8d32019-03-18 21:50:12 +00001564 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001565
1566private:
Louis Dionneba400782020-10-02 15:02:52 -04001567#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001568 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001569 {
1570 __get_db()->__insert_ic(this, __p);
1571 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001572#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001573 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001574#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001575
1576 template <class _Up> friend class __wrap_iter;
1577 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001578 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001579 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580
1581 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001582 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001584 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001585
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001587 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001589 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001590
Howard Hinnantc51e1022010-05-11 19:42:16 +00001591 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001592 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001593 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001594 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001595
Howard Hinnantc51e1022010-05-11 19:42:16 +00001596 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001597 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001599 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001600
Howard Hinnantc51e1022010-05-11 19:42:16 +00001601 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001602 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001603 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001604 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001605
Howard Hinnantc51e1022010-05-11 19:42:16 +00001606 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001607 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001608 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001609 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001610
Marshall Clow476d3f42016-07-18 13:19:00 +00001611#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001612 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001613 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001614 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001615 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001616 -> decltype(__x.base() - __y.base());
1617#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001619 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001621 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001622#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001623
Howard Hinnantc51e1022010-05-11 19:42:16 +00001624 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001625 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001626 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001627 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001628
Louis Dionne65b433b2019-11-06 12:02:41 +00001629 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op);
1630 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001631 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op move(_Ip, _Ip, _Op);
1632 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633};
1634
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001635#if _LIBCPP_STD_VER <= 17
1636template <class _It>
1637struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1638#endif
1639
1640template <class _Iter>
1641_LIBCPP_CONSTEXPR
1642_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1643__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1644 return _VSTD::__to_address(__w.base());
1645}
1646
Howard Hinnantc51e1022010-05-11 19:42:16 +00001647template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001648inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001649bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001650operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651{
1652 return __x.base() == __y.base();
1653}
1654
1655template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001656inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001657bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001658operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659{
Louis Dionneba400782020-10-02 15:02:52 -04001660#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001661 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001662 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001663#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664 return __x.base() < __y.base();
1665}
1666
1667template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001668inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001670operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001671{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001672 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001673}
1674
1675template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001676inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001677bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001678operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001680 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001681}
1682
1683template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001684inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001685bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001686operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001688 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001689}
1690
1691template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001692inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001693bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001694operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001695{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001696 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001697}
1698
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001699template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001700inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001701bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001702operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001703{
1704 return !(__x == __y);
1705}
1706
1707template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001708inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001709bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001710operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001711{
1712 return __y < __x;
1713}
1714
1715template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001716inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001717bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001718operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001719{
1720 return !(__x < __y);
1721}
1722
1723template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001724inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001725bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001726operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001727{
1728 return !(__y < __x);
1729}
1730
Marshall Clow476d3f42016-07-18 13:19:00 +00001731#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001732template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001733inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001734auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001735operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001736-> decltype(__x.base() - __y.base())
1737{
Louis Dionneba400782020-10-02 15:02:52 -04001738#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001739 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1740 "Attempted to subtract incompatible iterators");
1741#endif
1742 return __x.base() - __y.base();
1743}
1744#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001745template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001746inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001747typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001748operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001749{
Louis Dionneba400782020-10-02 15:02:52 -04001750#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001751 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001752 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001753#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001754 return __x.base() - __y.base();
1755}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001756#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001757
1758template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001759inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001760__wrap_iter<_Iter>
1761operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001762 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001763{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001764 __x += __n;
1765 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001766}
1767
Marshall Clow039b2f02016-01-13 21:54:34 +00001768template <class _Iter>
1769struct __libcpp_is_trivial_iterator
Marshall Clowb5f99122016-11-02 15:30:26 +00001770 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
Louis Dionne173f29e2019-05-29 16:01:36 +00001771
Marshall Clow039b2f02016-01-13 21:54:34 +00001772template <class _Iter>
1773struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001774 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001775
1776template <class _Iter>
1777struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001778 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001779
1780template <class _Iter>
1781struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001782 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001783
1784
Marshall Clow8411ebf2013-12-02 03:24:33 +00001785template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001786_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001787_Tp*
1788begin(_Tp (&__array)[_Np])
1789{
1790 return __array;
1791}
1792
1793template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001794_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001795_Tp*
1796end(_Tp (&__array)[_Np])
1797{
1798 return __array + _Np;
1799}
1800
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001801#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001802
Howard Hinnantc834c512011-11-29 18:15:50 +00001803template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001804_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001805auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001806begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001807{
1808 return __c.begin();
1809}
1810
Howard Hinnantc834c512011-11-29 18:15:50 +00001811template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001812_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001814begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001815{
1816 return __c.begin();
1817}
1818
Howard Hinnantc834c512011-11-29 18:15:50 +00001819template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001820_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001821auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001822end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001823{
1824 return __c.end();
1825}
1826
Howard Hinnantc834c512011-11-29 18:15:50 +00001827template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001828_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001829auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001830end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001831{
1832 return __c.end();
1833}
1834
Marshall Clowb278e9c2013-08-30 01:17:07 +00001835#if _LIBCPP_STD_VER > 11
1836
Marshall Clow8411ebf2013-12-02 03:24:33 +00001837template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001838_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001839reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1840{
1841 return reverse_iterator<_Tp*>(__array + _Np);
1842}
1843
1844template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001845_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001846reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1847{
1848 return reverse_iterator<_Tp*>(__array);
1849}
1850
1851template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001852_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001853reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1854{
1855 return reverse_iterator<const _Ep*>(__il.end());
1856}
1857
1858template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001859_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001860reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1861{
1862 return reverse_iterator<const _Ep*>(__il.begin());
1863}
1864
Marshall Clowb278e9c2013-08-30 01:17:07 +00001865template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001866_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001867auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001868{
Marshall Clow3862f532016-08-10 20:04:46 +00001869 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001870}
1871
1872template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001873_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001874auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001875{
Marshall Clow3862f532016-08-10 20:04:46 +00001876 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001877}
1878
1879template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001880_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001881auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1882{
1883 return __c.rbegin();
1884}
1885
1886template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001887_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001888auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1889{
1890 return __c.rbegin();
1891}
1892
1893template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001894_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001895auto rend(_Cp& __c) -> decltype(__c.rend())
1896{
1897 return __c.rend();
1898}
1899
1900template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001901_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001902auto rend(const _Cp& __c) -> decltype(__c.rend())
1903{
1904 return __c.rend();
1905}
1906
1907template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001908_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001909auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001910{
Marshall Clow3862f532016-08-10 20:04:46 +00001911 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001912}
1913
1914template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001915_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001916auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001917{
Marshall Clow3862f532016-08-10 20:04:46 +00001918 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001919}
1920
1921#endif
1922
1923
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001924#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001925
Howard Hinnantc834c512011-11-29 18:15:50 +00001926template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001927_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001928typename _Cp::iterator
1929begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001930{
1931 return __c.begin();
1932}
1933
Howard Hinnantc834c512011-11-29 18:15:50 +00001934template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001935_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001936typename _Cp::const_iterator
1937begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001938{
1939 return __c.begin();
1940}
1941
Howard Hinnantc834c512011-11-29 18:15:50 +00001942template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001943_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001944typename _Cp::iterator
1945end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001946{
1947 return __c.end();
1948}
1949
Howard Hinnantc834c512011-11-29 18:15:50 +00001950template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001951_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001952typename _Cp::const_iterator
1953end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954{
1955 return __c.end();
1956}
1957
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001958#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001959
Marshall Clowef357272014-11-19 19:43:23 +00001960#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001961
1962// #if _LIBCPP_STD_VER > 11
1963// template <>
1964// struct _LIBCPP_TEMPLATE_VIS plus<void>
1965// {
1966// template <class _T1, class _T2>
1967// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1968// auto operator()(_T1&& __t, _T2&& __u) const
1969// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1970// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1971// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1972// typedef void is_transparent;
1973// };
1974// #endif
1975
Marshall Clowc4b4a342015-02-11 16:14:01 +00001976template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001977_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001978constexpr auto size(const _Cont& __c)
1979_NOEXCEPT_(noexcept(__c.size()))
1980-> decltype (__c.size())
1981{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001982
Marshall Clowc4b4a342015-02-11 16:14:01 +00001983template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001984_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001985constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001986
Marshall Clow3c5363e2019-02-27 02:58:56 +00001987#if _LIBCPP_STD_VER > 17
1988template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001989_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001990constexpr auto ssize(const _Cont& __c)
1991_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1992-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1993{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1994
1995template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001996_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001997constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1998#endif
1999
Marshall Clowc4b4a342015-02-11 16:14:01 +00002000template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00002001_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00002002constexpr auto empty(const _Cont& __c)
2003_NOEXCEPT_(noexcept(__c.empty()))
2004-> decltype (__c.empty())
2005{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00002006
Marshall Clowc4b4a342015-02-11 16:14:01 +00002007template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00002008_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00002009constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00002010
2011template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00002012_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00002013constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
2014
Marshall Clowc4b4a342015-02-11 16:14:01 +00002015template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00002016_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00002017auto data(_Cont& __c)
2018_NOEXCEPT_(noexcept(__c.data()))
2019-> decltype (__c.data())
2020{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00002021
Marshall Clowc4b4a342015-02-11 16:14:01 +00002022template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00002023_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00002024auto data(const _Cont& __c)
2025_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00002026-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00002027{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00002028
Marshall Clowc4b4a342015-02-11 16:14:01 +00002029template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00002030_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00002031constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00002032
2033template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00002034_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00002035constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
2036#endif
2037
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04002038template <class _Container, class _Predicate>
2039typename _Container::size_type
2040__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
2041 typename _Container::size_type __old_size = __c.size();
2042
2043 const typename _Container::iterator __last = __c.end();
2044 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
2045 if (__pred(*__iter))
2046 __iter = __c.erase(__iter);
2047 else
2048 ++__iter;
2049 }
2050
2051 return __old_size - __c.size();
2052}
Marshall Clowef357272014-11-19 19:43:23 +00002053
Howard Hinnantc51e1022010-05-11 19:42:16 +00002054_LIBCPP_END_NAMESPACE_STD
2055
2056#endif // _LIBCPP_ITERATOR