blob: 34244358d75ca80e27efb0d0690a05155144fa33 [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
Howard Hinnantc51e1022010-05-11 19:42:16 +000046template<class Category, class T, class Distance = ptrdiff_t,
47 class Pointer = T*, class Reference = T&>
48struct iterator
49{
50 typedef T value_type;
51 typedef Distance difference_type;
52 typedef Pointer pointer;
53 typedef Reference reference;
54 typedef Category iterator_category;
55};
56
57struct input_iterator_tag {};
58struct output_iterator_tag {};
59struct forward_iterator_tag : public input_iterator_tag {};
60struct bidirectional_iterator_tag : public forward_iterator_tag {};
61struct random_access_iterator_tag : public bidirectional_iterator_tag {};
62
Marshall Clow75468e72017-05-17 18:51:36 +000063// 27.4.3, iterator operations
Louis Dionne45768662020-06-08 16:16:01 -040064template <class InputIterator, class Distance> // constexpr in C++17
65 constexpr void advance(InputIterator& i, Distance n);
Howard Hinnantc51e1022010-05-11 19:42:16 +000066
Marshall Clow75468e72017-05-17 18:51:36 +000067template <class InputIterator> // constexpr in C++17
68 constexpr typename iterator_traits<InputIterator>::difference_type
69 distance(InputIterator first, InputIterator last);
70
71template <class InputIterator> // constexpr in C++17
72 constexpr InputIterator next(InputIterator x,
73typename iterator_traits<InputIterator>::difference_type n = 1);
74
75template <class BidirectionalIterator> // constexpr in C++17
76 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionne173f29e2019-05-29 16:01:36 +000077 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +000078
79template <class Iterator>
80class reverse_iterator
81 : public iterator<typename iterator_traits<Iterator>::iterator_category,
82 typename iterator_traits<Iterator>::value_type,
83 typename iterator_traits<Iterator>::difference_type,
84 typename iterator_traits<Iterator>::pointer,
85 typename iterator_traits<Iterator>::reference>
86{
87protected:
88 Iterator current;
89public:
90 typedef Iterator iterator_type;
91 typedef typename iterator_traits<Iterator>::difference_type difference_type;
92 typedef typename iterator_traits<Iterator>::reference reference;
93 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000094
Marshall Clow5ace5542016-10-19 15:12:50 +000095 constexpr reverse_iterator();
96 constexpr explicit reverse_iterator(Iterator x);
97 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
98 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
99 constexpr Iterator base() const;
100 constexpr reference operator*() const;
101 constexpr pointer operator->() const;
102 constexpr reverse_iterator& operator++();
103 constexpr reverse_iterator operator++(int);
104 constexpr reverse_iterator& operator--();
105 constexpr reverse_iterator operator--(int);
106 constexpr reverse_iterator operator+ (difference_type n) const;
107 constexpr reverse_iterator& operator+=(difference_type n);
108 constexpr reverse_iterator operator- (difference_type n) const;
109 constexpr reverse_iterator& operator-=(difference_type n);
110 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000111};
112
113template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000114constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
116
117template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000118constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000119operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
120
121template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000122constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
124
125template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000126constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000127operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
128
129template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000130constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000131operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
132
133template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000134constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000135operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
136
137template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000138constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000139operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000140-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000141
142template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000143constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000144operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000145 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146
Marshall Clow5ace5542016-10-19 15:12:50 +0000147template <class Iterator>
148constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000149
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150template <class Container>
151class back_insert_iterator
152{
153protected:
154 Container* container;
155public:
156 typedef Container container_type;
157 typedef void value_type;
158 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000159 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160 typedef void pointer;
161
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500162 explicit back_insert_iterator(Container& x); // constexpr in C++20
163 back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
164 back_insert_iterator& operator*(); // constexpr in C++20
165 back_insert_iterator& operator++(); // constexpr in C++20
166 back_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167};
168
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500169template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170
171template <class Container>
172class front_insert_iterator
173{
174protected:
175 Container* container;
176public:
177 typedef Container container_type;
178 typedef void value_type;
179 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000180 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181 typedef void pointer;
182
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500183 explicit front_insert_iterator(Container& x); // constexpr in C++20
184 front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
185 front_insert_iterator& operator*(); // constexpr in C++20
186 front_insert_iterator& operator++(); // constexpr in C++20
187 front_insert_iterator operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188};
189
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500190template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000191
192template <class Container>
193class insert_iterator
194{
195protected:
196 Container* container;
197 typename Container::iterator iter;
198public:
199 typedef Container container_type;
200 typedef void value_type;
201 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000202 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203 typedef void pointer;
204
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500205 insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
206 insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
207 insert_iterator& operator*(); // constexpr in C++20
208 insert_iterator& operator++(); // constexpr in C++20
209 insert_iterator& operator++(int); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210};
211
212template <class Container, class Iterator>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500213insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000214
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000215template <class Iterator>
216class move_iterator {
217public:
218 typedef Iterator iterator_type;
219 typedef typename iterator_traits<Iterator>::difference_type difference_type;
220 typedef Iterator pointer;
221 typedef typename iterator_traits<Iterator>::value_type value_type;
222 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
223 typedef value_type&& reference;
Louis Dionne173f29e2019-05-29 16:01:36 +0000224
Marshall Clowb5f99122016-11-02 15:30:26 +0000225 constexpr move_iterator(); // all the constexprs are in C++17
226 constexpr explicit move_iterator(Iterator i);
227 template <class U>
228 constexpr move_iterator(const move_iterator<U>& u);
229 template <class U>
230 constexpr move_iterator& operator=(const move_iterator<U>& u);
231 constexpr iterator_type base() const;
232 constexpr reference operator*() const;
233 constexpr pointer operator->() const;
234 constexpr move_iterator& operator++();
235 constexpr move_iterator operator++(int);
236 constexpr move_iterator& operator--();
237 constexpr move_iterator operator--(int);
Louis Dionne173f29e2019-05-29 16:01:36 +0000238 constexpr move_iterator operator+(difference_type n) const;
239 constexpr move_iterator& operator+=(difference_type n);
240 constexpr move_iterator operator-(difference_type n) const;
241 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowb5f99122016-11-02 15:30:26 +0000242 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000243private:
244 Iterator current; // exposition only
245};
246
247template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000248constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000249operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
250
251template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000252constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000253operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
254
255template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000256constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000257operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
258
259template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000260constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000261operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
262
263template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000264constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000265operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
266
267template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000268constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000269operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
270
271template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000272constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000273operator-(const move_iterator<Iterator1>& x,
274 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
275
276template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000277constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000278 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000279 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000280
Marshall Clowb5f99122016-11-02 15:30:26 +0000281template <class Iterator> // constexpr in C++17
282constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000283
284
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
286class istream_iterator
287 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
288{
289public:
290 typedef charT char_type;
291 typedef traits traits_type;
292 typedef basic_istream<charT,traits> istream_type;
293
Marshall Clow0735e4e2015-04-16 21:36:54 +0000294 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295 istream_iterator(istream_type& s);
296 istream_iterator(const istream_iterator& x);
297 ~istream_iterator();
298
299 const T& operator*() const;
300 const T* operator->() const;
301 istream_iterator& operator++();
302 istream_iterator operator++(int);
303};
304
305template <class T, class charT, class traits, class Distance>
306bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
307 const istream_iterator<T,charT,traits,Distance>& y);
308template <class T, class charT, class traits, class Distance>
309bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
310 const istream_iterator<T,charT,traits,Distance>& y);
311
312template <class T, class charT = char, class traits = char_traits<charT> >
313class ostream_iterator
314 : public iterator<output_iterator_tag, void, void, void ,void>
315{
316public:
317 typedef charT char_type;
318 typedef traits traits_type;
319 typedef basic_ostream<charT,traits> ostream_type;
320
321 ostream_iterator(ostream_type& s);
322 ostream_iterator(ostream_type& s, const charT* delimiter);
323 ostream_iterator(const ostream_iterator& x);
324 ~ostream_iterator();
325 ostream_iterator& operator=(const T& value);
326
327 ostream_iterator& operator*();
328 ostream_iterator& operator++();
329 ostream_iterator& operator++(int);
330};
331
332template<class charT, class traits = char_traits<charT> >
333class istreambuf_iterator
334 : public iterator<input_iterator_tag, charT,
335 typename traits::off_type, unspecified,
336 charT>
337{
338public:
339 typedef charT char_type;
340 typedef traits traits_type;
341 typedef typename traits::int_type int_type;
342 typedef basic_streambuf<charT,traits> streambuf_type;
343 typedef basic_istream<charT,traits> istream_type;
344
Howard Hinnant011138d2012-07-20 19:36:34 +0000345 istreambuf_iterator() noexcept;
346 istreambuf_iterator(istream_type& s) noexcept;
347 istreambuf_iterator(streambuf_type* s) noexcept;
348 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349
350 charT operator*() const;
351 pointer operator->() const;
352 istreambuf_iterator& operator++();
353 a-private-type operator++(int);
354
355 bool equal(const istreambuf_iterator& b) const;
356};
357
358template <class charT, class traits>
359bool operator==(const istreambuf_iterator<charT,traits>& a,
360 const istreambuf_iterator<charT,traits>& b);
361template <class charT, class traits>
362bool operator!=(const istreambuf_iterator<charT,traits>& a,
363 const istreambuf_iterator<charT,traits>& b);
364
365template <class charT, class traits = char_traits<charT> >
366class ostreambuf_iterator
367 : public iterator<output_iterator_tag, void, void, void, void>
368{
369public:
370 typedef charT char_type;
371 typedef traits traits_type;
372 typedef basic_streambuf<charT,traits> streambuf_type;
373 typedef basic_ostream<charT,traits> ostream_type;
374
Howard Hinnant011138d2012-07-20 19:36:34 +0000375 ostreambuf_iterator(ostream_type& s) noexcept;
376 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377 ostreambuf_iterator& operator=(charT c);
378 ostreambuf_iterator& operator*();
379 ostreambuf_iterator& operator++();
380 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000381 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382};
383
Marshall Clow99ba0022017-01-04 17:58:17 +0000384template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
385template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
386template <class C> constexpr auto end(C& c) -> decltype(c.end());
387template <class C> constexpr auto end(const C& c) -> decltype(c.end());
388template <class T, size_t N> constexpr T* begin(T (&array)[N]);
389template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390
Marshall Clow99ba0022017-01-04 17:58:17 +0000391template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
392template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
393template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
394template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
395template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
396template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
397template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
398template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
399template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
400template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
401template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
402template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000403
Marshall Clowef357272014-11-19 19:43:23 +0000404// 24.8, container access:
405template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
406template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clow3c5363e2019-02-27 02:58:56 +0000407
408template <class C> constexpr auto ssize(const C& c)
Arthur O'Dwyer2fc9b5d2021-04-17 17:03:20 -0400409 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
Marshall Clow3c5363e2019-02-27 02:58:56 +0000410template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
411
Marshall Clowef357272014-11-19 19:43:23 +0000412template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
413template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
414template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
415template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
416template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
417template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
418template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
419
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420} // std
421
422*/
423
424#include <__config>
Eric Fiselier876c6862016-02-20 00:19:45 +0000425#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow3dc05502014-02-27 02:11:50 +0000426#include <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427#include <type_traits>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400428#include <compare>
zoecarver5d41ff52021-04-19 14:44:42 -0700429#include <concepts> // Mandated by the Standard.
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430#include <cstddef>
Marshall Clowb278e9c2013-08-30 01:17:07 +0000431#include <initializer_list>
zoecarver61ae1dc2021-04-19 14:28:27 -0400432#include <__iterator/incrementable_traits.h>
Louis Dionneca989a52021-04-20 14:40:43 -0400433#include <__iterator/iter_move.h>
zoecarver5d41ff52021-04-19 14:44:42 -0700434#include <__iterator/iterator_traits.h>
zoecarver61ae1dc2021-04-19 14:28:27 -0400435#include <__iterator/readable_traits.h>
Louis Dionne735bc462021-04-14 13:59:03 -0400436#include <__memory/addressof.h>
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500437#include <__memory/pointer_traits.h>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000438#include <version>
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000439
Eric Fiselier14b6de92014-08-10 23:53:08 +0000440#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000442#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000444#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
446_LIBCPP_BEGIN_NAMESPACE_STD
Christopher Di Bella490fe402021-03-23 03:55:52 +0000447
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448template<class _Category, class _Tp, class _Distance = ptrdiff_t,
449 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000450struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451{
452 typedef _Tp value_type;
453 typedef _Distance difference_type;
454 typedef _Pointer pointer;
455 typedef _Reference reference;
456 typedef _Category iterator_category;
457};
458
459template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000460inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461void __advance(_InputIter& __i,
462 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
463{
464 for (; __n > 0; --__n)
465 ++__i;
466}
467
468template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000469inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470void __advance(_BiDirIter& __i,
471 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
472{
473 if (__n >= 0)
474 for (; __n > 0; --__n)
475 ++__i;
476 else
477 for (; __n < 0; ++__n)
478 --__i;
479}
480
481template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000482inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483void __advance(_RandIter& __i,
484 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
485{
486 __i += __n;
487}
488
Louis Dionne45768662020-06-08 16:16:01 -0400489template <class _InputIter, class _Distance>
Marshall Clow75468e72017-05-17 18:51:36 +0000490inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Louis Dionne45768662020-06-08 16:16:01 -0400491void advance(_InputIter& __i, _Distance __orig_n)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492{
Louis Dionne45768662020-06-08 16:16:01 -0400493 _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
494 "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500495 typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
Louis Dionne45768662020-06-08 16:16:01 -0400496 _IntegralSize __n = __orig_n;
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500497 _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498}
499
500template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000501inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502typename iterator_traits<_InputIter>::difference_type
503__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
504{
505 typename iterator_traits<_InputIter>::difference_type __r(0);
506 for (; __first != __last; ++__first)
507 ++__r;
508 return __r;
509}
510
511template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000512inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513typename iterator_traits<_RandIter>::difference_type
514__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
515{
516 return __last - __first;
517}
518
519template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000520inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521typename iterator_traits<_InputIter>::difference_type
522distance(_InputIter __first, _InputIter __last)
523{
Arthur O'Dwyer6e9069c2020-12-07 23:42:47 -0500524 return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000525}
526
Marshall Clow990c70d2015-11-07 17:48:49 +0000527template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000528inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000529typename enable_if
530<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500531 __is_cpp17_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000532 _InputIter
533>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000534next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000535 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500537 _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400538 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
Marshall Clow3d435212019-03-22 22:32:20 +0000539
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000540 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541 return __x;
542}
543
Marshall Clow3d435212019-03-22 22:32:20 +0000544template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000545inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000546typename enable_if
547<
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500548 __is_cpp17_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000549 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000550>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000551prev(_InputIter __x,
552 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553{
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500554 _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
Louis Dionne45768662020-06-08 16:16:01 -0400555 "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000556 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557 return __x;
558}
559
Eric Fiselier883af112017-04-13 02:54:13 +0000560
561template <class _Tp, class = void>
562struct __is_stashing_iterator : false_type {};
563
564template <class _Tp>
565struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
566 : true_type {};
567
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000569class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 : public iterator<typename iterator_traits<_Iter>::iterator_category,
571 typename iterator_traits<_Iter>::value_type,
572 typename iterator_traits<_Iter>::difference_type,
573 typename iterator_traits<_Iter>::pointer,
574 typename iterator_traits<_Iter>::reference>
575{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000576private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000577 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000578
579 static_assert(!__is_stashing_iterator<_Iter>::value,
580 "The specified iterator type cannot be used with reverse_iterator; "
581 "Using stashing iterators with reverse_iterator causes undefined behavior");
582
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000583protected:
584 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585public:
586 typedef _Iter iterator_type;
587 typedef typename iterator_traits<_Iter>::difference_type difference_type;
588 typedef typename iterator_traits<_Iter>::reference reference;
589 typedef typename iterator_traits<_Iter>::pointer pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -0500590 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
591 random_access_iterator_tag,
592 typename iterator_traits<_Iter>::iterator_category> iterator_category;
593#if _LIBCPP_STD_VER > 17
594 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
595 random_access_iterator_tag,
596 bidirectional_iterator_tag> iterator_concept;
597#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000598
Marshall Clow5ace5542016-10-19 15:12:50 +0000599 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
600 reverse_iterator() : __t(), current() {}
601 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
602 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
603 template <class _Up>
604 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
605 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
606 template <class _Up>
607 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
608 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
609 { __t = current = __u.base(); return *this; }
610 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
611 _Iter base() const {return current;}
612 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
613 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
614 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
615 pointer operator->() const {return _VSTD::addressof(operator*());}
616 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
617 reverse_iterator& operator++() {--current; return *this;}
618 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
619 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
620 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
621 reverse_iterator& operator--() {++current; return *this;}
622 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
623 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
624 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
625 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
626 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
627 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
628 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
629 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
630 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
631 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
632 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
633 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634};
635
636template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000637inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000638bool
639operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
640{
641 return __x.base() == __y.base();
642}
643
644template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000645inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646bool
647operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
648{
649 return __x.base() > __y.base();
650}
651
652template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000653inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654bool
655operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
656{
657 return __x.base() != __y.base();
658}
659
660template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000661inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662bool
663operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
664{
665 return __x.base() < __y.base();
666}
667
668template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000669inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670bool
671operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
672{
673 return __x.base() <= __y.base();
674}
675
676template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000677inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678bool
679operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
680{
681 return __x.base() >= __y.base();
682}
683
Marshall Clow476d3f42016-07-18 13:19:00 +0000684#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000685template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000686inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000687auto
688operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
689-> decltype(__y.base() - __x.base())
690{
691 return __y.base() - __x.base();
692}
693#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694template <class _Iter1, class _Iter2>
695inline _LIBCPP_INLINE_VISIBILITY
696typename reverse_iterator<_Iter1>::difference_type
697operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
698{
699 return __y.base() - __x.base();
700}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000701#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702
703template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000704inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705reverse_iterator<_Iter>
706operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
707{
708 return reverse_iterator<_Iter>(__x.base() - __n);
709}
710
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000711#if _LIBCPP_STD_VER > 11
712template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000713inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000714reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
715{
716 return reverse_iterator<_Iter>(__i);
717}
718#endif
719
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000721class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722 : public iterator<output_iterator_tag,
723 void,
724 void,
725 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000726 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727{
728protected:
729 _Container* container;
730public:
731 typedef _Container container_type;
732
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500733 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
734 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000735 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000736#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500737 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000738 {container->push_back(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400739#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500740 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;}
741 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;}
742 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743};
744
745template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500746inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000747back_insert_iterator<_Container>
748back_inserter(_Container& __x)
749{
750 return back_insert_iterator<_Container>(__x);
751}
752
753template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000754class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755 : public iterator<output_iterator_tag,
756 void,
757 void,
758 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000759 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760{
761protected:
762 _Container* container;
763public:
764 typedef _Container container_type;
765
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500766 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
767 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000768 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000769#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500770 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000771 {container->push_front(_VSTD::move(__value_)); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400772#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500773 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;}
774 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;}
775 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776};
777
778template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500779inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780front_insert_iterator<_Container>
781front_inserter(_Container& __x)
782{
783 return front_insert_iterator<_Container>(__x);
784}
785
786template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000787class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788 : public iterator<output_iterator_tag,
789 void,
790 void,
791 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000792 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793{
794protected:
795 _Container* container;
796 typename _Container::iterator iter;
797public:
798 typedef _Container container_type;
799
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500800 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000801 : container(_VSTD::addressof(__x)), iter(__i) {}
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500802 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000803 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000804#ifndef _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500805 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
Howard Hinnantbf074022011-10-22 20:59:45 +0000806 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400807#endif // _LIBCPP_CXX03_LANG
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500808 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;}
809 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;}
810 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000811};
812
813template <class _Container>
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500814inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815insert_iterator<_Container>
816inserter(_Container& __x, typename _Container::iterator __i)
817{
818 return insert_iterator<_Container>(__x, __i);
819}
820
821template <class _Tp, class _CharT = char,
822 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000823class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
825{
826public:
827 typedef _CharT char_type;
828 typedef _Traits traits_type;
829 typedef basic_istream<_CharT,_Traits> istream_type;
830private:
831 istream_type* __in_stream_;
832 _Tp __value_;
833public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500834 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000835 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836 {
837 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500838 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839 }
840
841 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000842 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
844 {
845 if (!(*__in_stream_ >> __value_))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500846 __in_stream_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847 return *this;
848 }
849 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
850 {istream_iterator __t(*this); ++(*this); return __t;}
851
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000852 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000854 bool
855 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
856 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000858 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000860 bool
861 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
862 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863};
864
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000865template <class _Tp, class _CharT, class _Traits, class _Distance>
866inline _LIBCPP_INLINE_VISIBILITY
867bool
868operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
869 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
870{
871 return __x.__in_stream_ == __y.__in_stream_;
872}
873
874template <class _Tp, class _CharT, class _Traits, class _Distance>
875inline _LIBCPP_INLINE_VISIBILITY
876bool
877operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
878 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
879{
880 return !(__x == __y);
881}
882
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000884class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000885 : public iterator<output_iterator_tag, void, void, void, void>
886{
887public:
Louis Dionnea4d79522020-09-11 10:15:56 -0400888 typedef output_iterator_tag iterator_category;
889 typedef void value_type;
890#if _LIBCPP_STD_VER > 17
891 typedef std::ptrdiff_t difference_type;
892#else
893 typedef void difference_type;
894#endif
895 typedef void pointer;
896 typedef void reference;
897 typedef _CharT char_type;
898 typedef _Traits traits_type;
899 typedef basic_ostream<_CharT, _Traits> ostream_type;
900
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901private:
902 ostream_type* __out_stream_;
903 const char_type* __delim_;
904public:
Marshall Clow27a89512016-10-12 16:13:48 +0000905 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500906 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
Marshall Clow27a89512016-10-12 16:13:48 +0000907 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +0000908 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000909 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910 {
Howard Hinnantbf074022011-10-22 20:59:45 +0000911 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912 if (__delim_)
913 *__out_stream_ << __delim_;
914 return *this;
915 }
916
917 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
918 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
919 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
920};
921
922template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000923class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924 : public iterator<input_iterator_tag, _CharT,
925 typename _Traits::off_type, _CharT*,
926 _CharT>
927{
928public:
929 typedef _CharT char_type;
930 typedef _Traits traits_type;
931 typedef typename _Traits::int_type int_type;
932 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
933 typedef basic_istream<_CharT,_Traits> istream_type;
934private:
Howard Hinnant3e57b272012-11-16 22:17:23 +0000935 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000936
937 class __proxy
938 {
939 char_type __keep_;
940 streambuf_type* __sbuf_;
941 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
942 : __keep_(__c), __sbuf_(__s) {}
943 friend class istreambuf_iterator;
944 public:
945 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
946 };
947
Howard Hinnant756c69b2010-09-22 16:48:34 +0000948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +0000949 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950 {
951 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -0500952 __sbuf_ = nullptr;
953 return __sbuf_ == nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954 }
955public:
Bruce Mitchener170d8972020-11-24 12:53:53 -0500956 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000957 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +0000958 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000959 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +0000960 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +0000961 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962 : __sbuf_(__p.__sbuf_) {}
963
Howard Hinnant28b24882011-12-01 20:21:04 +0000964 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
965 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000966 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
967 {
Howard Hinnant3e57b272012-11-16 22:17:23 +0000968 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969 return *this;
970 }
971 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
972 {
Howard Hinnant3e57b272012-11-16 22:17:23 +0000973 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974 }
975
976 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +0000977 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978};
979
980template <class _CharT, class _Traits>
981inline _LIBCPP_INLINE_VISIBILITY
982bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
983 const istreambuf_iterator<_CharT,_Traits>& __b)
984 {return __a.equal(__b);}
985
986template <class _CharT, class _Traits>
987inline _LIBCPP_INLINE_VISIBILITY
988bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
989 const istreambuf_iterator<_CharT,_Traits>& __b)
990 {return !__a.equal(__b);}
991
992template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000993class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 : public iterator<output_iterator_tag, void, void, void, void>
995{
996public:
Louis Dionnea4d79522020-09-11 10:15:56 -0400997 typedef output_iterator_tag iterator_category;
998 typedef void value_type;
999#if _LIBCPP_STD_VER > 17
1000 typedef std::ptrdiff_t difference_type;
1001#else
1002 typedef void difference_type;
1003#endif
1004 typedef void pointer;
1005 typedef void reference;
1006 typedef _CharT char_type;
1007 typedef _Traits traits_type;
1008 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
1009 typedef basic_ostream<_CharT, _Traits> ostream_type;
1010
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011private:
1012 streambuf_type* __sbuf_;
1013public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001014 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001016 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 : __sbuf_(__s) {}
1018 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1019 {
1020 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
Bruce Mitchener170d8972020-11-24 12:53:53 -05001021 __sbuf_ = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022 return *this;
1023 }
1024 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1025 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1026 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Bruce Mitchener170d8972020-11-24 12:53:53 -05001027 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
Howard Hinnant97955172012-09-19 19:14:15 +00001028
1029 template <class _Ch, class _Tr>
1030 friend
1031 _LIBCPP_HIDDEN
1032 ostreambuf_iterator<_Ch, _Tr>
1033 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1034 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1035 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036};
1037
1038template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001039class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001040{
1041private:
1042 _Iter __i;
1043public:
1044 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045 typedef typename iterator_traits<iterator_type>::value_type value_type;
1046 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001047 typedef iterator_type pointer;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001048 typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1049 random_access_iterator_tag,
1050 typename iterator_traits<_Iter>::iterator_category> iterator_category;
1051#if _LIBCPP_STD_VER > 17
1052 typedef input_iterator_tag iterator_concept;
1053#endif
1054
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001055#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001056 typedef typename iterator_traits<iterator_type>::reference __reference;
1057 typedef typename conditional<
1058 is_reference<__reference>::value,
1059 typename remove_reference<__reference>::type&&,
1060 __reference
1061 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062#else
1063 typedef typename iterator_traits<iterator_type>::reference reference;
1064#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001065
Marshall Clowb5f99122016-11-02 15:30:26 +00001066 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1067 move_iterator() : __i() {}
1068 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1069 explicit move_iterator(_Iter __x) : __i(__x) {}
1070 template <class _Up>
1071 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1072 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1073 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001074 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001075 reference operator*() const { return static_cast<reference>(*__i); }
1076 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1077 pointer operator->() const { return __i;}
1078 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1079 move_iterator& operator++() {++__i; return *this;}
1080 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1081 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1082 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1083 move_iterator& operator--() {--__i; return *this;}
1084 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1085 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1086 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1087 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1088 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1089 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1090 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1091 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1092 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1093 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1095 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096};
1097
1098template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001099inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100bool
1101operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1102{
1103 return __x.base() == __y.base();
1104}
1105
1106template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001107inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108bool
1109operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1110{
1111 return __x.base() < __y.base();
1112}
1113
1114template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001115inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116bool
1117operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1118{
1119 return __x.base() != __y.base();
1120}
1121
1122template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001123inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124bool
1125operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1126{
1127 return __x.base() > __y.base();
1128}
1129
1130template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001131inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132bool
1133operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1134{
1135 return __x.base() >= __y.base();
1136}
1137
1138template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001139inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140bool
1141operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1142{
1143 return __x.base() <= __y.base();
1144}
1145
Marshall Clow476d3f42016-07-18 13:19:00 +00001146#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001147template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001148inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001149auto
1150operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1151-> decltype(__x.base() - __y.base())
1152{
1153 return __x.base() - __y.base();
1154}
1155#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156template <class _Iter1, class _Iter2>
1157inline _LIBCPP_INLINE_VISIBILITY
1158typename move_iterator<_Iter1>::difference_type
1159operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1160{
1161 return __x.base() - __y.base();
1162}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001163#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164
1165template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001166inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167move_iterator<_Iter>
1168operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1169{
1170 return move_iterator<_Iter>(__x.base() + __n);
1171}
1172
1173template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001174inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001176make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001177{
1178 return move_iterator<_Iter>(__i);
1179}
1180
1181// __wrap_iter
1182
1183template <class _Iter> class __wrap_iter;
1184
1185template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001186_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001187bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001188operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001189
1190template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001191_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001193operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194
1195template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001196_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001197bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001198operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199
1200template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001201_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001202bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001203operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204
1205template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001206_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001207bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001208operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209
1210template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001211_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001212bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001213operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001214
Marshall Clow476d3f42016-07-18 13:19:00 +00001215#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001216template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001217_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001218auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001219operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001220-> decltype(__x.base() - __y.base());
1221#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001222template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001223_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001225operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001226#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227
1228template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001229_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001231operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232
Louis Dionne65b433b2019-11-06 12:02:41 +00001233template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1234template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001235template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
1236template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001237
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238template <class _Iter>
1239class __wrap_iter
1240{
1241public:
1242 typedef _Iter iterator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001243 typedef typename iterator_traits<iterator_type>::value_type value_type;
1244 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1245 typedef typename iterator_traits<iterator_type>::pointer pointer;
1246 typedef typename iterator_traits<iterator_type>::reference reference;
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001247 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1248#if _LIBCPP_STD_VER > 17
1249 typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1250 contiguous_iterator_tag, iterator_category> iterator_concept;
1251#endif
1252
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253private:
1254 iterator_type __i;
1255public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001256 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001257#if _LIBCPP_STD_VER > 11
1258 : __i{}
1259#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001260 {
Louis Dionneba400782020-10-02 15:02:52 -04001261#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc90aa632011-09-16 19:52:23 +00001262 __get_db()->__insert_i(this);
1263#endif
1264 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001265 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1266 __wrap_iter(const __wrap_iter<_Up>& __u,
Bruce Mitchener170d8972020-11-24 12:53:53 -05001267 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001268 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001269 {
Louis Dionneba400782020-10-02 15:02:52 -04001270#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001271 __get_db()->__iterator_copy(this, &__u);
1272#endif
1273 }
Louis Dionneba400782020-10-02 15:02:52 -04001274#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001275 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001276 __wrap_iter(const __wrap_iter& __x)
1277 : __i(__x.base())
1278 {
1279 __get_db()->__iterator_copy(this, &__x);
1280 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001281 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001282 __wrap_iter& operator=(const __wrap_iter& __x)
1283 {
1284 if (this != &__x)
1285 {
1286 __get_db()->__iterator_copy(this, &__x);
1287 __i = __x.__i;
1288 }
1289 return *this;
1290 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001292 ~__wrap_iter()
1293 {
1294 __get_db()->__erase_i(this);
1295 }
1296#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001297 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001298 {
Louis Dionneba400782020-10-02 15:02:52 -04001299#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001300 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1301 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001302#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001303 return *__i;
1304 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001305 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001306 {
Louis Dionneba400782020-10-02 15:02:52 -04001307#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant76053d72013-06-27 19:35:32 +00001308 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1309 "Attempted to dereference a non-dereferenceable iterator");
1310#endif
Marshall Clowd85a0562016-04-11 03:54:53 +00001311 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001312 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001313 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001314 {
Louis Dionneba400782020-10-02 15:02:52 -04001315#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001316 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1317 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001318#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001319 ++__i;
1320 return *this;
1321 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001322 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001323 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001324
Eric Fiselier873b8d32019-03-18 21:50:12 +00001325 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001326 {
Louis Dionneba400782020-10-02 15:02:52 -04001327#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001328 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1329 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001330#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001331 --__i;
1332 return *this;
1333 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001334 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001335 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001336 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001337 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001338 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001339 {
Louis Dionneba400782020-10-02 15:02:52 -04001340#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001341 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1342 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001343#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001344 __i += __n;
1345 return *this;
1346 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001347 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001348 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001349 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001350 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001351 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001352 {
Louis Dionneba400782020-10-02 15:02:52 -04001353#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001354 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1355 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001356#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001357 return __i[__n];
1358 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001359
Eric Fiselier873b8d32019-03-18 21:50:12 +00001360 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001361
1362private:
Louis Dionneba400782020-10-02 15:02:52 -04001363#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001364 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001365 {
1366 __get_db()->__insert_ic(this, __p);
1367 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001368#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001369 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001370#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371
1372 template <class _Up> friend class __wrap_iter;
1373 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001374 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001375 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376
1377 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001378 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001380 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001381
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001383 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001384 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001385 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001386
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001388 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001390 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001391
Howard Hinnantc51e1022010-05-11 19:42:16 +00001392 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001393 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001395 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001396
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001398 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001400 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001401
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001403 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001404 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001405 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001406
Marshall Clow476d3f42016-07-18 13:19:00 +00001407#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001408 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001409 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001410 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001411 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001412 -> decltype(__x.base() - __y.base());
1413#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001415 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001417 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001418#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001419
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001421 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001422 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001423 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424
Louis Dionne65b433b2019-11-06 12:02:41 +00001425 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op);
1426 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2);
zoecarverd0279de2020-09-14 18:11:08 -04001427 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op move(_Ip, _Ip, _Op);
1428 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001429};
1430
Arthur O'Dwyer1ac9f092021-01-15 12:59:56 -05001431#if _LIBCPP_STD_VER <= 17
1432template <class _It>
1433struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1434#endif
1435
1436template <class _Iter>
1437_LIBCPP_CONSTEXPR
1438_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1439__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1440 return _VSTD::__to_address(__w.base());
1441}
1442
Howard Hinnantc51e1022010-05-11 19:42:16 +00001443template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001444inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001446operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447{
1448 return __x.base() == __y.base();
1449}
1450
1451template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001452inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001453bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001454operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455{
Louis Dionneba400782020-10-02 15:02:52 -04001456#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001457 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001458 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001459#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460 return __x.base() < __y.base();
1461}
1462
1463template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001464inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001465bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001466operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001468 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001469}
1470
1471template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001472inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001474operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001476 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001477}
1478
1479template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001480inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001481bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001482operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001483{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001484 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485}
1486
1487template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001488inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001489bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001490operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001492 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493}
1494
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001495template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001496inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001497bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001498operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001499{
1500 return !(__x == __y);
1501}
1502
1503template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001504inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001505bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001506operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001507{
1508 return __y < __x;
1509}
1510
1511template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001512inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001513bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001514operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001515{
1516 return !(__x < __y);
1517}
1518
1519template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001520inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001521bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001522operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001523{
1524 return !(__y < __x);
1525}
1526
Marshall Clow476d3f42016-07-18 13:19:00 +00001527#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001528template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001529inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001530auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001531operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001532-> decltype(__x.base() - __y.base())
1533{
Louis Dionneba400782020-10-02 15:02:52 -04001534#if _LIBCPP_DEBUG_LEVEL == 2
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001535 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1536 "Attempted to subtract incompatible iterators");
1537#endif
1538 return __x.base() - __y.base();
1539}
1540#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001541template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001542inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001543typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001544operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001545{
Louis Dionneba400782020-10-02 15:02:52 -04001546#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001547 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001548 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001549#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550 return __x.base() - __y.base();
1551}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001552#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001553
1554template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001555inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001556__wrap_iter<_Iter>
1557operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001558 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001559{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001560 __x += __n;
1561 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562}
1563
Marshall Clow039b2f02016-01-13 21:54:34 +00001564template <class _Iter>
1565struct __libcpp_is_trivial_iterator
Marshall Clowb5f99122016-11-02 15:30:26 +00001566 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
Louis Dionne173f29e2019-05-29 16:01:36 +00001567
Marshall Clow039b2f02016-01-13 21:54:34 +00001568template <class _Iter>
1569struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001570 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001571
1572template <class _Iter>
1573struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001574 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001575
1576template <class _Iter>
1577struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001578 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001579
1580
Marshall Clow8411ebf2013-12-02 03:24:33 +00001581template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001582_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001583_Tp*
1584begin(_Tp (&__array)[_Np])
1585{
1586 return __array;
1587}
1588
1589template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001590_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001591_Tp*
1592end(_Tp (&__array)[_Np])
1593{
1594 return __array + _Np;
1595}
1596
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001597#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001598
Howard Hinnantc834c512011-11-29 18:15:50 +00001599template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001600_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001601auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001602begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001603{
1604 return __c.begin();
1605}
1606
Howard Hinnantc834c512011-11-29 18:15:50 +00001607template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001608_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001610begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001611{
1612 return __c.begin();
1613}
1614
Howard Hinnantc834c512011-11-29 18:15:50 +00001615template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001616_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001617auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001618end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619{
1620 return __c.end();
1621}
1622
Howard Hinnantc834c512011-11-29 18:15:50 +00001623template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001624_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001626end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001627{
1628 return __c.end();
1629}
1630
Marshall Clowb278e9c2013-08-30 01:17:07 +00001631#if _LIBCPP_STD_VER > 11
1632
Marshall Clow8411ebf2013-12-02 03:24:33 +00001633template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001634_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001635reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1636{
1637 return reverse_iterator<_Tp*>(__array + _Np);
1638}
1639
1640template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001641_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001642reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1643{
1644 return reverse_iterator<_Tp*>(__array);
1645}
1646
1647template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001648_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001649reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1650{
1651 return reverse_iterator<const _Ep*>(__il.end());
1652}
1653
1654template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001655_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001656reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1657{
1658 return reverse_iterator<const _Ep*>(__il.begin());
1659}
1660
Marshall Clowb278e9c2013-08-30 01:17:07 +00001661template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001662_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001663auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001664{
Marshall Clow3862f532016-08-10 20:04:46 +00001665 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001666}
1667
1668template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001669_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001670auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001671{
Marshall Clow3862f532016-08-10 20:04:46 +00001672 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001673}
1674
1675template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001676_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001677auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1678{
1679 return __c.rbegin();
1680}
1681
1682template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001683_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001684auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1685{
1686 return __c.rbegin();
1687}
1688
1689template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001690_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001691auto rend(_Cp& __c) -> decltype(__c.rend())
1692{
1693 return __c.rend();
1694}
1695
1696template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001697_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001698auto rend(const _Cp& __c) -> decltype(__c.rend())
1699{
1700 return __c.rend();
1701}
1702
1703template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001704_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001705auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001706{
Marshall Clow3862f532016-08-10 20:04:46 +00001707 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001708}
1709
1710template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001711_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001712auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001713{
Marshall Clow3862f532016-08-10 20:04:46 +00001714 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001715}
1716
1717#endif
1718
1719
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001720#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001721
Howard Hinnantc834c512011-11-29 18:15:50 +00001722template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001723_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001724typename _Cp::iterator
1725begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001726{
1727 return __c.begin();
1728}
1729
Howard Hinnantc834c512011-11-29 18:15:50 +00001730template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001731_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001732typename _Cp::const_iterator
1733begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734{
1735 return __c.begin();
1736}
1737
Howard Hinnantc834c512011-11-29 18:15:50 +00001738template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001739_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001740typename _Cp::iterator
1741end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742{
1743 return __c.end();
1744}
1745
Howard Hinnantc834c512011-11-29 18:15:50 +00001746template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001747_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001748typename _Cp::const_iterator
1749end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001750{
1751 return __c.end();
1752}
1753
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001754#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001755
Marshall Clowef357272014-11-19 19:43:23 +00001756#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001757
1758// #if _LIBCPP_STD_VER > 11
1759// template <>
1760// struct _LIBCPP_TEMPLATE_VIS plus<void>
1761// {
1762// template <class _T1, class _T2>
1763// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1764// auto operator()(_T1&& __t, _T2&& __u) const
1765// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1766// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1767// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1768// typedef void is_transparent;
1769// };
1770// #endif
1771
Marshall Clowc4b4a342015-02-11 16:14:01 +00001772template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001773_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001774constexpr auto size(const _Cont& __c)
1775_NOEXCEPT_(noexcept(__c.size()))
1776-> decltype (__c.size())
1777{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001778
Marshall Clowc4b4a342015-02-11 16:14:01 +00001779template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001780_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001781constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001782
Marshall Clow3c5363e2019-02-27 02:58:56 +00001783#if _LIBCPP_STD_VER > 17
1784template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001785_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001786constexpr auto ssize(const _Cont& __c)
1787_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1788-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1789{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1790
1791template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001792_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001793constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1794#endif
1795
Marshall Clowc4b4a342015-02-11 16:14:01 +00001796template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001797_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001798constexpr auto empty(const _Cont& __c)
1799_NOEXCEPT_(noexcept(__c.empty()))
1800-> decltype (__c.empty())
1801{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001802
Marshall Clowc4b4a342015-02-11 16:14:01 +00001803template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001804_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001805constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001806
1807template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001808_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001809constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1810
Marshall Clowc4b4a342015-02-11 16:14:01 +00001811template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001812_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001813auto data(_Cont& __c)
1814_NOEXCEPT_(noexcept(__c.data()))
1815-> decltype (__c.data())
1816{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001817
Marshall Clowc4b4a342015-02-11 16:14:01 +00001818template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001819_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001820auto data(const _Cont& __c)
1821_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001822-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001823{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001824
Marshall Clowc4b4a342015-02-11 16:14:01 +00001825template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001826_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001827constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001828
1829template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001830_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001831constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1832#endif
1833
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001834template <class _Container, class _Predicate>
1835typename _Container::size_type
1836__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
1837 typename _Container::size_type __old_size = __c.size();
1838
1839 const typename _Container::iterator __last = __c.end();
1840 for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
1841 if (__pred(*__iter))
1842 __iter = __c.erase(__iter);
1843 else
1844 ++__iter;
1845 }
1846
1847 return __old_size - __c.size();
1848}
Marshall Clowef357272014-11-19 19:43:23 +00001849
Howard Hinnantc51e1022010-05-11 19:42:16 +00001850_LIBCPP_END_NAMESPACE_STD
1851
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001852#endif // _LIBCPP_ITERATOR