blob: 0b5c4eedca18028511ece8e444669c6893db43ac [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ITERATOR
11#define _LIBCPP_ITERATOR
12
13/*
14 iterator synopsis
15
Christopher Di Bella490fe402021-03-23 03:55:52 +000016#include <concepts>
17
Howard Hinnantc51e1022010-05-11 19:42:16 +000018namespace std
19{
Christopher Di Bellae00eebc2021-03-23 20:48:41 +000020template<class> struct incrementable_traits; // since C++20
Christopher Di Bellaa3a10062021-04-20 18:56:08 +000021template<class T>
22 using iter_difference_t = see below; // since C++20
23
Christopher Di Bellae00eebc2021-03-23 20:48:41 +000024template<class> struct indirectly_readable_traits; // since C++20
Christopher Di Bellaa3a10062021-04-20 18:56:08 +000025template<class T>
26 using iter_value_t = see below; // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000027
28template<class Iterator>
zoecarver9f1e2972021-04-20 08:50:11 -040029struct iterator_traits;
Howard Hinnantc51e1022010-05-11 19:42:16 +000030
31template<class T>
zoecarver9f1e2972021-04-20 08:50:11 -040032 requires is_object_v<T> // since C++20
33struct iterator_traits<T*>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000034
Christopher Di Bella875636f2021-04-04 05:12:46 +000035template<dereferenceable T>
36 using iter_reference_t = decltype(*declval<T&>());
37
Louis Dionneca989a52021-04-20 14:40:43 -040038namespace ranges::inline unspecified {
39 inline constexpr unspecified iter_move = unspecified; // since C++20, nodiscard as an extension
40}}
41
42template<dereferenceable T>
43 requires ...
44using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // since C++20
45
Louis Dionne463afb82021-04-22 11:05:30 -040046// [iterator.concepts], iterator concepts
47// [iterator.concept.readable], concept indirectly_readable
48template<class In>
Louis Dionne170a03c2021-04-28 15:02:08 -040049 concept indirectly_readable = see below; // since C++20
50
51template<indirectly_readable T>
52 using iter_common_reference_t =
53 common_reference_t<iter_reference_t<T>, iter_value_t<T>&>; // since C++20
Louis Dionne463afb82021-04-22 11:05:30 -040054
55// [iterator.concept.writable], concept indirectly_writable
56template<class Out, class T>
57 concept indirectly_writable = see below; // since C++20
58
Mark de Wever6639f422021-04-26 17:53:20 +020059// [iterator.concept.winc], concept weakly_incrementable
Christopher Di Bella54ffc182021-04-23 18:22:55 -070060template<class I>
61 concept weakly_incrementable = see below; // since C++20
62
63// [iterator.concept.inc], concept incrementable
64template<class I>
65 concept incrementable = see below; // since C++20
66
Mark de Wever6639f422021-04-26 17:53:20 +020067// [iterator.concept.iterator], concept input_or_output_iterator
Christopher Di Bella0ef52282021-04-09 02:10:32 +000068 template<class I>
69 concept input_or_output_iterator = see below; // since C++20
70
Mark de Wever6639f422021-04-26 17:53:20 +020071// [iterator.concept.sentinel], concept sentinel_for
Christopher Di Bella0ef52282021-04-09 02:10:32 +000072template<class S, class I>
73 concept sentinel_for = see below; // since C++20
74
zoecarver11391bc2021-04-26 09:35:47 -070075// [iterator.concept.sizedsentinel], concept sized_sentinel_for
76template<class S, class I>
77 inline constexpr bool disable_sized_sentinel_for = false;
78
79template<class S, class I>
80 concept sized_sentinel_for = see below;
81
Christopher Di Bella8250c632021-04-11 19:04:52 +000082// [iterator.concept.input], concept input_iterator
83template<class I>
84 concept input_iterator = see below; // since C++20
85
Christopher Di Bella8f1370d2021-04-11 22:11:03 +000086// [iterator.concept.forward], concept forward_iterator
87template<class I>
88 concept forward_iterator = see below; // since C++20
89
Christopher Di Bella10a31472021-04-12 01:16:45 +000090// [iterator.concept.bidir], concept bidirectional_iterator
91template<class I>
92 concept bidirectional_iterator = see below; // since C++20
93
zoecarver21da57e2021-04-23 17:11:44 -070094// [iterator.concept.random.access], concept random_access_iterator
95template<class I>
96 concept random_access_iterator = see below; // since C++20
97
Louis Dionne170a03c2021-04-28 15:02:08 -040098// [indirectcallable]
99// [indirectcallable.indirectinvocable]
100template<class F, class I>
101 concept indirectly_unary_invocable = see below; // since C++20
102
103template<class F, class I>
104 concept indirectly_regular_unary_invocable = see below; // since C++20
105
106template<class F, class I>
107 concept indirect_unary_predicate = see below; // since C++20
108
109template<class F, class I1, class I2>
110 concept indirect_binary_predicate = see below; // since C++20
111
112template<class F, class I1, class I2 = I1>
113 concept indirect_equivalence_relation = see below; // since C++20
114
115template<class F, class I1, class I2 = I1>
116 concept indirect_strict_weak_order = see below; // since C++20
117
118template<class F, class... Is>
119 using indirect_result_t = see below; // since C++20
120
121// [projected], projected
122template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
123 struct projected; // since C++20
124
125template<weakly_incrementable I, indirectly_regular_unary_invocable<I> Proj>
126 struct incrementable_traits<projected<I, Proj>>; // since C++20
127
zoecarver7e38f802021-05-17 10:30:12 -0700128// [alg.req.ind.move], concept indirectly_movable
129template<class In, class Out>
130 concept indirectly_movable = see below; // since C++20
131
132template<class In, class Out>
133 concept indirectly_movable_storable = see below; // since C++20
134
Howard Hinnantc51e1022010-05-11 19:42:16 +0000135template<class Category, class T, class Distance = ptrdiff_t,
136 class Pointer = T*, class Reference = T&>
Louis Dionne8762e2b2021-05-25 18:15:58 -0400137struct iterator // deprecated in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000138{
139 typedef T value_type;
140 typedef Distance difference_type;
141 typedef Pointer pointer;
142 typedef Reference reference;
143 typedef Category iterator_category;
144};
145
146struct input_iterator_tag {};
147struct output_iterator_tag {};
148struct forward_iterator_tag : public input_iterator_tag {};
149struct bidirectional_iterator_tag : public forward_iterator_tag {};
150struct random_access_iterator_tag : public bidirectional_iterator_tag {};
151
Marshall Clow75468e72017-05-17 18:51:36 +0000152// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -0400153template <class InputIterator, class Distance> // constexpr in C++17
154 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155
Marshall Clow75468e72017-05-17 18:51:36 +0000156template <class InputIterator> // constexpr in C++17
157 constexpr typename iterator_traits<InputIterator>::difference_type
158 distance(InputIterator first, InputIterator last);
159
160template <class InputIterator> // constexpr in C++17
161 constexpr InputIterator next(InputIterator x,
162typename iterator_traits<InputIterator>::difference_type n = 1);
163
164template <class BidirectionalIterator> // constexpr in C++17
165 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +0000166 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167
Christopher Di Bellac6ead652021-05-05 07:14:08 +0000168// [range.iter.ops], range iterator operations
169namespace ranges {
170 // [range.iter.op.advance], ranges::advance
171 template<input_or_output_iterator I>
172 constexpr void advance(I& i, iter_difference_t<I> n); // since C++20
173 template<input_or_output_iterator I, sentinel_for<I> S>
174 constexpr void advance(I& i, S bound); // since C++20
175 template<input_or_output_iterator I, sentinel_for<I> S>
176 constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound); // since C++20
177}
178
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179template <class Iterator>
180class reverse_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400181 : public iterator<typename iterator_traits<Iterator>::iterator_category, // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182 typename iterator_traits<Iterator>::value_type,
183 typename iterator_traits<Iterator>::difference_type,
184 typename iterator_traits<Iterator>::pointer,
185 typename iterator_traits<Iterator>::reference>
186{
187protected:
188 Iterator current;
189public:
190 typedef Iterator iterator_type;
191 typedef typename iterator_traits<Iterator>::difference_type difference_type;
192 typedef typename iterator_traits<Iterator>::reference reference;
193 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000194
Marshall Clow5ace5542016-10-19 15:12:50 +0000195 constexpr reverse_iterator();
196 constexpr explicit reverse_iterator(Iterator x);
197 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
198 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
199 constexpr Iterator base() const;
200 constexpr reference operator*() const;
201 constexpr pointer operator->() const;
202 constexpr reverse_iterator& operator++();
203 constexpr reverse_iterator operator++(int);
204 constexpr reverse_iterator& operator--();
205 constexpr reverse_iterator operator--(int);
206 constexpr reverse_iterator operator+ (difference_type n) const;
207 constexpr reverse_iterator& operator+=(difference_type n);
208 constexpr reverse_iterator operator- (difference_type n) const;
209 constexpr reverse_iterator& operator-=(difference_type n);
210 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000211};
212
213template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000214constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
216
217template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000218constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
220
221template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000222constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000223operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
224
225template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000226constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000227operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
228
229template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000230constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000231operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
232
233template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000234constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
236
237template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000238constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000239operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000240-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000241
242template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000243constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000244operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000245 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246
Marshall Clow5ace5542016-10-19 15:12:50 +0000247template <class Iterator>
248constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000249
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250template <class Container>
251class back_insert_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400252 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253{
254protected:
255 Container* container;
256public:
257 typedef Container container_type;
258 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400259 typedef void difference_type; // until C++20
260 typedef ptrdiff_t difference_type; // since C++20
Eric Fiselier9aeea872016-06-30 04:40:50 +0000261 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262 typedef void pointer;
263
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500264 explicit back_insert_iterator(Container& x); // constexpr in C++20
265 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
266 back_insert_iterator& operator*(); // constexpr in C++20
267 back_insert_iterator& operator++(); // constexpr in C++20
268 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000269};
270
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500271template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272
273template <class Container>
274class front_insert_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400275 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276{
277protected:
278 Container* container;
279public:
280 typedef Container container_type;
281 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400282 typedef void difference_type; // until C++20
283 typedef ptrdiff_t difference_type; // since C++20
Eric Fiselier9aeea872016-06-30 04:40:50 +0000284 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285 typedef void pointer;
286
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500287 explicit front_insert_iterator(Container& x); // constexpr in C++20
288 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
289 front_insert_iterator& operator*(); // constexpr in C++20
290 front_insert_iterator& operator++(); // constexpr in C++20
291 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292};
293
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500294template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295
296template <class Container>
297class insert_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400298 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299{
300protected:
301 Container* container;
302 typename Container::iterator iter;
303public:
304 typedef Container container_type;
305 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400306 typedef void difference_type; // until C++20
307 typedef ptrdiff_t difference_type; // since C++20
Eric Fiselier9aeea872016-06-30 04:40:50 +0000308 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309 typedef void pointer;
310
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500311 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
312 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
313 insert_iterator& operator*(); // constexpr in C++20
314 insert_iterator& operator++(); // constexpr in C++20
315 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316};
317
318template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500319insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000321template <class Iterator>
322class move_iterator {
323public:
324 typedef Iterator iterator_type;
325 typedef typename iterator_traits<Iterator>::difference_type difference_type;
326 typedef Iterator pointer;
327 typedef typename iterator_traits<Iterator>::value_type value_type;
328 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
329 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000330
Marshall Clowb5f99122016-11-02 15:30:26 +0000331 constexpr move_iterator(); // all the constexprs are in C++17
332 constexpr explicit move_iterator(Iterator i);
333 template <class U>
334 constexpr move_iterator(const move_iterator<U>& u);
335 template <class U>
336 constexpr move_iterator& operator=(const move_iterator<U>& u);
337 constexpr iterator_type base() const;
338 constexpr reference operator*() const;
339 constexpr pointer operator->() const;
340 constexpr move_iterator& operator++();
341 constexpr move_iterator operator++(int);
342 constexpr move_iterator& operator--();
343 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000344 constexpr move_iterator operator+(difference_type n) const;
345 constexpr move_iterator& operator+=(difference_type n);
346 constexpr move_iterator operator-(difference_type n) const;
347 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000348 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000349private:
350 Iterator current; // exposition only
351};
352
353template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000354constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000355operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
356
357template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000358constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000359operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
360
361template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000362constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000363operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
364
365template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000366constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000367operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
368
369template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000370constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000371operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
372
373template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000374constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000375operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
376
377template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000378constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000379operator-(const move_iterator<Iterator1>& x,
380 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
381
382template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000383constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000384 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000385 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000386
Marshall Clowb5f99122016-11-02 15:30:26 +0000387template <class Iterator> // constexpr in C++17
388constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000389
zoecarver63f13202021-06-01 12:55:33 -0700390// [default.sentinel], default sentinel
391struct default_sentinel_t;
392inline constexpr default_sentinel_t default_sentinel{};
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000393
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
395class istream_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400396 : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397{
398public:
Louis Dionne3402c3c2021-05-27 12:56:12 -0400399 typedef input_iterator_tag iterator_category;
400 typedef T value_type;
401 typedef Distance difference_type;
402 typedef const T* pointer;
403 typedef const T& reference;
404
405 typedef charT char_type;
406 typedef traits traits_type;
407 typedef basic_istream<charT, traits> istream_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408
Marshall Clow0735e4e2015-04-16 21:36:54 +0000409 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410 istream_iterator(istream_type& s);
411 istream_iterator(const istream_iterator& x);
412 ~istream_iterator();
413
414 const T& operator*() const;
415 const T* operator->() const;
416 istream_iterator& operator++();
417 istream_iterator operator++(int);
418};
419
420template <class T, class charT, class traits, class Distance>
421bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
422 const istream_iterator<T,charT,traits,Distance>& y);
423template <class T, class charT, class traits, class Distance>
424bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
425 const istream_iterator<T,charT,traits,Distance>& y);
426
427template <class T, class charT = char, class traits = char_traits<charT> >
428class ostream_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400429 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430{
431public:
Louis Dionne3402c3c2021-05-27 12:56:12 -0400432 typedef output_iterator_tag iterator_category;
433 typedef void value_type;
434 typedef void difference_type; // until C++20
435 typedef ptrdiff_t difference_type; // since C++20
436 typedef void pointer;
437 typedef void reference;
438
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439 typedef charT char_type;
440 typedef traits traits_type;
441 typedef basic_ostream<charT,traits> ostream_type;
442
443 ostream_iterator(ostream_type& s);
444 ostream_iterator(ostream_type& s, const charT* delimiter);
445 ostream_iterator(const ostream_iterator& x);
446 ~ostream_iterator();
447 ostream_iterator& operator=(const T& value);
448
449 ostream_iterator& operator*();
450 ostream_iterator& operator++();
451 ostream_iterator& operator++(int);
452};
453
454template<class charT, class traits = char_traits<charT> >
455class istreambuf_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400456 : public iterator<input_iterator_tag, charT, traits::off_type, unspecified, charT> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457{
458public:
Louis Dionne3402c3c2021-05-27 12:56:12 -0400459 typedef input_iterator_tag iterator_category;
460 typedef charT value_type;
461 typedef traits::off_type difference_type;
462 typedef unspecified pointer;
463 typedef charT reference;
464
465 typedef charT char_type;
466 typedef traits traits_type;
467 typedef traits::int_type int_type;
468 typedef basic_streambuf<charT, traits> streambuf_type;
469 typedef basic_istream<charT, traits> istream_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470
Howard Hinnant011138d2012-07-20 19:36:34 +0000471 istreambuf_iterator() noexcept;
472 istreambuf_iterator(istream_type& s) noexcept;
473 istreambuf_iterator(streambuf_type* s) noexcept;
474 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475
476 charT operator*() const;
477 pointer operator->() const;
478 istreambuf_iterator& operator++();
479 a-private-type operator++(int);
480
481 bool equal(const istreambuf_iterator& b) const;
482};
483
484template <class charT, class traits>
485bool operator==(const istreambuf_iterator<charT,traits>& a,
486 const istreambuf_iterator<charT,traits>& b);
487template <class charT, class traits>
488bool operator!=(const istreambuf_iterator<charT,traits>& a,
489 const istreambuf_iterator<charT,traits>& b);
490
491template <class charT, class traits = char_traits<charT> >
492class ostreambuf_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400493 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494{
495public:
Louis Dionne3402c3c2021-05-27 12:56:12 -0400496 typedef output_iterator_tag iterator_category;
497 typedef void value_type;
498 typedef void difference_type; // until C++20
499 typedef ptrdiff_t difference_type; // since C++20
500 typedef void pointer;
501 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502
Louis Dionne3402c3c2021-05-27 12:56:12 -0400503 typedef charT char_type;
504 typedef traits traits_type;
505 typedef basic_streambuf<charT, traits> streambuf_type;
506 typedef basic_ostream<charT, traits> ostream_type;
507
Howard Hinnant011138d2012-07-20 19:36:34 +0000508 ostreambuf_iterator(ostream_type& s) noexcept;
509 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510 ostreambuf_iterator& operator=(charT c);
511 ostreambuf_iterator& operator*();
512 ostreambuf_iterator& operator++();
513 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000514 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515};
516
Marshall Clow99ba0022017-01-04 17:58:17 +0000517template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
518template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
519template <class C> constexpr auto end(C& c) -> decltype(c.end());
520template <class C> constexpr auto end(const C& c) -> decltype(c.end());
521template <class T, size_t N> constexpr T* begin(T (&array)[N]);
522template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523
Marshall Clow99ba0022017-01-04 17:58:17 +0000524template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
525template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
526template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
527template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
528template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
529template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
530template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
531template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
532template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
533template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
534template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
535template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000536
Marshall Clowef357272014-11-19 19:43:23 +0000537// 24.8, container access:
538template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
539template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000540
541template <class C> constexpr auto ssize(const C& c)
Arthur O'Dwyer2fc9b5d2021-04-17 17:03:20 -0400542 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
Marshall Clow3c5363e2019-02-27 02:58:56 +0000543template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
544
Marshall Clowef357272014-11-19 19:43:23 +0000545template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
546template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
547template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
548template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
549template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
550template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
551template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
552
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553} // std
554
555*/
556
557#include <__config>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400558#include <__debug>
Marshall Clow3dc05502014-02-27 02:11:50 +0000559#include <__functional_base>
Christopher Di Bellac6ead652021-05-05 07:14:08 +0000560#include <__iterator/advance.h>
Louis Dionne463afb82021-04-22 11:05:30 -0400561#include <__iterator/concepts.h>
zoecarver63f13202021-06-01 12:55:33 -0700562#include <__iterator/default_sentinel.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400563#include <__iterator/incrementable_traits.h>
Louis Dionneca989a52021-04-20 14:40:43 -0400564#include <__iterator/iter_move.h>
zoecarver31f4f5d2021-05-18 16:18:18 -0700565#include <__iterator/iter_swap.h>
zoecarver5d41ff52021-04-19 14:44:42 -0700566#include <__iterator/iterator_traits.h>
Christopher Di Bella9c0adab2021-05-08 05:02:43 +0000567#include <__iterator/next.h>
Christopher Di Bellab8e21042021-05-16 01:39:22 +0000568#include <__iterator/prev.h>
Louis Dionne170a03c2021-04-28 15:02:08 -0400569#include <__iterator/projected.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400570#include <__iterator/readable_traits.h>
Louis Dionne735bc462021-04-14 13:59:03 -0400571#include <__memory/addressof.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500572#include <__memory/pointer_traits.h>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400573#include <compare>
574#include <concepts> // Mandated by the Standard.
575#include <cstddef>
576#include <initializer_list>
577#include <iosfwd> // for forward declarations of vector and string
578#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000579#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000580
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000581#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000583#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584
585_LIBCPP_BEGIN_NAMESPACE_STD
Christopher Di Bella490fe402021-03-23 03:55:52 +0000586
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587template<class _Category, class _Tp, class _Distance = ptrdiff_t,
588 class _Pointer = _Tp*, class _Reference = _Tp&>
Louis Dionne8762e2b2021-05-25 18:15:58 -0400589struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590{
591 typedef _Tp value_type;
592 typedef _Distance difference_type;
593 typedef _Pointer pointer;
594 typedef _Reference reference;
595 typedef _Category iterator_category;
596};
597
598template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000599inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600typename iterator_traits<_InputIter>::difference_type
601__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
602{
603 typename iterator_traits<_InputIter>::difference_type __r(0);
604 for (; __first != __last; ++__first)
605 ++__r;
606 return __r;
607}
608
609template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000610inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611typename iterator_traits<_RandIter>::difference_type
612__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
613{
614 return __last - __first;
615}
616
617template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000618inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619typename iterator_traits<_InputIter>::difference_type
620distance(_InputIter __first, _InputIter __last)
621{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500622 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000623}
624
Eric Fiselier883af112017-04-13 02:54:13 +0000625template <class _Tp, class = void>
626struct __is_stashing_iterator : false_type {};
627
628template <class _Tp>
629struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
630 : true_type {};
631
Louis Dionne8762e2b2021-05-25 18:15:58 -0400632_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000634class _LIBCPP_TEMPLATE_VIS reverse_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400635#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636 : public iterator<typename iterator_traits<_Iter>::iterator_category,
637 typename iterator_traits<_Iter>::value_type,
638 typename iterator_traits<_Iter>::difference_type,
639 typename iterator_traits<_Iter>::pointer,
640 typename iterator_traits<_Iter>::reference>
Louis Dionne8762e2b2021-05-25 18:15:58 -0400641#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400643_LIBCPP_SUPPRESS_DEPRECATED_POP
Marshall Clow0ad029e2014-03-11 22:05:31 +0000644private:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400645#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
646 _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
647#endif
Eric Fiselier883af112017-04-13 02:54:13 +0000648
649 static_assert(!__is_stashing_iterator<_Iter>::value,
650 "The specified iterator type cannot be used with reverse_iterator; "
651 "Using stashing iterators with reverse_iterator causes undefined behavior");
652
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000653protected:
654 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655public:
656 typedef _Iter iterator_type;
657 typedef typename iterator_traits<_Iter>::difference_type difference_type;
658 typedef typename iterator_traits<_Iter>::reference reference;
659 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500660 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
661 random_access_iterator_tag,
662 typename iterator_traits<_Iter>::iterator_category> iterator_category;
Louis Dionne8762e2b2021-05-25 18:15:58 -0400663 typedef typename iterator_traits<_Iter>::value_type value_type;
664
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500665#if _LIBCPP_STD_VER > 17
666 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
667 random_access_iterator_tag,
668 bidirectional_iterator_tag> iterator_concept;
669#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000670
Louis Dionne8762e2b2021-05-25 18:15:58 -0400671#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
Marshall Clow5ace5542016-10-19 15:12:50 +0000672 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
673 reverse_iterator() : __t(), current() {}
Louis Dionne130f0f92021-06-03 14:14:57 -0400674
Marshall Clow5ace5542016-10-19 15:12:50 +0000675 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
676 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
Louis Dionne130f0f92021-06-03 14:14:57 -0400677
678 template <class _Up, class = _EnableIf<
679 !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
680 > >
681 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
682 reverse_iterator(const reverse_iterator<_Up>& __u)
683 : __t(__u.base()), current(__u.base())
684 { }
685
686 template <class _Up, class = _EnableIf<
687 !is_same<_Up, _Iter>::value &&
688 is_convertible<_Up const&, _Iter>::value &&
689 is_assignable<_Up const&, _Iter>::value
690 > >
691 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
692 reverse_iterator& operator=(const reverse_iterator<_Up>& __u) {
693 __t = current = __u.base();
694 return *this;
695 }
Louis Dionne8762e2b2021-05-25 18:15:58 -0400696#else
697 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
698 reverse_iterator() : current() {}
Louis Dionne130f0f92021-06-03 14:14:57 -0400699
Louis Dionne8762e2b2021-05-25 18:15:58 -0400700 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
701 explicit reverse_iterator(_Iter __x) : current(__x) {}
Louis Dionne130f0f92021-06-03 14:14:57 -0400702
703 template <class _Up, class = _EnableIf<
704 !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
705 > >
706 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
707 reverse_iterator(const reverse_iterator<_Up>& __u)
708 : current(__u.base())
709 { }
710
711 template <class _Up, class = _EnableIf<
712 !is_same<_Up, _Iter>::value &&
713 is_convertible<_Up const&, _Iter>::value &&
714 is_assignable<_Up const&, _Iter>::value
715 > >
716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
717 reverse_iterator& operator=(const reverse_iterator<_Up>& __u) {
718 current = __u.base();
719 return *this;
720 }
Louis Dionne8762e2b2021-05-25 18:15:58 -0400721#endif
Marshall Clow5ace5542016-10-19 15:12:50 +0000722 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
723 _Iter base() const {return current;}
724 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
725 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
726 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
727 pointer operator->() const {return _VSTD::addressof(operator*());}
728 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
729 reverse_iterator& operator++() {--current; return *this;}
730 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
731 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
732 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
733 reverse_iterator& operator--() {++current; return *this;}
734 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
735 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
736 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
737 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
738 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
739 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
740 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
741 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
742 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
743 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
744 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
745 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746};
747
748template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000749inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750bool
751operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
752{
753 return __x.base() == __y.base();
754}
755
756template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000757inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758bool
759operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
760{
761 return __x.base() > __y.base();
762}
763
764template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000765inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766bool
767operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
768{
769 return __x.base() != __y.base();
770}
771
772template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000773inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774bool
775operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
776{
777 return __x.base() < __y.base();
778}
779
780template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000781inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782bool
783operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
784{
785 return __x.base() <= __y.base();
786}
787
788template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000789inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790bool
791operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
792{
793 return __x.base() >= __y.base();
794}
795
Marshall Clow476d3f42016-07-18 13:19:00 +0000796#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000797template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000798inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000799auto
800operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
801-> decltype(__y.base() - __x.base())
802{
803 return __y.base() - __x.base();
804}
805#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806template <class _Iter1, class _Iter2>
807inline _LIBCPP_INLINE_VISIBILITY
808typename reverse_iterator<_Iter1>::difference_type
809operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
810{
811 return __y.base() - __x.base();
812}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000813#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814
815template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000816inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817reverse_iterator<_Iter>
818operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
819{
820 return reverse_iterator<_Iter>(__x.base() - __n);
821}
822
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000823#if _LIBCPP_STD_VER > 11
824template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000825inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000826reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
827{
828 return reverse_iterator<_Iter>(__i);
829}
830#endif
831
Louis Dionne8762e2b2021-05-25 18:15:58 -0400832_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000834class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400835#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
836 : public iterator<output_iterator_tag, void, void, void, void>
837#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400839_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840protected:
841 _Container* container;
842public:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400843 typedef output_iterator_tag iterator_category;
844 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400845#if _LIBCPP_STD_VER > 17
846 typedef ptrdiff_t difference_type;
847#else
Louis Dionne8762e2b2021-05-25 18:15:58 -0400848 typedef void difference_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400849#endif
Louis Dionne8762e2b2021-05-25 18:15:58 -0400850 typedef void pointer;
851 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852 typedef _Container container_type;
853
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500854 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
855 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000856 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000857#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500858 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000859 {container->push_back(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400860#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500861 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
862 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
863 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864};
865
866template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500867inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868back_insert_iterator<_Container>
869back_inserter(_Container& __x)
870{
871 return back_insert_iterator<_Container>(__x);
872}
873
Louis Dionne8762e2b2021-05-25 18:15:58 -0400874_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000876class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400877#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
878 : public iterator<output_iterator_tag, void, void, void, void>
879#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400881_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882protected:
883 _Container* container;
884public:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400885 typedef output_iterator_tag iterator_category;
886 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400887#if _LIBCPP_STD_VER > 17
888 typedef ptrdiff_t difference_type;
889#else
Louis Dionne8762e2b2021-05-25 18:15:58 -0400890 typedef void difference_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400891#endif
Louis Dionne8762e2b2021-05-25 18:15:58 -0400892 typedef void pointer;
893 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894 typedef _Container container_type;
895
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500896 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
897 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000898 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000899#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500900 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000901 {container->push_front(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400902#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500903 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
904 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
905 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906};
907
908template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500909inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910front_insert_iterator<_Container>
911front_inserter(_Container& __x)
912{
913 return front_insert_iterator<_Container>(__x);
914}
915
Louis Dionne8762e2b2021-05-25 18:15:58 -0400916_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000918class _LIBCPP_TEMPLATE_VIS insert_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400919#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
920 : public iterator<output_iterator_tag, void, void, void, void>
921#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400923_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924protected:
925 _Container* container;
Christopher Di Bella92072c22021-05-14 06:20:07 +0000926 typename _Container::iterator iter; // FIXME: `ranges::iterator_t<Container>` in C++20 mode
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927public:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400928 typedef output_iterator_tag iterator_category;
929 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400930#if _LIBCPP_STD_VER > 17
931 typedef ptrdiff_t difference_type;
932#else
Louis Dionne8762e2b2021-05-25 18:15:58 -0400933 typedef void difference_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400934#endif
Louis Dionne8762e2b2021-05-25 18:15:58 -0400935 typedef void pointer;
936 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937 typedef _Container container_type;
938
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500939 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000940 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500941 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000942 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000943#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500944 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000945 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400946#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500947 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
948 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
949 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950};
951
952template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500953inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954insert_iterator<_Container>
955inserter(_Container& __x, typename _Container::iterator __i)
956{
957 return insert_iterator<_Container>(__x, __i);
958}
959
Louis Dionne8762e2b2021-05-25 18:15:58 -0400960_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961template <class _Tp, class _CharT = char,
962 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000963class _LIBCPP_TEMPLATE_VIS istream_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400964#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
Louis Dionne8762e2b2021-05-25 18:15:58 -0400966#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000967{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400968_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969public:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400970 typedef input_iterator_tag iterator_category;
971 typedef _Tp value_type;
972 typedef _Distance difference_type;
973 typedef const _Tp* pointer;
974 typedef const _Tp& reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975 typedef _CharT char_type;
976 typedef _Traits traits_type;
977 typedef basic_istream<_CharT,_Traits> istream_type;
978private:
979 istream_type* __in_stream_;
980 _Tp __value_;
981public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500982 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000983 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 {
985 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500986 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 }
988
989 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000990 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
992 {
993 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500994 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995 return *this;
996 }
997 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
998 {istream_iterator __t(*this); ++(*this); return __t;}
999
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001000 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001002 bool
1003 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
1004 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001006 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001008 bool
1009 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
1010 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011};
1012
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001013template <class _Tp, class _CharT, class _Traits, class _Distance>
1014inline _LIBCPP_INLINE_VISIBILITY
1015bool
1016operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
1017 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
1018{
1019 return __x.__in_stream_ == __y.__in_stream_;
1020}
1021
1022template <class _Tp, class _CharT, class _Traits, class _Distance>
1023inline _LIBCPP_INLINE_VISIBILITY
1024bool
1025operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
1026 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
1027{
1028 return !(__x == __y);
1029}
1030
Louis Dionne8762e2b2021-05-25 18:15:58 -04001031_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001033class _LIBCPP_TEMPLATE_VIS ostream_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -04001034#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035 : public iterator<output_iterator_tag, void, void, void, void>
Louis Dionne8762e2b2021-05-25 18:15:58 -04001036#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001037{
Louis Dionne8762e2b2021-05-25 18:15:58 -04001038_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001040 typedef output_iterator_tag iterator_category;
1041 typedef void value_type;
1042#if _LIBCPP_STD_VER > 17
Louis Dionne3402c3c2021-05-27 12:56:12 -04001043 typedef ptrdiff_t difference_type;
Louis Dionnea4d79522020-09-11 10:15:56 -04001044#else
1045 typedef void difference_type;
1046#endif
1047 typedef void pointer;
1048 typedef void reference;
1049 typedef _CharT char_type;
1050 typedef _Traits traits_type;
1051 typedef basic_ostream<_CharT, _Traits> ostream_type;
1052
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053private:
1054 ostream_type* __out_stream_;
1055 const char_type* __delim_;
1056public:
Marshall Clow27a89512016-10-12 16:13:48 +00001057 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -05001058 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +00001059 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +00001060 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +00001061 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062 {
Howard Hinnantbf074022011-10-22 20:59:45 +00001063 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064 if (__delim_)
1065 *__out_stream_ << __delim_;
1066 return *this;
1067 }
1068
1069 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
1070 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
1071 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
1072};
1073
Louis Dionne8762e2b2021-05-25 18:15:58 -04001074_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001076class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -04001077#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078 : public iterator<input_iterator_tag, _CharT,
1079 typename _Traits::off_type, _CharT*,
1080 _CharT>
Louis Dionne8762e2b2021-05-25 18:15:58 -04001081#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082{
Louis Dionne8762e2b2021-05-25 18:15:58 -04001083_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084public:
Louis Dionne8762e2b2021-05-25 18:15:58 -04001085 typedef input_iterator_tag iterator_category;
1086 typedef _CharT value_type;
1087 typedef typename _Traits::off_type difference_type;
1088 typedef _CharT* pointer;
1089 typedef _CharT reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090 typedef _CharT char_type;
1091 typedef _Traits traits_type;
1092 typedef typename _Traits::int_type int_type;
1093 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1094 typedef basic_istream<_CharT,_Traits> istream_type;
1095private:
Howard Hinnant3e57b272012-11-16 22:17:23 +00001096 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001097
1098 class __proxy
1099 {
1100 char_type __keep_;
1101 streambuf_type* __sbuf_;
1102 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
1103 : __keep_(__c), __sbuf_(__s) {}
1104 friend class istreambuf_iterator;
1105 public:
1106 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
1107 };
1108
Howard Hinnant756c69b2010-09-22 16:48:34 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +00001110 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111 {
1112 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001113 __sbuf_ = nullptr;
1114 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115 }
1116public:
Bruce Mitchener170d8972020-11-24 12:53:53 -05001117 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001118 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001119 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001120 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001121 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001122 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123 : __sbuf_(__p.__sbuf_) {}
1124
Howard Hinnant28b24882011-12-01 20:21:04 +00001125 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1126 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1128 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001129 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130 return *this;
1131 }
1132 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1133 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001134 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001135 }
1136
1137 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001138 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139};
1140
1141template <class _CharT, class _Traits>
1142inline _LIBCPP_INLINE_VISIBILITY
1143bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1144 const istreambuf_iterator<_CharT,_Traits>& __b)
1145 {return __a.equal(__b);}
1146
1147template <class _CharT, class _Traits>
1148inline _LIBCPP_INLINE_VISIBILITY
1149bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1150 const istreambuf_iterator<_CharT,_Traits>& __b)
1151 {return !__a.equal(__b);}
1152
Louis Dionne8762e2b2021-05-25 18:15:58 -04001153_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001154template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001155class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -04001156#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001157 : public iterator<output_iterator_tag, void, void, void, void>
Louis Dionne8762e2b2021-05-25 18:15:58 -04001158#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159{
Louis Dionne8762e2b2021-05-25 18:15:58 -04001160_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001161public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001162 typedef output_iterator_tag iterator_category;
1163 typedef void value_type;
1164#if _LIBCPP_STD_VER > 17
Louis Dionne3402c3c2021-05-27 12:56:12 -04001165 typedef ptrdiff_t difference_type;
Louis Dionnea4d79522020-09-11 10:15:56 -04001166#else
1167 typedef void difference_type;
1168#endif
1169 typedef void pointer;
1170 typedef void reference;
1171 typedef _CharT char_type;
1172 typedef _Traits traits_type;
1173 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1174 typedef basic_ostream<_CharT, _Traits> ostream_type;
1175
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176private:
1177 streambuf_type* __sbuf_;
1178public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001179 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001181 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182 : __sbuf_(__s) {}
1183 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1184 {
1185 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001186 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001187 return *this;
1188 }
1189 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1190 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1191 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001192 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001193
1194 template <class _Ch, class _Tr>
1195 friend
1196 _LIBCPP_HIDDEN
1197 ostreambuf_iterator<_Ch, _Tr>
1198 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1199 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1200 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001201};
1202
1203template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001204class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001205{
1206private:
1207 _Iter __i;
1208public:
1209 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210 typedef typename iterator_traits<iterator_type>::value_type value_type;
1211 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001212 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001213 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1214 random_access_iterator_tag,
1215 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1216#if _LIBCPP_STD_VER > 17
1217 typedef input_iterator_tag iterator_concept;
1218#endif
1219
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001220#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001221 typedef typename iterator_traits<iterator_type>::reference __reference;
1222 typedef typename conditional<
1223 is_reference<__reference>::value,
1224 typename remove_reference<__reference>::type&&,
1225 __reference
1226 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227#else
1228 typedef typename iterator_traits<iterator_type>::reference reference;
1229#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001230
Marshall Clowb5f99122016-11-02 15:30:26 +00001231 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1232 move_iterator() : __i() {}
Louis Dionne130f0f92021-06-03 14:14:57 -04001233
Marshall Clowb5f99122016-11-02 15:30:26 +00001234 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1235 explicit move_iterator(_Iter __x) : __i(__x) {}
Louis Dionne130f0f92021-06-03 14:14:57 -04001236
1237 template <class _Up, class = _EnableIf<
1238 !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
1239 > >
1240 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1241 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1242
1243 template <class _Up, class = _EnableIf<
1244 !is_same<_Up, _Iter>::value &&
1245 is_convertible<_Up const&, _Iter>::value &&
1246 is_assignable<_Iter&, _Up const&>::value
1247 > >
1248 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1249 move_iterator& operator=(const move_iterator<_Up>& __u) {
1250 __i = __u.base();
1251 return *this;
1252 }
1253
Marshall Clowb5f99122016-11-02 15:30:26 +00001254 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001255 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001256 reference operator*() const { return static_cast<reference>(*__i); }
1257 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1258 pointer operator->() const { return __i;}
1259 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1260 move_iterator& operator++() {++__i; return *this;}
1261 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1262 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1263 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1264 move_iterator& operator--() {--__i; return *this;}
1265 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1266 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1267 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1268 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1269 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1270 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1271 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1272 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1273 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1274 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1275 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1276 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277};
1278
1279template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001280inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281bool
1282operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1283{
1284 return __x.base() == __y.base();
1285}
1286
1287template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001288inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289bool
1290operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1291{
1292 return __x.base() < __y.base();
1293}
1294
1295template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001296inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297bool
1298operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1299{
1300 return __x.base() != __y.base();
1301}
1302
1303template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001304inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305bool
1306operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1307{
1308 return __x.base() > __y.base();
1309}
1310
1311template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001312inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313bool
1314operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1315{
1316 return __x.base() >= __y.base();
1317}
1318
1319template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001320inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321bool
1322operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1323{
1324 return __x.base() <= __y.base();
1325}
1326
Marshall Clow476d3f42016-07-18 13:19:00 +00001327#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001328template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001329inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001330auto
1331operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1332-> decltype(__x.base() - __y.base())
1333{
1334 return __x.base() - __y.base();
1335}
1336#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337template <class _Iter1, class _Iter2>
1338inline _LIBCPP_INLINE_VISIBILITY
1339typename move_iterator<_Iter1>::difference_type
1340operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1341{
1342 return __x.base() - __y.base();
1343}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001344#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001345
1346template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001347inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001348move_iterator<_Iter>
1349operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1350{
1351 return move_iterator<_Iter>(__x.base() + __n);
1352}
1353
1354template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001355inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001356move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001357make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001358{
1359 return move_iterator<_Iter>(__i);
1360}
1361
1362// __wrap_iter
1363
1364template <class _Iter> class __wrap_iter;
1365
1366template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001367_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001369operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370
1371template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001372_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001374operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375
1376template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001377_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001379operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380
1381template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001382_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001383bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001384operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001385
1386template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001387_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001388bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001389operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001390
1391template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001392_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001394operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395
Marshall Clow476d3f42016-07-18 13:19:00 +00001396#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001397template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001398_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001399auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001400operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001401-> decltype(__x.base() - __y.base());
1402#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001403template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001404_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001405typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001406operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001407#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001408
1409template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001410_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001412operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001413
Louis Dionne65b433b2019-11-06 12:02:41 +00001414template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1415template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001416template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1417template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001418
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419template <class _Iter>
1420class __wrap_iter
1421{
1422public:
1423 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424 typedef typename iterator_traits<iterator_type>::value_type value_type;
1425 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1426 typedef typename iterator_traits<iterator_type>::pointer pointer;
1427 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001428 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1429#if _LIBCPP_STD_VER > 17
Arthur O'Dwyer6eb8a5d2021-05-19 11:54:31 -04001430 typedef contiguous_iterator_tag iterator_concept;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001431#endif
1432
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433private:
1434 iterator_type __i;
1435public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001436 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001437#if _LIBCPP_STD_VER > 11
1438 : __i{}
1439#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001440 {
Louis Dionneba400782020-10-02 15:02:52 -04001441#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001442 __get_db()->__insert_i(this);
1443#endif
1444 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001445 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1446 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001447 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001448 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001449 {
Louis Dionneba400782020-10-02 15:02:52 -04001450#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001451 __get_db()->__iterator_copy(this, &__u);
1452#endif
1453 }
Louis Dionneba400782020-10-02 15:02:52 -04001454#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001455 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001456 __wrap_iter(const __wrap_iter& __x)
1457 : __i(__x.base())
1458 {
1459 __get_db()->__iterator_copy(this, &__x);
1460 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001461 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001462 __wrap_iter& operator=(const __wrap_iter& __x)
1463 {
1464 if (this != &__x)
1465 {
1466 __get_db()->__iterator_copy(this, &__x);
1467 __i = __x.__i;
1468 }
1469 return *this;
1470 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001471 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001472 ~__wrap_iter()
1473 {
1474 __get_db()->__erase_i(this);
1475 }
1476#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001477 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001478 {
Louis Dionneba400782020-10-02 15:02:52 -04001479#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001480 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1481 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001482#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001483 return *__i;
1484 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001485 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001486 {
Louis Dionneba400782020-10-02 15:02:52 -04001487#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001488 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1489 "Attempted to dereference a non-dereferenceable iterator");
1490#endif
Louis Dionne1c8315b2021-05-04 18:51:58 -04001491 return _VSTD::__to_address(__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001492 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001493 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001494 {
Louis Dionneba400782020-10-02 15:02:52 -04001495#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001496 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001497 "Attempted to increment a non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001498#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001499 ++__i;
1500 return *this;
1501 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001502 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001503 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001504
Eric Fiselier873b8d32019-03-18 21:50:12 +00001505 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001506 {
Louis Dionneba400782020-10-02 15:02:52 -04001507#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001508 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001509 "Attempted to decrement a non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001510#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001511 --__i;
1512 return *this;
1513 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001514 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001515 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001516 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001517 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001518 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001519 {
Louis Dionneba400782020-10-02 15:02:52 -04001520#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001521 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001522 "Attempted to add/subtract an iterator outside its valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001523#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001524 __i += __n;
1525 return *this;
1526 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001527 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001528 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001529 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001530 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001531 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001532 {
Louis Dionneba400782020-10-02 15:02:52 -04001533#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001534 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001535 "Attempted to subscript an iterator outside its valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001536#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001537 return __i[__n];
1538 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539
Eric Fiselier873b8d32019-03-18 21:50:12 +00001540 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001541
1542private:
Louis Dionneba400782020-10-02 15:02:52 -04001543#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001544 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001545 {
1546 __get_db()->__insert_ic(this, __p);
1547 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001548#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001549 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001550#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551
1552 template <class _Up> friend class __wrap_iter;
1553 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001554 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001555 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001556
1557 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001558 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001559 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001560 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001561
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001563 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001564 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001565 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001566
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001568 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001570 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001571
Howard Hinnantc51e1022010-05-11 19:42:16 +00001572 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001573 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001575 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001576
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001578 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001579 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001580 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001581
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001583 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001585 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001586
Marshall Clow476d3f42016-07-18 13:19:00 +00001587#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001588 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001589 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001590 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001591 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001592 -> decltype(__x.base() - __y.base());
1593#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001594 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001595 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001596 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001597 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001598#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001599
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001601 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001603 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604};
1605
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001606#if _LIBCPP_STD_VER <= 17
1607template <class _It>
Arthur O'Dwyer6eb8a5d2021-05-19 11:54:31 -04001608struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001609#endif
1610
1611template <class _Iter>
1612_LIBCPP_CONSTEXPR
Arthur O'Dwyer6eb8a5d2021-05-19 11:54:31 -04001613decltype(_VSTD::__to_address(declval<_Iter>()))
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001614__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1615 return _VSTD::__to_address(__w.base());
1616}
1617
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001619inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001621operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001622{
1623 return __x.base() == __y.base();
1624}
1625
1626template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001627inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001628bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001629operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001630{
Louis Dionneba400782020-10-02 15:02:52 -04001631#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001632 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001633 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001634#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635 return __x.base() < __y.base();
1636}
1637
1638template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001639inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001641operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001643 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644}
1645
1646template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001647inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001648bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001649operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001650{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001651 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001652}
1653
1654template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001655inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001656bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001657operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001659 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001660}
1661
1662template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001663inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001665operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001667 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001668}
1669
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001670template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001671inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001672bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001673operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001674{
1675 return !(__x == __y);
1676}
1677
1678template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001679inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001680bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001681operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001682{
1683 return __y < __x;
1684}
1685
1686template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001687inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001688bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001689operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001690{
1691 return !(__x < __y);
1692}
1693
1694template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001695inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001696bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001697operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001698{
1699 return !(__y < __x);
1700}
1701
Marshall Clow476d3f42016-07-18 13:19:00 +00001702#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001703template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001704inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001705auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001706operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001707-> decltype(__x.base() - __y.base())
1708{
Louis Dionneba400782020-10-02 15:02:52 -04001709#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001710 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1711 "Attempted to subtract incompatible iterators");
1712#endif
1713 return __x.base() - __y.base();
1714}
1715#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001716template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001717inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001718typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001719operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001720{
Louis Dionneba400782020-10-02 15:02:52 -04001721#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001722 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001723 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001724#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001725 return __x.base() - __y.base();
1726}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001727#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001728
1729template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001730inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001731__wrap_iter<_Iter>
1732operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001733 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001735 __x += __n;
1736 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001737}
1738
Marshall Clow8411ebf2013-12-02 03:24:33 +00001739template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001740_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001741_Tp*
1742begin(_Tp (&__array)[_Np])
1743{
1744 return __array;
1745}
1746
1747template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001748_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001749_Tp*
1750end(_Tp (&__array)[_Np])
1751{
1752 return __array + _Np;
1753}
1754
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001755#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001756
Howard Hinnantc834c512011-11-29 18:15:50 +00001757template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001758_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001759auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001760begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001761{
1762 return __c.begin();
1763}
1764
Howard Hinnantc834c512011-11-29 18:15:50 +00001765template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001766_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001767auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001768begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769{
1770 return __c.begin();
1771}
1772
Howard Hinnantc834c512011-11-29 18:15:50 +00001773template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001774_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001775auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001776end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001777{
1778 return __c.end();
1779}
1780
Howard Hinnantc834c512011-11-29 18:15:50 +00001781template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001782_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001783auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001784end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001785{
1786 return __c.end();
1787}
1788
Marshall Clowb278e9c2013-08-30 01:17:07 +00001789#if _LIBCPP_STD_VER > 11
1790
Marshall Clow8411ebf2013-12-02 03:24:33 +00001791template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001792_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001793reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1794{
1795 return reverse_iterator<_Tp*>(__array + _Np);
1796}
1797
1798template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001799_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001800reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1801{
1802 return reverse_iterator<_Tp*>(__array);
1803}
1804
1805template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001806_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001807reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1808{
1809 return reverse_iterator<const _Ep*>(__il.end());
1810}
1811
1812template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001813_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001814reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1815{
1816 return reverse_iterator<const _Ep*>(__il.begin());
1817}
1818
Marshall Clowb278e9c2013-08-30 01:17:07 +00001819template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001820_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001821auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001822{
Marshall Clow3862f532016-08-10 20:04:46 +00001823 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001824}
1825
1826template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001827_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001828auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001829{
Marshall Clow3862f532016-08-10 20:04:46 +00001830 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001831}
1832
1833template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001834_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001835auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1836{
1837 return __c.rbegin();
1838}
1839
1840template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001841_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001842auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1843{
1844 return __c.rbegin();
1845}
1846
1847template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001848_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001849auto rend(_Cp& __c) -> decltype(__c.rend())
1850{
1851 return __c.rend();
1852}
1853
1854template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001855_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001856auto rend(const _Cp& __c) -> decltype(__c.rend())
1857{
1858 return __c.rend();
1859}
1860
1861template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001862_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001863auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001864{
Marshall Clow3862f532016-08-10 20:04:46 +00001865 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001866}
1867
1868template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001869_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001870auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001871{
Marshall Clow3862f532016-08-10 20:04:46 +00001872 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001873}
1874
1875#endif
1876
1877
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001878#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879
Howard Hinnantc834c512011-11-29 18:15:50 +00001880template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001881_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001882typename _Cp::iterator
1883begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001884{
1885 return __c.begin();
1886}
1887
Howard Hinnantc834c512011-11-29 18:15:50 +00001888template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001889_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001890typename _Cp::const_iterator
1891begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001892{
1893 return __c.begin();
1894}
1895
Howard Hinnantc834c512011-11-29 18:15:50 +00001896template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001897_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001898typename _Cp::iterator
1899end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001900{
1901 return __c.end();
1902}
1903
Howard Hinnantc834c512011-11-29 18:15:50 +00001904template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001905_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001906typename _Cp::const_iterator
1907end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001908{
1909 return __c.end();
1910}
1911
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001912#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001913
Marshall Clowef357272014-11-19 19:43:23 +00001914#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001915
1916// #if _LIBCPP_STD_VER > 11
1917// template <>
1918// struct _LIBCPP_TEMPLATE_VIS plus<void>
1919// {
1920// template <class _T1, class _T2>
1921// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1922// auto operator()(_T1&& __t, _T2&& __u) const
1923// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1924// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1925// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1926// typedef void is_transparent;
1927// };
1928// #endif
1929
Marshall Clowc4b4a342015-02-11 16:14:01 +00001930template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001931_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001932constexpr auto size(const _Cont& __c)
1933_NOEXCEPT_(noexcept(__c.size()))
1934-> decltype (__c.size())
1935{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001936
Marshall Clowc4b4a342015-02-11 16:14:01 +00001937template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001938_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001939constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001940
Marshall Clow3c5363e2019-02-27 02:58:56 +00001941#if _LIBCPP_STD_VER > 17
1942template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001943_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001944constexpr auto ssize(const _Cont& __c)
1945_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1946-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1947{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1948
1949template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001950_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001951constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1952#endif
1953
Marshall Clowc4b4a342015-02-11 16:14:01 +00001954template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001955_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001956constexpr auto empty(const _Cont& __c)
1957_NOEXCEPT_(noexcept(__c.empty()))
1958-> decltype (__c.empty())
1959{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001960
Marshall Clowc4b4a342015-02-11 16:14:01 +00001961template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001962_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001963constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001964
1965template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001966_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001967constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1968
Marshall Clowc4b4a342015-02-11 16:14:01 +00001969template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001970_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001971auto data(_Cont& __c)
1972_NOEXCEPT_(noexcept(__c.data()))
1973-> decltype (__c.data())
1974{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001975
Marshall Clowc4b4a342015-02-11 16:14:01 +00001976template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001977_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001978auto data(const _Cont& __c)
1979_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001980-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001981{ return __c.data(); }
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
Marshall Clowc4b4a342015-02-11 16:14:01 +00001985constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001986
1987template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001988_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001989constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1990#endif
1991
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001992template <class _Container, class _Predicate>
1993typename _Container::size_type
1994__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
1995 typename _Container::size_type __old_size = __c.size();
1996
1997 const typename _Container::iterator __last = __c.end();
1998 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
1999 if (__pred(*__iter))
2000 __iter = __c.erase(__iter);
2001 else
2002 ++__iter;
2003 }
2004
2005 return __old_size - __c.size();
2006}
Marshall Clowef357272014-11-19 19:43:23 +00002007
Howard Hinnantc51e1022010-05-11 19:42:16 +00002008_LIBCPP_END_NAMESPACE_STD
2009
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002010#endif // _LIBCPP_ITERATOR