blob: 364c74325b1803283d836635abef5f21a2f2a94a [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
Howard Hinnantc51e1022010-05-11 19:42:16 +0000128template<class Category, class T, class Distance = ptrdiff_t,
129 class Pointer = T*, class Reference = T&>
Louis Dionne8762e2b2021-05-25 18:15:58 -0400130struct iterator // deprecated in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000131{
132 typedef T value_type;
133 typedef Distance difference_type;
134 typedef Pointer pointer;
135 typedef Reference reference;
136 typedef Category iterator_category;
137};
138
139struct input_iterator_tag {};
140struct output_iterator_tag {};
141struct forward_iterator_tag : public input_iterator_tag {};
142struct bidirectional_iterator_tag : public forward_iterator_tag {};
143struct random_access_iterator_tag : public bidirectional_iterator_tag {};
144
Marshall Clow75468e72017-05-17 18:51:36 +0000145// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -0400146template <class InputIterator, class Distance> // constexpr in C++17
147 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148
Marshall Clow75468e72017-05-17 18:51:36 +0000149template <class InputIterator> // constexpr in C++17
150 constexpr typename iterator_traits<InputIterator>::difference_type
151 distance(InputIterator first, InputIterator last);
152
153template <class InputIterator> // constexpr in C++17
154 constexpr InputIterator next(InputIterator x,
155typename iterator_traits<InputIterator>::difference_type n = 1);
156
157template <class BidirectionalIterator> // constexpr in C++17
158 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +0000159 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160
Christopher Di Bellac6ead652021-05-05 07:14:08 +0000161// [range.iter.ops], range iterator operations
162namespace ranges {
163 // [range.iter.op.advance], ranges::advance
164 template<input_or_output_iterator I>
165 constexpr void advance(I& i, iter_difference_t<I> n); // since C++20
166 template<input_or_output_iterator I, sentinel_for<I> S>
167 constexpr void advance(I& i, S bound); // since C++20
168 template<input_or_output_iterator I, sentinel_for<I> S>
169 constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound); // since C++20
170}
171
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172template <class Iterator>
173class reverse_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400174 : public iterator<typename iterator_traits<Iterator>::iterator_category, // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175 typename iterator_traits<Iterator>::value_type,
176 typename iterator_traits<Iterator>::difference_type,
177 typename iterator_traits<Iterator>::pointer,
178 typename iterator_traits<Iterator>::reference>
179{
180protected:
181 Iterator current;
182public:
183 typedef Iterator iterator_type;
184 typedef typename iterator_traits<Iterator>::difference_type difference_type;
185 typedef typename iterator_traits<Iterator>::reference reference;
186 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000187
Marshall Clow5ace5542016-10-19 15:12:50 +0000188 constexpr reverse_iterator();
189 constexpr explicit reverse_iterator(Iterator x);
190 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
191 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
192 constexpr Iterator base() const;
193 constexpr reference operator*() const;
194 constexpr pointer operator->() const;
195 constexpr reverse_iterator& operator++();
196 constexpr reverse_iterator operator++(int);
197 constexpr reverse_iterator& operator--();
198 constexpr reverse_iterator operator--(int);
199 constexpr reverse_iterator operator+ (difference_type n) const;
200 constexpr reverse_iterator& operator+=(difference_type n);
201 constexpr reverse_iterator operator- (difference_type n) const;
202 constexpr reverse_iterator& operator-=(difference_type n);
203 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204};
205
206template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000207constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
209
210template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000211constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
213
214template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000215constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
217
218template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000219constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000220operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
221
222template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000223constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
225
226template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000227constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
229
230template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000231constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000232operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000233-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234
235template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000236constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000237operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000238 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239
Marshall Clow5ace5542016-10-19 15:12:50 +0000240template <class Iterator>
241constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000242
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243template <class Container>
244class back_insert_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400245 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246{
247protected:
248 Container* container;
249public:
250 typedef Container container_type;
251 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400252 typedef void difference_type; // until C++20
253 typedef ptrdiff_t difference_type; // since C++20
Eric Fiselier9aeea872016-06-30 04:40:50 +0000254 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255 typedef void pointer;
256
Louis Dionne3402c3c2021-05-27 12:56:12 -0400257 constexpr back_insert_iterator() noexcept = default; // since C++20
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500258 explicit back_insert_iterator(Container& x); // constexpr in C++20
259 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
260 back_insert_iterator& operator*(); // constexpr in C++20
261 back_insert_iterator& operator++(); // constexpr in C++20
262 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263};
264
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500265template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266
267template <class Container>
268class front_insert_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400269 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270{
271protected:
272 Container* container;
273public:
274 typedef Container container_type;
275 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400276 typedef void difference_type; // until C++20
277 typedef ptrdiff_t difference_type; // since C++20
Eric Fiselier9aeea872016-06-30 04:40:50 +0000278 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279 typedef void pointer;
280
Louis Dionne3402c3c2021-05-27 12:56:12 -0400281 constexpr front_insert_iterator() noexcept = default; // since C++20
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500282 explicit front_insert_iterator(Container& x); // constexpr in C++20
283 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
284 front_insert_iterator& operator*(); // constexpr in C++20
285 front_insert_iterator& operator++(); // constexpr in C++20
286 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287};
288
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500289template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290
291template <class Container>
292class insert_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400293 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294{
295protected:
296 Container* container;
297 typename Container::iterator iter;
298public:
299 typedef Container container_type;
300 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400301 typedef void difference_type; // until C++20
302 typedef ptrdiff_t difference_type; // since C++20
Eric Fiselier9aeea872016-06-30 04:40:50 +0000303 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304 typedef void pointer;
305
Louis Dionne3402c3c2021-05-27 12:56:12 -0400306 insert_iterator() = default; // since C++20
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500307 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
308 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
309 insert_iterator& operator*(); // constexpr in C++20
310 insert_iterator& operator++(); // constexpr in C++20
311 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312};
313
314template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500315insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000317template <class Iterator>
318class move_iterator {
319public:
320 typedef Iterator iterator_type;
321 typedef typename iterator_traits<Iterator>::difference_type difference_type;
322 typedef Iterator pointer;
323 typedef typename iterator_traits<Iterator>::value_type value_type;
324 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
325 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000326
Marshall Clowb5f99122016-11-02 15:30:26 +0000327 constexpr move_iterator(); // all the constexprs are in C++17
328 constexpr explicit move_iterator(Iterator i);
329 template <class U>
330 constexpr move_iterator(const move_iterator<U>& u);
331 template <class U>
332 constexpr move_iterator& operator=(const move_iterator<U>& u);
333 constexpr iterator_type base() const;
334 constexpr reference operator*() const;
335 constexpr pointer operator->() const;
336 constexpr move_iterator& operator++();
337 constexpr move_iterator operator++(int);
338 constexpr move_iterator& operator--();
339 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000340 constexpr move_iterator operator+(difference_type n) const;
341 constexpr move_iterator& operator+=(difference_type n);
342 constexpr move_iterator operator-(difference_type n) const;
343 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000344 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000345private:
346 Iterator current; // exposition only
347};
348
349template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000350constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000351operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
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 auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000375operator-(const move_iterator<Iterator1>& x,
376 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
377
378template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000379constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000380 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000381 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000382
Marshall Clowb5f99122016-11-02 15:30:26 +0000383template <class Iterator> // constexpr in C++17
384constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000385
386
Howard Hinnantc51e1022010-05-11 19:42:16 +0000387template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
388class istream_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400389 : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390{
391public:
Louis Dionne3402c3c2021-05-27 12:56:12 -0400392 typedef input_iterator_tag iterator_category;
393 typedef T value_type;
394 typedef Distance difference_type;
395 typedef const T* pointer;
396 typedef const T& reference;
397
398 typedef charT char_type;
399 typedef traits traits_type;
400 typedef basic_istream<charT, traits> istream_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401
Marshall Clow0735e4e2015-04-16 21:36:54 +0000402 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403 istream_iterator(istream_type& s);
404 istream_iterator(const istream_iterator& x);
405 ~istream_iterator();
406
407 const T& operator*() const;
408 const T* operator->() const;
409 istream_iterator& operator++();
410 istream_iterator operator++(int);
411};
412
413template <class T, class charT, class traits, class Distance>
414bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
415 const istream_iterator<T,charT,traits,Distance>& y);
416template <class T, class charT, class traits, class Distance>
417bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
418 const istream_iterator<T,charT,traits,Distance>& y);
419
420template <class T, class charT = char, class traits = char_traits<charT> >
421class ostream_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400422 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423{
424public:
Louis Dionne3402c3c2021-05-27 12:56:12 -0400425 typedef output_iterator_tag iterator_category;
426 typedef void value_type;
427 typedef void difference_type; // until C++20
428 typedef ptrdiff_t difference_type; // since C++20
429 typedef void pointer;
430 typedef void reference;
431
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432 typedef charT char_type;
433 typedef traits traits_type;
434 typedef basic_ostream<charT,traits> ostream_type;
435
Louis Dionne3402c3c2021-05-27 12:56:12 -0400436 constexpr ostream_iterator() noexcept = default; // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000437 ostream_iterator(ostream_type& s);
438 ostream_iterator(ostream_type& s, const charT* delimiter);
439 ostream_iterator(const ostream_iterator& x);
440 ~ostream_iterator();
441 ostream_iterator& operator=(const T& value);
442
443 ostream_iterator& operator*();
444 ostream_iterator& operator++();
445 ostream_iterator& operator++(int);
446};
447
448template<class charT, class traits = char_traits<charT> >
449class istreambuf_iterator
Louis Dionne3402c3c2021-05-27 12:56:12 -0400450 : public iterator<input_iterator_tag, charT, traits::off_type, unspecified, charT> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451{
452public:
Louis Dionne3402c3c2021-05-27 12:56:12 -0400453 typedef input_iterator_tag iterator_category;
454 typedef charT value_type;
455 typedef traits::off_type difference_type;
456 typedef unspecified pointer;
457 typedef charT reference;
458
459 typedef charT char_type;
460 typedef traits traits_type;
461 typedef traits::int_type int_type;
462 typedef basic_streambuf<charT, traits> streambuf_type;
463 typedef basic_istream<charT, traits> istream_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464
Howard Hinnant011138d2012-07-20 19:36:34 +0000465 istreambuf_iterator() noexcept;
466 istreambuf_iterator(istream_type& s) noexcept;
467 istreambuf_iterator(streambuf_type* s) noexcept;
468 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469
470 charT operator*() const;
471 pointer operator->() const;
472 istreambuf_iterator& operator++();
473 a-private-type operator++(int);
474
475 bool equal(const istreambuf_iterator& b) const;
476};
477
478template <class charT, class traits>
479bool operator==(const istreambuf_iterator<charT,traits>& a,
480 const istreambuf_iterator<charT,traits>& b);
481template <class charT, class traits>
482bool operator!=(const istreambuf_iterator<charT,traits>& a,
483 const istreambuf_iterator<charT,traits>& b);
484
485template <class charT, class traits = char_traits<charT> >
486class ostreambuf_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400487 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488{
489public:
Louis Dionne3402c3c2021-05-27 12:56:12 -0400490 typedef output_iterator_tag iterator_category;
491 typedef void value_type;
492 typedef void difference_type; // until C++20
493 typedef ptrdiff_t difference_type; // since C++20
494 typedef void pointer;
495 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496
Louis Dionne3402c3c2021-05-27 12:56:12 -0400497 typedef charT char_type;
498 typedef traits traits_type;
499 typedef basic_streambuf<charT, traits> streambuf_type;
500 typedef basic_ostream<charT, traits> ostream_type;
501
502 constexpr ostreambuf_iterator() noexcept = default; // since C++20
Howard Hinnant011138d2012-07-20 19:36:34 +0000503 ostreambuf_iterator(ostream_type& s) noexcept;
504 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505 ostreambuf_iterator& operator=(charT c);
506 ostreambuf_iterator& operator*();
507 ostreambuf_iterator& operator++();
508 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000509 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510};
511
Marshall Clow99ba0022017-01-04 17:58:17 +0000512template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
513template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
514template <class C> constexpr auto end(C& c) -> decltype(c.end());
515template <class C> constexpr auto end(const C& c) -> decltype(c.end());
516template <class T, size_t N> constexpr T* begin(T (&array)[N]);
517template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518
Marshall Clow99ba0022017-01-04 17:58:17 +0000519template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
520template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
521template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
522template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
523template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
524template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
525template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
526template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
527template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
528template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
529template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
530template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000531
Marshall Clowef357272014-11-19 19:43:23 +0000532// 24.8, container access:
533template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
534template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000535
536template <class C> constexpr auto ssize(const C& c)
Arthur O'Dwyer2fc9b5d2021-04-17 17:03:20 -0400537 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
Marshall Clow3c5363e2019-02-27 02:58:56 +0000538template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
539
Marshall Clowef357272014-11-19 19:43:23 +0000540template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
541template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
542template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
543template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
544template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
545template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
546template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
547
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548} // std
549
550*/
551
552#include <__config>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400553#include <__debug>
Marshall Clow3dc05502014-02-27 02:11:50 +0000554#include <__functional_base>
Christopher Di Bellac6ead652021-05-05 07:14:08 +0000555#include <__iterator/advance.h>
Louis Dionne463afb82021-04-22 11:05:30 -0400556#include <__iterator/concepts.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400557#include <__iterator/incrementable_traits.h>
Louis Dionne170a03c2021-04-28 15:02:08 -0400558#include <__iterator/indirect_concepts.h>
Louis Dionneca989a52021-04-20 14:40:43 -0400559#include <__iterator/iter_move.h>
zoecarver5d41ff52021-04-19 14:44:42 -0700560#include <__iterator/iterator_traits.h>
Christopher Di Bella9c0adab2021-05-08 05:02:43 +0000561#include <__iterator/next.h>
Christopher Di Bellab8e21042021-05-16 01:39:22 +0000562#include <__iterator/prev.h>
Louis Dionne170a03c2021-04-28 15:02:08 -0400563#include <__iterator/projected.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400564#include <__iterator/readable_traits.h>
Louis Dionne735bc462021-04-14 13:59:03 -0400565#include <__memory/addressof.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500566#include <__memory/pointer_traits.h>
Arthur O'Dwyera2f99ee2021-04-29 17:40:17 -0400567#include <compare>
568#include <concepts> // Mandated by the Standard.
569#include <cstddef>
570#include <initializer_list>
571#include <iosfwd> // for forward declarations of vector and string
572#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000573#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000574
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000575#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000577#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578
579_LIBCPP_BEGIN_NAMESPACE_STD
Christopher Di Bella490fe402021-03-23 03:55:52 +0000580
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581template<class _Category, class _Tp, class _Distance = ptrdiff_t,
582 class _Pointer = _Tp*, class _Reference = _Tp&>
Louis Dionne8762e2b2021-05-25 18:15:58 -0400583struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584{
585 typedef _Tp value_type;
586 typedef _Distance difference_type;
587 typedef _Pointer pointer;
588 typedef _Reference reference;
589 typedef _Category iterator_category;
590};
591
592template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000593inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594typename iterator_traits<_InputIter>::difference_type
595__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
596{
597 typename iterator_traits<_InputIter>::difference_type __r(0);
598 for (; __first != __last; ++__first)
599 ++__r;
600 return __r;
601}
602
603template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000604inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605typename iterator_traits<_RandIter>::difference_type
606__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
607{
608 return __last - __first;
609}
610
611template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000612inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613typename iterator_traits<_InputIter>::difference_type
614distance(_InputIter __first, _InputIter __last)
615{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500616 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617}
618
Eric Fiselier883af112017-04-13 02:54:13 +0000619template <class _Tp, class = void>
620struct __is_stashing_iterator : false_type {};
621
622template <class _Tp>
623struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
624 : true_type {};
625
Louis Dionne8762e2b2021-05-25 18:15:58 -0400626_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000628class _LIBCPP_TEMPLATE_VIS reverse_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400629#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000630 : public iterator<typename iterator_traits<_Iter>::iterator_category,
631 typename iterator_traits<_Iter>::value_type,
632 typename iterator_traits<_Iter>::difference_type,
633 typename iterator_traits<_Iter>::pointer,
634 typename iterator_traits<_Iter>::reference>
Louis Dionne8762e2b2021-05-25 18:15:58 -0400635#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400637_LIBCPP_SUPPRESS_DEPRECATED_POP
Marshall Clow0ad029e2014-03-11 22:05:31 +0000638private:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400639#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
640 _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
641#endif
Eric Fiselier883af112017-04-13 02:54:13 +0000642
643 static_assert(!__is_stashing_iterator<_Iter>::value,
644 "The specified iterator type cannot be used with reverse_iterator; "
645 "Using stashing iterators with reverse_iterator causes undefined behavior");
646
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000647protected:
648 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649public:
650 typedef _Iter iterator_type;
651 typedef typename iterator_traits<_Iter>::difference_type difference_type;
652 typedef typename iterator_traits<_Iter>::reference reference;
653 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500654 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
655 random_access_iterator_tag,
656 typename iterator_traits<_Iter>::iterator_category> iterator_category;
Louis Dionne8762e2b2021-05-25 18:15:58 -0400657 typedef typename iterator_traits<_Iter>::value_type value_type;
658
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500659#if _LIBCPP_STD_VER > 17
660 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
661 random_access_iterator_tag,
662 bidirectional_iterator_tag> iterator_concept;
663#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000664
Louis Dionne8762e2b2021-05-25 18:15:58 -0400665#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
Marshall Clow5ace5542016-10-19 15:12:50 +0000666 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
667 reverse_iterator() : __t(), current() {}
668 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
669 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
670 template <class _Up>
671 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
672 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
673 template <class _Up>
674 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
675 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
676 { __t = current = __u.base(); return *this; }
Louis Dionne8762e2b2021-05-25 18:15:58 -0400677#else
678 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
679 reverse_iterator() : current() {}
680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
681 explicit reverse_iterator(_Iter __x) : current(__x) {}
682 template <class _Up>
683 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
684 reverse_iterator(const reverse_iterator<_Up>& __u) : current(__u.base()) {}
685 template <class _Up>
686 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
687 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
688 { current = __u.base(); return *this; }
689#endif
Marshall Clow5ace5542016-10-19 15:12:50 +0000690 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
691 _Iter base() const {return current;}
692 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
693 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
694 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
695 pointer operator->() const {return _VSTD::addressof(operator*());}
696 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
697 reverse_iterator& operator++() {--current; return *this;}
698 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
699 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
700 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
701 reverse_iterator& operator--() {++current; return *this;}
702 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
703 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
704 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
705 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
706 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
707 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
708 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
709 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
710 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
711 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
712 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
713 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714};
715
716template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000717inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718bool
719operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
720{
721 return __x.base() == __y.base();
722}
723
724template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000725inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000726bool
727operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
728{
729 return __x.base() > __y.base();
730}
731
732template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000733inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734bool
735operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
736{
737 return __x.base() != __y.base();
738}
739
740template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000741inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742bool
743operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
744{
745 return __x.base() < __y.base();
746}
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
Marshall Clow476d3f42016-07-18 13:19:00 +0000764#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000765template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000766inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000767auto
768operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
769-> decltype(__y.base() - __x.base())
770{
771 return __y.base() - __x.base();
772}
773#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774template <class _Iter1, class _Iter2>
775inline _LIBCPP_INLINE_VISIBILITY
776typename reverse_iterator<_Iter1>::difference_type
777operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
778{
779 return __y.base() - __x.base();
780}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000781#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782
783template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000784inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785reverse_iterator<_Iter>
786operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
787{
788 return reverse_iterator<_Iter>(__x.base() - __n);
789}
790
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000791#if _LIBCPP_STD_VER > 11
792template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000793inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000794reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
795{
796 return reverse_iterator<_Iter>(__i);
797}
798#endif
799
Louis Dionne8762e2b2021-05-25 18:15:58 -0400800_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000802class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400803#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
804 : public iterator<output_iterator_tag, void, void, void, void>
805#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400807_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808protected:
809 _Container* container;
810public:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400811 typedef output_iterator_tag iterator_category;
812 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400813#if _LIBCPP_STD_VER > 17
814 typedef ptrdiff_t difference_type;
815#else
Louis Dionne8762e2b2021-05-25 18:15:58 -0400816 typedef void difference_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400817#endif
Louis Dionne8762e2b2021-05-25 18:15:58 -0400818 typedef void pointer;
819 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820 typedef _Container container_type;
821
Louis Dionne3402c3c2021-05-27 12:56:12 -0400822#if _LIBCPP_STD_VER > 17
823 _LIBCPP_INLINE_VISIBILITY constexpr back_insert_iterator() noexcept = default;
824#endif
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500825 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
826 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000827 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000828#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500829 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000830 {container->push_back(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400831#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500832 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
833 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
834 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835};
836
837template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500838inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839back_insert_iterator<_Container>
840back_inserter(_Container& __x)
841{
842 return back_insert_iterator<_Container>(__x);
843}
844
Louis Dionne8762e2b2021-05-25 18:15:58 -0400845_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000847class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400848#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
849 : public iterator<output_iterator_tag, void, void, void, void>
850#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400852_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853protected:
854 _Container* container;
855public:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400856 typedef output_iterator_tag iterator_category;
857 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400858#if _LIBCPP_STD_VER > 17
859 typedef ptrdiff_t difference_type;
860#else
Louis Dionne8762e2b2021-05-25 18:15:58 -0400861 typedef void difference_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400862#endif
Louis Dionne8762e2b2021-05-25 18:15:58 -0400863 typedef void pointer;
864 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000865 typedef _Container container_type;
866
Louis Dionne3402c3c2021-05-27 12:56:12 -0400867#if _LIBCPP_STD_VER > 17
868 _LIBCPP_INLINE_VISIBILITY constexpr front_insert_iterator() noexcept = default;
869#endif
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500870 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
871 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000872 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000873#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500874 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000875 {container->push_front(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400876#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500877 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
878 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
879 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880};
881
882template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500883inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884front_insert_iterator<_Container>
885front_inserter(_Container& __x)
886{
887 return front_insert_iterator<_Container>(__x);
888}
889
Louis Dionne8762e2b2021-05-25 18:15:58 -0400890_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000892class _LIBCPP_TEMPLATE_VIS insert_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400893#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
894 : public iterator<output_iterator_tag, void, void, void, void>
895#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400897_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898protected:
899 _Container* container;
900 typename _Container::iterator iter;
901public:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400902 typedef output_iterator_tag iterator_category;
903 typedef void value_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400904#if _LIBCPP_STD_VER > 17
905 typedef ptrdiff_t difference_type;
906#else
Louis Dionne8762e2b2021-05-25 18:15:58 -0400907 typedef void difference_type;
Louis Dionne3402c3c2021-05-27 12:56:12 -0400908#endif
Louis Dionne8762e2b2021-05-25 18:15:58 -0400909 typedef void pointer;
910 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 typedef _Container container_type;
912
Louis Dionne3402c3c2021-05-27 12:56:12 -0400913#if _LIBCPP_STD_VER > 17
914 _LIBCPP_INLINE_VISIBILITY insert_iterator() = default;
915#endif
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500916 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000917 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500918 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000919 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000920#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500921 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000922 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400923#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500924 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
925 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
926 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927};
928
929template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500930inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931insert_iterator<_Container>
932inserter(_Container& __x, typename _Container::iterator __i)
933{
934 return insert_iterator<_Container>(__x, __i);
935}
936
Louis Dionne8762e2b2021-05-25 18:15:58 -0400937_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938template <class _Tp, class _CharT = char,
939 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000940class _LIBCPP_TEMPLATE_VIS istream_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -0400941#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
Louis Dionne8762e2b2021-05-25 18:15:58 -0400943#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944{
Louis Dionne8762e2b2021-05-25 18:15:58 -0400945_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946public:
Louis Dionne8762e2b2021-05-25 18:15:58 -0400947 typedef input_iterator_tag iterator_category;
948 typedef _Tp value_type;
949 typedef _Distance difference_type;
950 typedef const _Tp* pointer;
951 typedef const _Tp& reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952 typedef _CharT char_type;
953 typedef _Traits traits_type;
954 typedef basic_istream<_CharT,_Traits> istream_type;
955private:
956 istream_type* __in_stream_;
957 _Tp __value_;
958public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500959 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000960 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961 {
962 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500963 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964 }
965
966 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000967 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
969 {
970 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500971 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 return *this;
973 }
974 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
975 {istream_iterator __t(*this); ++(*this); return __t;}
976
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000977 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000979 bool
980 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
981 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000983 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000985 bool
986 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
987 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988};
989
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000990template <class _Tp, class _CharT, class _Traits, class _Distance>
991inline _LIBCPP_INLINE_VISIBILITY
992bool
993operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
994 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
995{
996 return __x.__in_stream_ == __y.__in_stream_;
997}
998
999template <class _Tp, class _CharT, class _Traits, class _Distance>
1000inline _LIBCPP_INLINE_VISIBILITY
1001bool
1002operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
1003 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
1004{
1005 return !(__x == __y);
1006}
1007
Louis Dionne8762e2b2021-05-25 18:15:58 -04001008_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001010class _LIBCPP_TEMPLATE_VIS ostream_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -04001011#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012 : public iterator<output_iterator_tag, void, void, void, void>
Louis Dionne8762e2b2021-05-25 18:15:58 -04001013#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014{
Louis Dionne8762e2b2021-05-25 18:15:58 -04001015_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001017 typedef output_iterator_tag iterator_category;
1018 typedef void value_type;
1019#if _LIBCPP_STD_VER > 17
Louis Dionne3402c3c2021-05-27 12:56:12 -04001020 typedef ptrdiff_t difference_type;
Louis Dionnea4d79522020-09-11 10:15:56 -04001021#else
1022 typedef void difference_type;
1023#endif
1024 typedef void pointer;
1025 typedef void reference;
1026 typedef _CharT char_type;
1027 typedef _Traits traits_type;
1028 typedef basic_ostream<_CharT, _Traits> ostream_type;
1029
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030private:
1031 ostream_type* __out_stream_;
1032 const char_type* __delim_;
1033public:
Louis Dionne3402c3c2021-05-27 12:56:12 -04001034#if _LIBCPP_STD_VER > 17
1035 _LIBCPP_INLINE_VISIBILITY constexpr ostream_iterator() noexcept = default;
1036#endif
Marshall Clow27a89512016-10-12 16:13:48 +00001037 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -05001038 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +00001039 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +00001040 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +00001041 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 {
Howard Hinnantbf074022011-10-22 20:59:45 +00001043 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044 if (__delim_)
1045 *__out_stream_ << __delim_;
1046 return *this;
1047 }
1048
1049 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
1050 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
1051 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
1052};
1053
Louis Dionne8762e2b2021-05-25 18:15:58 -04001054_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001056class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -04001057#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058 : public iterator<input_iterator_tag, _CharT,
1059 typename _Traits::off_type, _CharT*,
1060 _CharT>
Louis Dionne8762e2b2021-05-25 18:15:58 -04001061#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062{
Louis Dionne8762e2b2021-05-25 18:15:58 -04001063_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064public:
Louis Dionne8762e2b2021-05-25 18:15:58 -04001065 typedef input_iterator_tag iterator_category;
1066 typedef _CharT value_type;
1067 typedef typename _Traits::off_type difference_type;
1068 typedef _CharT* pointer;
1069 typedef _CharT reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070 typedef _CharT char_type;
1071 typedef _Traits traits_type;
1072 typedef typename _Traits::int_type int_type;
1073 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1074 typedef basic_istream<_CharT,_Traits> istream_type;
1075private:
Howard Hinnant3e57b272012-11-16 22:17:23 +00001076 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077
1078 class __proxy
1079 {
1080 char_type __keep_;
1081 streambuf_type* __sbuf_;
1082 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
1083 : __keep_(__c), __sbuf_(__s) {}
1084 friend class istreambuf_iterator;
1085 public:
1086 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
1087 };
1088
Howard Hinnant756c69b2010-09-22 16:48:34 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +00001090 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001091 {
1092 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001093 __sbuf_ = nullptr;
1094 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095 }
1096public:
Bruce Mitchener170d8972020-11-24 12:53:53 -05001097 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001098 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001099 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001100 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001101 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001102 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103 : __sbuf_(__p.__sbuf_) {}
1104
Howard Hinnant28b24882011-12-01 20:21:04 +00001105 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1106 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001107 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1108 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001109 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110 return *this;
1111 }
1112 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1113 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001114 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115 }
1116
1117 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001118 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119};
1120
1121template <class _CharT, class _Traits>
1122inline _LIBCPP_INLINE_VISIBILITY
1123bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1124 const istreambuf_iterator<_CharT,_Traits>& __b)
1125 {return __a.equal(__b);}
1126
1127template <class _CharT, class _Traits>
1128inline _LIBCPP_INLINE_VISIBILITY
1129bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1130 const istreambuf_iterator<_CharT,_Traits>& __b)
1131 {return !__a.equal(__b);}
1132
Louis Dionne8762e2b2021-05-25 18:15:58 -04001133_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001135class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Louis Dionne8762e2b2021-05-25 18:15:58 -04001136#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 : public iterator<output_iterator_tag, void, void, void, void>
Louis Dionne8762e2b2021-05-25 18:15:58 -04001138#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139{
Louis Dionne8762e2b2021-05-25 18:15:58 -04001140_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141public:
Louis Dionnea4d79522020-09-11 10:15:56 -04001142 typedef output_iterator_tag iterator_category;
1143 typedef void value_type;
1144#if _LIBCPP_STD_VER > 17
Louis Dionne3402c3c2021-05-27 12:56:12 -04001145 typedef ptrdiff_t difference_type;
Louis Dionnea4d79522020-09-11 10:15:56 -04001146#else
1147 typedef void difference_type;
1148#endif
1149 typedef void pointer;
1150 typedef void reference;
1151 typedef _CharT char_type;
1152 typedef _Traits traits_type;
1153 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1154 typedef basic_ostream<_CharT, _Traits> ostream_type;
1155
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156private:
1157 streambuf_type* __sbuf_;
1158public:
Louis Dionne3402c3c2021-05-27 12:56:12 -04001159#if _LIBCPP_STD_VER > 17
1160 _LIBCPP_INLINE_VISIBILITY constexpr ostreambuf_iterator() noexcept = default;
1161#endif
Howard Hinnant011138d2012-07-20 19:36:34 +00001162 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001163 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001164 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165 : __sbuf_(__s) {}
1166 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1167 {
1168 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001169 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170 return *this;
1171 }
1172 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1173 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1174 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001175 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001176
1177 template <class _Ch, class _Tr>
1178 friend
1179 _LIBCPP_HIDDEN
1180 ostreambuf_iterator<_Ch, _Tr>
1181 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1182 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1183 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001184};
1185
1186template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001187class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188{
1189private:
1190 _Iter __i;
1191public:
1192 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193 typedef typename iterator_traits<iterator_type>::value_type value_type;
1194 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001195 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001196 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1197 random_access_iterator_tag,
1198 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1199#if _LIBCPP_STD_VER > 17
1200 typedef input_iterator_tag iterator_concept;
1201#endif
1202
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001203#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001204 typedef typename iterator_traits<iterator_type>::reference __reference;
1205 typedef typename conditional<
1206 is_reference<__reference>::value,
1207 typename remove_reference<__reference>::type&&,
1208 __reference
1209 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210#else
1211 typedef typename iterator_traits<iterator_type>::reference reference;
1212#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001213
Marshall Clowb5f99122016-11-02 15:30:26 +00001214 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1215 move_iterator() : __i() {}
1216 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1217 explicit move_iterator(_Iter __x) : __i(__x) {}
1218 template <class _Up>
1219 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1220 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1221 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001222 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001223 reference operator*() const { return static_cast<reference>(*__i); }
1224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1225 pointer operator->() const { return __i;}
1226 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1227 move_iterator& operator++() {++__i; return *this;}
1228 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1229 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1230 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1231 move_iterator& operator--() {--__i; return *this;}
1232 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1233 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1234 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1235 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1236 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1237 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1238 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1239 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1240 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1241 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1242 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1243 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244};
1245
1246template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001247inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248bool
1249operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1250{
1251 return __x.base() == __y.base();
1252}
1253
1254template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001255inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001256bool
1257operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1258{
1259 return __x.base() < __y.base();
1260}
1261
1262template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001263inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264bool
1265operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1266{
1267 return __x.base() != __y.base();
1268}
1269
1270template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001271inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272bool
1273operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1274{
1275 return __x.base() > __y.base();
1276}
1277
1278template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001279inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280bool
1281operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1282{
1283 return __x.base() >= __y.base();
1284}
1285
1286template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001287inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001288bool
1289operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1290{
1291 return __x.base() <= __y.base();
1292}
1293
Marshall Clow476d3f42016-07-18 13:19:00 +00001294#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001295template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001296inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001297auto
1298operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1299-> decltype(__x.base() - __y.base())
1300{
1301 return __x.base() - __y.base();
1302}
1303#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304template <class _Iter1, class _Iter2>
1305inline _LIBCPP_INLINE_VISIBILITY
1306typename move_iterator<_Iter1>::difference_type
1307operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1308{
1309 return __x.base() - __y.base();
1310}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001311#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001312
1313template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001314inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315move_iterator<_Iter>
1316operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1317{
1318 return move_iterator<_Iter>(__x.base() + __n);
1319}
1320
1321template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001322inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001324make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325{
1326 return move_iterator<_Iter>(__i);
1327}
1328
1329// __wrap_iter
1330
1331template <class _Iter> class __wrap_iter;
1332
1333template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001334_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001335bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001336operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337
1338template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001339_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001341operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001342
1343template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001344_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001345bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001346operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001347
1348template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001349_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001351operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352
1353template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001354_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001355bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001356operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001357
1358template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001359_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001361operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001362
Marshall Clow476d3f42016-07-18 13:19:00 +00001363#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001364template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001365_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001366auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001367operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001368-> decltype(__x.base() - __y.base());
1369#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001371_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001372typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001373operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001374#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375
1376template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001377_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001379operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380
Louis Dionne65b433b2019-11-06 12:02:41 +00001381template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1382template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001383template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1384template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001385
Howard Hinnantc51e1022010-05-11 19:42:16 +00001386template <class _Iter>
1387class __wrap_iter
1388{
1389public:
1390 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001391 typedef typename iterator_traits<iterator_type>::value_type value_type;
1392 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1393 typedef typename iterator_traits<iterator_type>::pointer pointer;
1394 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001395 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1396#if _LIBCPP_STD_VER > 17
Arthur O'Dwyer6eb8a5d2021-05-19 11:54:31 -04001397 typedef contiguous_iterator_tag iterator_concept;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001398#endif
1399
Howard Hinnantc51e1022010-05-11 19:42:16 +00001400private:
1401 iterator_type __i;
1402public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001403 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001404#if _LIBCPP_STD_VER > 11
1405 : __i{}
1406#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001407 {
Louis Dionneba400782020-10-02 15:02:52 -04001408#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001409 __get_db()->__insert_i(this);
1410#endif
1411 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001412 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1413 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001414 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001415 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001416 {
Louis Dionneba400782020-10-02 15:02:52 -04001417#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001418 __get_db()->__iterator_copy(this, &__u);
1419#endif
1420 }
Louis Dionneba400782020-10-02 15:02:52 -04001421#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001422 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001423 __wrap_iter(const __wrap_iter& __x)
1424 : __i(__x.base())
1425 {
1426 __get_db()->__iterator_copy(this, &__x);
1427 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001428 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001429 __wrap_iter& operator=(const __wrap_iter& __x)
1430 {
1431 if (this != &__x)
1432 {
1433 __get_db()->__iterator_copy(this, &__x);
1434 __i = __x.__i;
1435 }
1436 return *this;
1437 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001438 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001439 ~__wrap_iter()
1440 {
1441 __get_db()->__erase_i(this);
1442 }
1443#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001444 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001445 {
Louis Dionneba400782020-10-02 15:02:52 -04001446#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001447 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1448 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001449#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001450 return *__i;
1451 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001452 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001453 {
Louis Dionneba400782020-10-02 15:02:52 -04001454#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001455 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1456 "Attempted to dereference a non-dereferenceable iterator");
1457#endif
Louis Dionne1c8315b2021-05-04 18:51:58 -04001458 return _VSTD::__to_address(__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001459 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001460 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001461 {
Louis Dionneba400782020-10-02 15:02:52 -04001462#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001463 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001464 "Attempted to increment a non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001465#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001466 ++__i;
1467 return *this;
1468 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001469 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001470 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001471
Eric Fiselier873b8d32019-03-18 21:50:12 +00001472 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001473 {
Louis Dionneba400782020-10-02 15:02:52 -04001474#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001475 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001476 "Attempted to decrement a non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001477#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001478 --__i;
1479 return *this;
1480 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001481 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001482 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001483 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001484 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001485 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001486 {
Louis Dionneba400782020-10-02 15:02:52 -04001487#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001488 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001489 "Attempted to add/subtract an iterator outside its valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001490#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001491 __i += __n;
1492 return *this;
1493 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001494 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001495 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001496 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001497 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001498 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001499 {
Louis Dionneba400782020-10-02 15:02:52 -04001500#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001501 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
Kristina Bessonovaaeeaa7e2021-05-09 19:29:56 +02001502 "Attempted to subscript an iterator outside its valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001503#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001504 return __i[__n];
1505 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506
Eric Fiselier873b8d32019-03-18 21:50:12 +00001507 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508
1509private:
Louis Dionneba400782020-10-02 15:02:52 -04001510#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001511 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001512 {
1513 __get_db()->__insert_ic(this, __p);
1514 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001515#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001516 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001517#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518
1519 template <class _Up> friend class __wrap_iter;
1520 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001521 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001522 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523
1524 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001525 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001527 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001528
Howard Hinnantc51e1022010-05-11 19:42:16 +00001529 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001530 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001531 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001532 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001533
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001535 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001536 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001537 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001538
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001540 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001541 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001542 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001543
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001545 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001547 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001548
Howard Hinnantc51e1022010-05-11 19:42:16 +00001549 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001550 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001552 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001553
Marshall Clow476d3f42016-07-18 13:19:00 +00001554#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001555 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001556 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001557 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001558 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001559 -> decltype(__x.base() - __y.base());
1560#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001562 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001564 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001565#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001566
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001568 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001570 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571};
1572
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001573#if _LIBCPP_STD_VER <= 17
1574template <class _It>
Arthur O'Dwyer6eb8a5d2021-05-19 11:54:31 -04001575struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001576#endif
1577
1578template <class _Iter>
1579_LIBCPP_CONSTEXPR
Arthur O'Dwyer6eb8a5d2021-05-19 11:54:31 -04001580decltype(_VSTD::__to_address(declval<_Iter>()))
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001581__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1582 return _VSTD::__to_address(__w.base());
1583}
1584
Howard Hinnantc51e1022010-05-11 19:42:16 +00001585template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001586inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001588operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589{
1590 return __x.base() == __y.base();
1591}
1592
1593template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001594inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001595bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001596operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597{
Louis Dionneba400782020-10-02 15:02:52 -04001598#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001599 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001600 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001601#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602 return __x.base() < __y.base();
1603}
1604
1605template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001606inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001608operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001610 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001611}
1612
1613template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001614inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001616operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001617{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001618 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619}
1620
1621template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001622inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001624operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001626 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001627}
1628
1629template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001630inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001632operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001634 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635}
1636
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001637template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001638inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001639bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001640operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001641{
1642 return !(__x == __y);
1643}
1644
1645template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001646inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001647bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001648operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001649{
1650 return __y < __x;
1651}
1652
1653template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001654inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001655bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001656operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001657{
1658 return !(__x < __y);
1659}
1660
1661template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001662inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001663bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001664operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001665{
1666 return !(__y < __x);
1667}
1668
Marshall Clow476d3f42016-07-18 13:19:00 +00001669#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001670template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001671inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001672auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001673operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001674-> decltype(__x.base() - __y.base())
1675{
Louis Dionneba400782020-10-02 15:02:52 -04001676#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001677 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1678 "Attempted to subtract incompatible iterators");
1679#endif
1680 return __x.base() - __y.base();
1681}
1682#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001683template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001684inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001685typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001686operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687{
Louis Dionneba400782020-10-02 15:02:52 -04001688#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001689 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001690 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001691#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001692 return __x.base() - __y.base();
1693}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001694#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001695
1696template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001697inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001698__wrap_iter<_Iter>
1699operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001700 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001701{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001702 __x += __n;
1703 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001704}
1705
Marshall Clow8411ebf2013-12-02 03:24:33 +00001706template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001707_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001708_Tp*
1709begin(_Tp (&__array)[_Np])
1710{
1711 return __array;
1712}
1713
1714template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001715_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001716_Tp*
1717end(_Tp (&__array)[_Np])
1718{
1719 return __array + _Np;
1720}
1721
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001722#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001723
Howard Hinnantc834c512011-11-29 18:15:50 +00001724template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001725_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001726auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001727begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001728{
1729 return __c.begin();
1730}
1731
Howard Hinnantc834c512011-11-29 18:15:50 +00001732template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001733_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001735begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001736{
1737 return __c.begin();
1738}
1739
Howard Hinnantc834c512011-11-29 18:15:50 +00001740template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001741_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001743end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001744{
1745 return __c.end();
1746}
1747
Howard Hinnantc834c512011-11-29 18:15:50 +00001748template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001749_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001750auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001751end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752{
1753 return __c.end();
1754}
1755
Marshall Clowb278e9c2013-08-30 01:17:07 +00001756#if _LIBCPP_STD_VER > 11
1757
Marshall Clow8411ebf2013-12-02 03:24:33 +00001758template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001759_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001760reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1761{
1762 return reverse_iterator<_Tp*>(__array + _Np);
1763}
1764
1765template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001766_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001767reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1768{
1769 return reverse_iterator<_Tp*>(__array);
1770}
1771
1772template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001773_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001774reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1775{
1776 return reverse_iterator<const _Ep*>(__il.end());
1777}
1778
1779template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001780_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001781reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1782{
1783 return reverse_iterator<const _Ep*>(__il.begin());
1784}
1785
Marshall Clowb278e9c2013-08-30 01:17:07 +00001786template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001787_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001788auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001789{
Marshall Clow3862f532016-08-10 20:04:46 +00001790 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001791}
1792
1793template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001794_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001795auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001796{
Marshall Clow3862f532016-08-10 20:04:46 +00001797 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001798}
1799
1800template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001801_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001802auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1803{
1804 return __c.rbegin();
1805}
1806
1807template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001808_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001809auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1810{
1811 return __c.rbegin();
1812}
1813
1814template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001815_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001816auto rend(_Cp& __c) -> decltype(__c.rend())
1817{
1818 return __c.rend();
1819}
1820
1821template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001822_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001823auto rend(const _Cp& __c) -> decltype(__c.rend())
1824{
1825 return __c.rend();
1826}
1827
1828template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001829_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001830auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001831{
Marshall Clow3862f532016-08-10 20:04:46 +00001832 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001833}
1834
1835template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001836_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001837auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001838{
Marshall Clow3862f532016-08-10 20:04:46 +00001839 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001840}
1841
1842#endif
1843
1844
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001845#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001846
Howard Hinnantc834c512011-11-29 18:15:50 +00001847template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001848_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001849typename _Cp::iterator
1850begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001851{
1852 return __c.begin();
1853}
1854
Howard Hinnantc834c512011-11-29 18:15:50 +00001855template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001856_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001857typename _Cp::const_iterator
1858begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001859{
1860 return __c.begin();
1861}
1862
Howard Hinnantc834c512011-11-29 18:15:50 +00001863template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001864_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001865typename _Cp::iterator
1866end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001867{
1868 return __c.end();
1869}
1870
Howard Hinnantc834c512011-11-29 18:15:50 +00001871template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001872_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001873typename _Cp::const_iterator
1874end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001875{
1876 return __c.end();
1877}
1878
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001879#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001880
Marshall Clowef357272014-11-19 19:43:23 +00001881#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001882
1883// #if _LIBCPP_STD_VER > 11
1884// template <>
1885// struct _LIBCPP_TEMPLATE_VIS plus<void>
1886// {
1887// template <class _T1, class _T2>
1888// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1889// auto operator()(_T1&& __t, _T2&& __u) const
1890// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1891// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1892// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1893// typedef void is_transparent;
1894// };
1895// #endif
1896
Marshall Clowc4b4a342015-02-11 16:14:01 +00001897template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001898_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001899constexpr auto size(const _Cont& __c)
1900_NOEXCEPT_(noexcept(__c.size()))
1901-> decltype (__c.size())
1902{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001903
Marshall Clowc4b4a342015-02-11 16:14:01 +00001904template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001905_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001906constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001907
Marshall Clow3c5363e2019-02-27 02:58:56 +00001908#if _LIBCPP_STD_VER > 17
1909template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001910_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001911constexpr auto ssize(const _Cont& __c)
1912_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1913-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1914{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1915
1916template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001917_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001918constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1919#endif
1920
Marshall Clowc4b4a342015-02-11 16:14:01 +00001921template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001922_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001923constexpr auto empty(const _Cont& __c)
1924_NOEXCEPT_(noexcept(__c.empty()))
1925-> decltype (__c.empty())
1926{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001927
Marshall Clowc4b4a342015-02-11 16:14:01 +00001928template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001929_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001930constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001931
1932template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001933_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001934constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1935
Marshall Clowc4b4a342015-02-11 16:14:01 +00001936template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001937_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001938auto data(_Cont& __c)
1939_NOEXCEPT_(noexcept(__c.data()))
1940-> decltype (__c.data())
1941{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001942
Marshall Clowc4b4a342015-02-11 16:14:01 +00001943template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001944_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001945auto data(const _Cont& __c)
1946_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001947-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001948{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001949
Marshall Clowc4b4a342015-02-11 16:14:01 +00001950template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001951_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001952constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001953
1954template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001955_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001956constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1957#endif
1958
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001959template <class _Container, class _Predicate>
1960typename _Container::size_type
1961__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
1962 typename _Container::size_type __old_size = __c.size();
1963
1964 const typename _Container::iterator __last = __c.end();
1965 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
1966 if (__pred(*__iter))
1967 __iter = __c.erase(__iter);
1968 else
1969 ++__iter;
1970 }
1971
1972 return __old_size - __c.size();
1973}
Marshall Clowef357272014-11-19 19:43:23 +00001974
Howard Hinnantc51e1022010-05-11 19:42:16 +00001975_LIBCPP_END_NAMESPACE_STD
1976
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001977#endif // _LIBCPP_ITERATOR