blob: 30801ea83dbdadb687f456e18a6e6fe93a6f80fe [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Chandler Carruth7c3769d2019-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 Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ITERATOR
11#define _LIBCPP_ITERATOR
12
13/*
14 iterator synopsis
15
16namespace std
17{
18
19template<class Iterator>
20struct iterator_traits
21{
22 typedef typename Iterator::difference_type difference_type;
23 typedef typename Iterator::value_type value_type;
24 typedef typename Iterator::pointer pointer;
25 typedef typename Iterator::reference reference;
26 typedef typename Iterator::iterator_category iterator_category;
27};
28
29template<class T>
30struct iterator_traits<T*>
31{
32 typedef ptrdiff_t difference_type;
33 typedef T value_type;
34 typedef T* pointer;
35 typedef T& reference;
36 typedef random_access_iterator_tag iterator_category;
37};
38
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000039template<class Category, class T, class Distance = ptrdiff_t,
40 class Pointer = T*, class Reference = T&>
41struct iterator
42{
43 typedef T value_type;
44 typedef Distance difference_type;
45 typedef Pointer pointer;
46 typedef Reference reference;
47 typedef Category iterator_category;
48};
49
50struct input_iterator_tag {};
51struct output_iterator_tag {};
52struct forward_iterator_tag : public input_iterator_tag {};
53struct bidirectional_iterator_tag : public forward_iterator_tag {};
54struct random_access_iterator_tag : public bidirectional_iterator_tag {};
55
Marshall Clow9e6b5402017-05-17 18:51:36 +000056// 27.4.3, iterator operations
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000057// extension: second argument not conforming to C++03
Marshall Clow9e6b5402017-05-17 18:51:36 +000058template <class InputIterator> // constexpr in C++17
59 constexpr void advance(InputIterator& i,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000060 typename iterator_traits<InputIterator>::difference_type n);
61
Marshall Clow9e6b5402017-05-17 18:51:36 +000062template <class InputIterator> // constexpr in C++17
63 constexpr typename iterator_traits<InputIterator>::difference_type
64 distance(InputIterator first, InputIterator last);
65
66template <class InputIterator> // constexpr in C++17
67 constexpr InputIterator next(InputIterator x,
68typename iterator_traits<InputIterator>::difference_type n = 1);
69
70template <class BidirectionalIterator> // constexpr in C++17
71 constexpr BidirectionalIterator prev(BidirectionalIterator x,
Louis Dionnec30e2d92019-05-29 16:01:36 +000072 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073
74template <class Iterator>
75class reverse_iterator
76 : public iterator<typename iterator_traits<Iterator>::iterator_category,
77 typename iterator_traits<Iterator>::value_type,
78 typename iterator_traits<Iterator>::difference_type,
79 typename iterator_traits<Iterator>::pointer,
80 typename iterator_traits<Iterator>::reference>
81{
82protected:
83 Iterator current;
84public:
85 typedef Iterator iterator_type;
86 typedef typename iterator_traits<Iterator>::difference_type difference_type;
87 typedef typename iterator_traits<Iterator>::reference reference;
88 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +000089
Marshall Clow4414a6a2016-10-19 15:12:50 +000090 constexpr reverse_iterator();
91 constexpr explicit reverse_iterator(Iterator x);
92 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
93 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
94 constexpr Iterator base() const;
95 constexpr reference operator*() const;
96 constexpr pointer operator->() const;
97 constexpr reverse_iterator& operator++();
98 constexpr reverse_iterator operator++(int);
99 constexpr reverse_iterator& operator--();
100 constexpr reverse_iterator operator--(int);
101 constexpr reverse_iterator operator+ (difference_type n) const;
102 constexpr reverse_iterator& operator+=(difference_type n);
103 constexpr reverse_iterator operator- (difference_type n) const;
104 constexpr reverse_iterator& operator-=(difference_type n);
105 constexpr reference operator[](difference_type n) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000106};
107
108template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000109constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000110operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
111
112template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000113constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000114operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
115
116template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000117constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000118operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
119
120template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000121constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000122operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
123
124template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000125constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
127
128template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000129constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000130operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
131
132template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000133constexpr auto
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000134operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow4414a6a2016-10-19 15:12:50 +0000135-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000136
137template <class Iterator>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000138constexpr reverse_iterator<Iterator>
Louis Dionnec30e2d92019-05-29 16:01:36 +0000139operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow4414a6a2016-10-19 15:12:50 +0000140 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141
Marshall Clow4414a6a2016-10-19 15:12:50 +0000142template <class Iterator>
143constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clowff137e92014-03-03 01:24:04 +0000144
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000145template <class Container>
146class back_insert_iterator
147{
148protected:
149 Container* container;
150public:
151 typedef Container container_type;
152 typedef void value_type;
153 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50 +0000154 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155 typedef void pointer;
156
157 explicit back_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000158 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000159 back_insert_iterator& operator*();
160 back_insert_iterator& operator++();
161 back_insert_iterator operator++(int);
162};
163
164template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
165
166template <class Container>
167class front_insert_iterator
168{
169protected:
170 Container* container;
171public:
172 typedef Container container_type;
173 typedef void value_type;
174 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50 +0000175 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176 typedef void pointer;
177
178 explicit front_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27 +0000179 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000180 front_insert_iterator& operator*();
181 front_insert_iterator& operator++();
182 front_insert_iterator operator++(int);
183};
184
185template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
186
187template <class Container>
188class insert_iterator
189{
190protected:
191 Container* container;
192 typename Container::iterator iter;
193public:
194 typedef Container container_type;
195 typedef void value_type;
196 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50 +0000197 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198 typedef void pointer;
199
200 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant45f57172010-09-14 20:26:27 +0000201 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202 insert_iterator& operator*();
203 insert_iterator& operator++();
204 insert_iterator& operator++(int);
205};
206
207template <class Container, class Iterator>
208insert_iterator<Container> inserter(Container& x, Iterator i);
209
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000210template <class Iterator>
211class move_iterator {
212public:
213 typedef Iterator iterator_type;
214 typedef typename iterator_traits<Iterator>::difference_type difference_type;
215 typedef Iterator pointer;
216 typedef typename iterator_traits<Iterator>::value_type value_type;
217 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
218 typedef value_type&& reference;
Louis Dionnec30e2d92019-05-29 16:01:36 +0000219
Marshall Clowf333bee2016-11-02 15:30:26 +0000220 constexpr move_iterator(); // all the constexprs are in C++17
221 constexpr explicit move_iterator(Iterator i);
222 template <class U>
223 constexpr move_iterator(const move_iterator<U>& u);
224 template <class U>
225 constexpr move_iterator& operator=(const move_iterator<U>& u);
226 constexpr iterator_type base() const;
227 constexpr reference operator*() const;
228 constexpr pointer operator->() const;
229 constexpr move_iterator& operator++();
230 constexpr move_iterator operator++(int);
231 constexpr move_iterator& operator--();
232 constexpr move_iterator operator--(int);
Louis Dionnec30e2d92019-05-29 16:01:36 +0000233 constexpr move_iterator operator+(difference_type n) const;
234 constexpr move_iterator& operator+=(difference_type n);
235 constexpr move_iterator operator-(difference_type n) const;
236 constexpr move_iterator& operator-=(difference_type n);
Marshall Clowf333bee2016-11-02 15:30:26 +0000237 constexpr unspecified operator[](difference_type n) const;
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000238private:
239 Iterator current; // exposition only
240};
241
242template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26 +0000243constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000244operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
245
246template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26 +0000247constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000248operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
249
250template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26 +0000251constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000252operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
253
254template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26 +0000255constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000256operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
257
258template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26 +0000259constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000260operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
261
262template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26 +0000263constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000264operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
265
266template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26 +0000267constexpr auto // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000268operator-(const move_iterator<Iterator1>& x,
269 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
270
271template <class Iterator>
Marshall Clowf333bee2016-11-02 15:30:26 +0000272constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionnec30e2d92019-05-29 16:01:36 +0000273 typename move_iterator<Iterator>::difference_type n,
Marshall Clowf333bee2016-11-02 15:30:26 +0000274 const move_iterator<Iterator>& x);
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000275
Marshall Clowf333bee2016-11-02 15:30:26 +0000276template <class Iterator> // constexpr in C++17
277constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000278
279
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
281class istream_iterator
282 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
283{
284public:
285 typedef charT char_type;
286 typedef traits traits_type;
287 typedef basic_istream<charT,traits> istream_type;
288
Marshall Clowe9d03062015-04-16 21:36:54 +0000289 constexpr istream_iterator();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290 istream_iterator(istream_type& s);
291 istream_iterator(const istream_iterator& x);
292 ~istream_iterator();
293
294 const T& operator*() const;
295 const T* operator->() const;
296 istream_iterator& operator++();
297 istream_iterator operator++(int);
298};
299
300template <class T, class charT, class traits, class Distance>
301bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
302 const istream_iterator<T,charT,traits,Distance>& y);
303template <class T, class charT, class traits, class Distance>
304bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
305 const istream_iterator<T,charT,traits,Distance>& y);
306
307template <class T, class charT = char, class traits = char_traits<charT> >
308class ostream_iterator
309 : public iterator<output_iterator_tag, void, void, void ,void>
310{
311public:
312 typedef charT char_type;
313 typedef traits traits_type;
314 typedef basic_ostream<charT,traits> ostream_type;
315
316 ostream_iterator(ostream_type& s);
317 ostream_iterator(ostream_type& s, const charT* delimiter);
318 ostream_iterator(const ostream_iterator& x);
319 ~ostream_iterator();
320 ostream_iterator& operator=(const T& value);
321
322 ostream_iterator& operator*();
323 ostream_iterator& operator++();
324 ostream_iterator& operator++(int);
325};
326
327template<class charT, class traits = char_traits<charT> >
328class istreambuf_iterator
329 : public iterator<input_iterator_tag, charT,
330 typename traits::off_type, unspecified,
331 charT>
332{
333public:
334 typedef charT char_type;
335 typedef traits traits_type;
336 typedef typename traits::int_type int_type;
337 typedef basic_streambuf<charT,traits> streambuf_type;
338 typedef basic_istream<charT,traits> istream_type;
339
Howard Hinnantd06a6402012-07-20 19:36:34 +0000340 istreambuf_iterator() noexcept;
341 istreambuf_iterator(istream_type& s) noexcept;
342 istreambuf_iterator(streambuf_type* s) noexcept;
343 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000344
345 charT operator*() const;
346 pointer operator->() const;
347 istreambuf_iterator& operator++();
348 a-private-type operator++(int);
349
350 bool equal(const istreambuf_iterator& b) const;
351};
352
353template <class charT, class traits>
354bool operator==(const istreambuf_iterator<charT,traits>& a,
355 const istreambuf_iterator<charT,traits>& b);
356template <class charT, class traits>
357bool operator!=(const istreambuf_iterator<charT,traits>& a,
358 const istreambuf_iterator<charT,traits>& b);
359
360template <class charT, class traits = char_traits<charT> >
361class ostreambuf_iterator
362 : public iterator<output_iterator_tag, void, void, void, void>
363{
364public:
365 typedef charT char_type;
366 typedef traits traits_type;
367 typedef basic_streambuf<charT,traits> streambuf_type;
368 typedef basic_ostream<charT,traits> ostream_type;
369
Howard Hinnantd06a6402012-07-20 19:36:34 +0000370 ostreambuf_iterator(ostream_type& s) noexcept;
371 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372 ostreambuf_iterator& operator=(charT c);
373 ostreambuf_iterator& operator*();
374 ostreambuf_iterator& operator++();
375 ostreambuf_iterator& operator++(int);
Howard Hinnantd06a6402012-07-20 19:36:34 +0000376 bool failed() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377};
378
Marshall Clowe22af6b2017-01-04 17:58:17 +0000379template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
380template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
381template <class C> constexpr auto end(C& c) -> decltype(c.end());
382template <class C> constexpr auto end(const C& c) -> decltype(c.end());
383template <class T, size_t N> constexpr T* begin(T (&array)[N]);
384template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385
Marshall Clowe22af6b2017-01-04 17:58:17 +0000386template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
387template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
388template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
389template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
390template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
391template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
392template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
393template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
394template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
395template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
396template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
397template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clow09da3c02013-08-30 01:17:07 +0000398
Marshall Clow03c67912014-11-19 19:43:23 +0000399// 24.8, container access:
400template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
401template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
Marshall Clowdd2ae122019-02-27 02:58:56 +0000402
403template <class C> constexpr auto ssize(const C& c)
404 -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
405template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
406
Marshall Clow03c67912014-11-19 19:43:23 +0000407template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
408template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
409template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
410template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
411template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
412template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
413template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
414
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415} // std
416
417*/
418
419#include <__config>
Eric Fiselierb3792282016-02-20 00:19:45 +0000420#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow02ca8af2014-02-27 02:11:50 +0000421#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422#include <type_traits>
423#include <cstddef>
Marshall Clow09da3c02013-08-30 01:17:07 +0000424#include <initializer_list>
Marshall Clowe3973fd2018-09-12 19:41:40 +0000425#include <version>
Marshall Clowdece7fe2013-03-18 17:45:34 +0000426#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15 +0000427#include <Availability.h>
428#endif
429
Eric Fiselierb9536102014-08-10 23:53:08 +0000430#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000431
Howard Hinnant08e17472011-10-17 20:05:10 +0000432#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000434#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435
436_LIBCPP_BEGIN_NAMESPACE_STD
437
Eric Fiselierc3589a82017-01-04 23:56:00 +0000438struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
439struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
440struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
441struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
442struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443
444template <class _Tp>
Marshall Clow3870a972018-11-13 05:33:31 +0000445struct __has_iterator_typedefs
446{
447private:
448 struct __two {char __lx; char __lxx;};
449 template <class _Up> static __two __test(...);
450 template <class _Up> static char __test(typename std::__void_t<typename _Up::iterator_category>::type* = 0,
451 typename std::__void_t<typename _Up::difference_type>::type* = 0,
452 typename std::__void_t<typename _Up::value_type>::type* = 0,
453 typename std::__void_t<typename _Up::reference>::type* = 0,
454 typename std::__void_t<typename _Up::pointer>::type* = 0
455 );
456public:
457 static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1;
458};
459
460
461template <class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462struct __has_iterator_category
463{
464private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000465 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 template <class _Up> static __two __test(...);
467 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
468public:
469 static const bool value = sizeof(__test<_Tp>(0)) == 1;
470};
471
Marshall Clowa71f9562014-01-03 22:55:49 +0000472template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000473
474template <class _Iter>
Marshall Clowa71f9562014-01-03 22:55:49 +0000475struct __iterator_traits_impl<_Iter, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476{
477 typedef typename _Iter::difference_type difference_type;
478 typedef typename _Iter::value_type value_type;
479 typedef typename _Iter::pointer pointer;
480 typedef typename _Iter::reference reference;
481 typedef typename _Iter::iterator_category iterator_category;
482};
483
484template <class _Iter, bool> struct __iterator_traits {};
485
486template <class _Iter>
487struct __iterator_traits<_Iter, true>
Marshall Clowa71f9562014-01-03 22:55:49 +0000488 : __iterator_traits_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489 <
490 _Iter,
491 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
492 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
493 >
494{};
495
496// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
497// exists. Else iterator_traits<Iterator> will be an empty class. This is a
498// conforming extension which allows some programs to compile and behave as
499// the client expects instead of failing at compile time.
500
501template <class _Iter>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000502struct _LIBCPP_TEMPLATE_VIS iterator_traits
Marshall Clow3870a972018-11-13 05:33:31 +0000503 : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504
505template<class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000506struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000507{
508 typedef ptrdiff_t difference_type;
Marshall Clowe1cfe7a2017-11-14 00:03:10 +0000509 typedef typename remove_cv<_Tp>::type value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510 typedef _Tp* pointer;
511 typedef _Tp& reference;
512 typedef random_access_iterator_tag iterator_category;
513};
514
515template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
516struct __has_iterator_category_convertible_to
517 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
518{};
519
520template <class _Tp, class _Up>
521struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
522
523template <class _Tp>
524struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
525
526template <class _Tp>
527struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
528
529template <class _Tp>
530struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
531
532template <class _Tp>
533struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
534
Marshall Clowdf9db312016-01-13 21:54:34 +0000535template <class _Tp>
536struct __is_exactly_input_iterator
Louis Dionnec30e2d92019-05-29 16:01:36 +0000537 : public integral_constant<bool,
538 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
Marshall Clowf333bee2016-11-02 15:30:26 +0000539 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
Marshall Clowdf9db312016-01-13 21:54:34 +0000540
Louis Dionnee46f6852019-06-20 19:32:00 +0000541#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
542template<class _InputIterator>
543using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
544
545template<class _InputIterator>
546using __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
547
548template<class _InputIterator>
549using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
550
551template<class _InputIterator>
552using __iter_to_alloc_type = pair<
553 add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
554 typename iterator_traits<_InputIterator>::value_type::second_type>;
555#endif
556
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557template<class _Category, class _Tp, class _Distance = ptrdiff_t,
558 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000559struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560{
561 typedef _Tp value_type;
562 typedef _Distance difference_type;
563 typedef _Pointer pointer;
564 typedef _Reference reference;
565 typedef _Category iterator_category;
566};
567
568template <class _InputIter>
Marshall Clow9e6b5402017-05-17 18:51:36 +0000569inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570void __advance(_InputIter& __i,
571 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
572{
573 for (; __n > 0; --__n)
574 ++__i;
575}
576
577template <class _BiDirIter>
Marshall Clow9e6b5402017-05-17 18:51:36 +0000578inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579void __advance(_BiDirIter& __i,
580 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
581{
582 if (__n >= 0)
583 for (; __n > 0; --__n)
584 ++__i;
585 else
586 for (; __n < 0; ++__n)
587 --__i;
588}
589
590template <class _RandIter>
Marshall Clow9e6b5402017-05-17 18:51:36 +0000591inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000592void __advance(_RandIter& __i,
593 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
594{
595 __i += __n;
596}
597
598template <class _InputIter>
Marshall Clow9e6b5402017-05-17 18:51:36 +0000599inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600void advance(_InputIter& __i,
601 typename iterator_traits<_InputIter>::difference_type __n)
602{
Marshall Clowd36fc702019-03-22 22:32:20 +0000603 _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value,
604 "Attempt to advance(it, -n) on a non-bidi iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
606}
607
608template <class _InputIter>
Marshall Clow9e6b5402017-05-17 18:51:36 +0000609inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610typename iterator_traits<_InputIter>::difference_type
611__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
612{
613 typename iterator_traits<_InputIter>::difference_type __r(0);
614 for (; __first != __last; ++__first)
615 ++__r;
616 return __r;
617}
618
619template <class _RandIter>
Marshall Clow9e6b5402017-05-17 18:51:36 +0000620inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621typename iterator_traits<_RandIter>::difference_type
622__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
623{
624 return __last - __first;
625}
626
627template <class _InputIter>
Marshall Clow9e6b5402017-05-17 18:51:36 +0000628inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629typename iterator_traits<_InputIter>::difference_type
630distance(_InputIter __first, _InputIter __last)
631{
632 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
633}
634
Marshall Clowe9ef9882015-11-07 17:48:49 +0000635template <class _InputIter>
Marshall Clow9e6b5402017-05-17 18:51:36 +0000636inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik24047fd2017-07-24 22:17:05 +0000637typename enable_if
638<
Louis Dionnec30e2d92019-05-29 16:01:36 +0000639 __is_input_iterator<_InputIter>::value,
Rachel Craik24047fd2017-07-24 22:17:05 +0000640 _InputIter
641>::type
Marshall Clowe9ef9882015-11-07 17:48:49 +0000642next(_InputIter __x,
Rachel Craik24047fd2017-07-24 22:17:05 +0000643 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644{
Marshall Clowd36fc702019-03-22 22:32:20 +0000645 _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value,
646 "Attempt to next(it, -n) on a non-bidi iterator");
647
Howard Hinnant0949eed2011-06-30 21:18:19 +0000648 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649 return __x;
650}
651
Marshall Clowd36fc702019-03-22 22:32:20 +0000652template <class _InputIter>
Marshall Clow9e6b5402017-05-17 18:51:36 +0000653inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik24047fd2017-07-24 22:17:05 +0000654typename enable_if
655<
Louis Dionnec30e2d92019-05-29 16:01:36 +0000656 __is_input_iterator<_InputIter>::value,
Marshall Clowd36fc702019-03-22 22:32:20 +0000657 _InputIter
Rachel Craik24047fd2017-07-24 22:17:05 +0000658>::type
Marshall Clowd36fc702019-03-22 22:32:20 +0000659prev(_InputIter __x,
660 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661{
Marshall Clowd36fc702019-03-22 22:32:20 +0000662 _LIBCPP_ASSERT(__n <= 0 || __is_bidirectional_iterator<_InputIter>::value,
663 "Attempt to prev(it, +n) on a non-bidi iterator");
Howard Hinnant0949eed2011-06-30 21:18:19 +0000664 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 return __x;
666}
667
Eric Fiselier706e2c72017-04-13 02:54:13 +0000668
669template <class _Tp, class = void>
670struct __is_stashing_iterator : false_type {};
671
672template <class _Tp>
673struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
674 : true_type {};
675
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676template <class _Iter>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000677class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678 : public iterator<typename iterator_traits<_Iter>::iterator_category,
679 typename iterator_traits<_Iter>::value_type,
680 typename iterator_traits<_Iter>::difference_type,
681 typename iterator_traits<_Iter>::pointer,
682 typename iterator_traits<_Iter>::reference>
683{
Marshall Clow668a1d82014-03-11 22:05:31 +0000684private:
Marshall Clow4414a6a2016-10-19 15:12:50 +0000685 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier706e2c72017-04-13 02:54:13 +0000686
687 static_assert(!__is_stashing_iterator<_Iter>::value,
688 "The specified iterator type cannot be used with reverse_iterator; "
689 "Using stashing iterators with reverse_iterator causes undefined behavior");
690
Marshall Clow5a8e27b2014-03-12 01:19:36 +0000691protected:
692 _Iter current;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693public:
694 typedef _Iter iterator_type;
695 typedef typename iterator_traits<_Iter>::difference_type difference_type;
696 typedef typename iterator_traits<_Iter>::reference reference;
697 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43 +0000698
Marshall Clow4414a6a2016-10-19 15:12:50 +0000699 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
700 reverse_iterator() : __t(), current() {}
701 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
702 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
703 template <class _Up>
704 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
705 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
706 template <class _Up>
707 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
708 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
709 { __t = current = __u.base(); return *this; }
710 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
711 _Iter base() const {return current;}
712 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
713 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
714 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
715 pointer operator->() const {return _VSTD::addressof(operator*());}
716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
717 reverse_iterator& operator++() {--current; return *this;}
718 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
719 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
720 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
721 reverse_iterator& operator--() {++current; return *this;}
722 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
723 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
724 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
725 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
726 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
727 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
728 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
729 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
730 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
731 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
732 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
733 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734};
735
736template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000737inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738bool
739operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
740{
741 return __x.base() == __y.base();
742}
743
744template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000745inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746bool
747operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
748{
749 return __x.base() > __y.base();
750}
751
752template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000753inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754bool
755operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
756{
757 return __x.base() != __y.base();
758}
759
760template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000761inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762bool
763operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
764{
765 return __x.base() < __y.base();
766}
767
768template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000769inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770bool
771operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
772{
773 return __x.base() <= __y.base();
774}
775
776template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000777inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000778bool
779operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
780{
781 return __x.base() >= __y.base();
782}
783
Marshall Clow3f013892016-07-18 13:19:00 +0000784#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000785template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000786inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000787auto
788operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
789-> decltype(__y.base() - __x.base())
790{
791 return __y.base() - __x.base();
792}
793#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794template <class _Iter1, class _Iter2>
795inline _LIBCPP_INLINE_VISIBILITY
796typename reverse_iterator<_Iter1>::difference_type
797operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
798{
799 return __y.base() - __x.base();
800}
Marshall Clowdf4a22d2016-07-08 16:54:47 +0000801#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000802
803template <class _Iter>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000804inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805reverse_iterator<_Iter>
806operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
807{
808 return reverse_iterator<_Iter>(__x.base() - __n);
809}
810
Marshall Clowff137e92014-03-03 01:24:04 +0000811#if _LIBCPP_STD_VER > 11
812template <class _Iter>
Marshall Clow4414a6a2016-10-19 15:12:50 +0000813inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowff137e92014-03-03 01:24:04 +0000814reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
815{
816 return reverse_iterator<_Iter>(__i);
817}
818#endif
819
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820template <class _Container>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000821class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822 : public iterator<output_iterator_tag,
823 void,
824 void,
825 void,
Eric Fiselierc848cef2016-06-30 04:40:50 +0000826 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827{
828protected:
829 _Container* container;
830public:
831 typedef _Container container_type;
832
Marshall Clow53c0e722014-03-03 19:20:40 +0000833 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000834 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
835 {container->push_back(__value_); return *this;}
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000836#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant78b68282011-10-22 20:59:45 +0000837 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
838 {container->push_back(_VSTD::move(__value_)); return *this;}
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000839#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
841 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
842 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
843};
844
845template <class _Container>
846inline _LIBCPP_INLINE_VISIBILITY
847back_insert_iterator<_Container>
848back_inserter(_Container& __x)
849{
850 return back_insert_iterator<_Container>(__x);
851}
852
853template <class _Container>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000854class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855 : public iterator<output_iterator_tag,
856 void,
857 void,
858 void,
Eric Fiselierc848cef2016-06-30 04:40:50 +0000859 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860{
861protected:
862 _Container* container;
863public:
864 typedef _Container container_type;
865
Marshall Clow53c0e722014-03-03 19:20:40 +0000866 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000867 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
868 {container->push_front(__value_); return *this;}
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000869#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant78b68282011-10-22 20:59:45 +0000870 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
871 {container->push_front(_VSTD::move(__value_)); return *this;}
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000872#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
874 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
875 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
876};
877
878template <class _Container>
879inline _LIBCPP_INLINE_VISIBILITY
880front_insert_iterator<_Container>
881front_inserter(_Container& __x)
882{
883 return front_insert_iterator<_Container>(__x);
884}
885
886template <class _Container>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000887class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 : public iterator<output_iterator_tag,
889 void,
890 void,
891 void,
Eric Fiselierc848cef2016-06-30 04:40:50 +0000892 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893{
894protected:
895 _Container* container;
896 typename _Container::iterator iter;
897public:
898 typedef _Container container_type;
899
900 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clow53c0e722014-03-03 19:20:40 +0000901 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000902 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
903 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000904#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant78b68282011-10-22 20:59:45 +0000905 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
906 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000907#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
909 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
910 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
911};
912
913template <class _Container>
914inline _LIBCPP_INLINE_VISIBILITY
915insert_iterator<_Container>
916inserter(_Container& __x, typename _Container::iterator __i)
917{
918 return insert_iterator<_Container>(__x, __i);
919}
920
921template <class _Tp, class _CharT = char,
922 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000923class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000924 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
925{
926public:
927 typedef _CharT char_type;
928 typedef _Traits traits_type;
929 typedef basic_istream<_CharT,_Traits> istream_type;
930private:
931 istream_type* __in_stream_;
932 _Tp __value_;
933public:
Marshall Clowe9d03062015-04-16 21:36:54 +0000934 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000935 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936 {
937 if (!(*__in_stream_ >> __value_))
938 __in_stream_ = 0;
939 }
940
941 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000942 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
944 {
945 if (!(*__in_stream_ >> __value_))
946 __in_stream_ = 0;
947 return *this;
948 }
949 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
950 {istream_iterator __t(*this); ++(*this); return __t;}
951
Roger Ferrer Ibanez4a3242f2017-12-11 13:54:58 +0000952 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000953 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanez4a3242f2017-12-11 13:54:58 +0000954 bool
955 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
956 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957
Roger Ferrer Ibanez4a3242f2017-12-11 13:54:58 +0000958 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000959 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanez4a3242f2017-12-11 13:54:58 +0000960 bool
961 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
962 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963};
964
Roger Ferrer Ibanez4a3242f2017-12-11 13:54:58 +0000965template <class _Tp, class _CharT, class _Traits, class _Distance>
966inline _LIBCPP_INLINE_VISIBILITY
967bool
968operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
969 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
970{
971 return __x.__in_stream_ == __y.__in_stream_;
972}
973
974template <class _Tp, class _CharT, class _Traits, class _Distance>
975inline _LIBCPP_INLINE_VISIBILITY
976bool
977operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
978 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
979{
980 return !(__x == __y);
981}
982
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierc3589a82017-01-04 23:56:00 +0000984class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985 : public iterator<output_iterator_tag, void, void, void, void>
986{
987public:
988 typedef _CharT char_type;
989 typedef _Traits traits_type;
990 typedef basic_ostream<_CharT,_Traits> ostream_type;
991private:
992 ostream_type* __out_stream_;
993 const char_type* __delim_;
994public:
Marshall Clowb6361282016-10-12 16:13:48 +0000995 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000996 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
Marshall Clowb6361282016-10-12 16:13:48 +0000997 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowd8fc1ec2016-05-17 17:44:40 +0000998 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45 +0000999 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001000 {
Howard Hinnant78b68282011-10-22 20:59:45 +00001001 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001002 if (__delim_)
1003 *__out_stream_ << __delim_;
1004 return *this;
1005 }
1006
1007 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
1008 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
1009 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
1010};
1011
1012template<class _CharT, class _Traits>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001013class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 : public iterator<input_iterator_tag, _CharT,
1015 typename _Traits::off_type, _CharT*,
1016 _CharT>
1017{
1018public:
1019 typedef _CharT char_type;
1020 typedef _Traits traits_type;
1021 typedef typename _Traits::int_type int_type;
1022 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1023 typedef basic_istream<_CharT,_Traits> istream_type;
1024private:
Howard Hinnant984f10f2012-11-16 22:17:23 +00001025 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001026
1027 class __proxy
1028 {
1029 char_type __keep_;
1030 streambuf_type* __sbuf_;
1031 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
1032 : __keep_(__c), __sbuf_(__s) {}
1033 friend class istreambuf_iterator;
1034 public:
1035 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
1036 };
1037
Howard Hinnant82894812010-09-22 16:48:34 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23 +00001039 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001040 {
1041 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
1042 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23 +00001043 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044 }
1045public:
Howard Hinnant984f10f2012-11-16 22:17:23 +00001046 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +00001047 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +00001048 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +00001049 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42 +00001050 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +00001051 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052 : __sbuf_(__p.__sbuf_) {}
1053
Howard Hinnantec3773c2011-12-01 20:21:04 +00001054 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1055 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1057 {
Howard Hinnant984f10f2012-11-16 22:17:23 +00001058 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059 return *this;
1060 }
1061 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1062 {
Howard Hinnant984f10f2012-11-16 22:17:23 +00001063 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064 }
1065
1066 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23 +00001067 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001068};
1069
1070template <class _CharT, class _Traits>
1071inline _LIBCPP_INLINE_VISIBILITY
1072bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1073 const istreambuf_iterator<_CharT,_Traits>& __b)
1074 {return __a.equal(__b);}
1075
1076template <class _CharT, class _Traits>
1077inline _LIBCPP_INLINE_VISIBILITY
1078bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1079 const istreambuf_iterator<_CharT,_Traits>& __b)
1080 {return !__a.equal(__b);}
1081
1082template <class _CharT, class _Traits>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001083class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001084 : public iterator<output_iterator_tag, void, void, void, void>
1085{
1086public:
1087 typedef _CharT char_type;
1088 typedef _Traits traits_type;
1089 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1090 typedef basic_ostream<_CharT,_Traits> ostream_type;
1091private:
1092 streambuf_type* __sbuf_;
1093public:
Howard Hinnantd06a6402012-07-20 19:36:34 +00001094 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34 +00001096 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097 : __sbuf_(__s) {}
1098 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1099 {
1100 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1101 __sbuf_ = 0;
1102 return *this;
1103 }
1104 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1105 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1106 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:34 +00001107 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:15 +00001108
1109 template <class _Ch, class _Tr>
1110 friend
1111 _LIBCPP_HIDDEN
1112 ostreambuf_iterator<_Ch, _Tr>
1113 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1114 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1115 ios_base& __iob, _Ch __fl);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116};
1117
1118template <class _Iter>
Eric Fiselierc3589a82017-01-04 23:56:00 +00001119class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120{
1121private:
1122 _Iter __i;
1123public:
1124 typedef _Iter iterator_type;
1125 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1126 typedef typename iterator_traits<iterator_type>::value_type value_type;
1127 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowdca800c2016-04-11 03:54:53 +00001128 typedef iterator_type pointer;
Eric Fiselieraa55cef2017-04-19 01:34:08 +00001129#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierdf46b782016-04-22 00:49:12 +00001130 typedef typename iterator_traits<iterator_type>::reference __reference;
1131 typedef typename conditional<
1132 is_reference<__reference>::value,
1133 typename remove_reference<__reference>::type&&,
1134 __reference
1135 >::type reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136#else
1137 typedef typename iterator_traits<iterator_type>::reference reference;
1138#endif
Howard Hinnant324bb032010-08-22 00:02:43 +00001139
Marshall Clowf333bee2016-11-02 15:30:26 +00001140 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1141 move_iterator() : __i() {}
1142 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1143 explicit move_iterator(_Iter __x) : __i(__x) {}
1144 template <class _Up>
1145 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1146 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1147 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionnec30e2d92019-05-29 16:01:36 +00001148 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf333bee2016-11-02 15:30:26 +00001149 reference operator*() const { return static_cast<reference>(*__i); }
1150 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1151 pointer operator->() const { return __i;}
1152 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1153 move_iterator& operator++() {++__i; return *this;}
1154 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1155 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1156 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1157 move_iterator& operator--() {--__i; return *this;}
1158 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1159 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1160 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1161 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1162 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1163 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1164 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1165 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1166 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1167 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1168 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1169 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170};
1171
1172template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:26 +00001173inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174bool
1175operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1176{
1177 return __x.base() == __y.base();
1178}
1179
1180template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:26 +00001181inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001182bool
1183operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1184{
1185 return __x.base() < __y.base();
1186}
1187
1188template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:26 +00001189inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001190bool
1191operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1192{
1193 return __x.base() != __y.base();
1194}
1195
1196template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:26 +00001197inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198bool
1199operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1200{
1201 return __x.base() > __y.base();
1202}
1203
1204template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:26 +00001205inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206bool
1207operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1208{
1209 return __x.base() >= __y.base();
1210}
1211
1212template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:26 +00001213inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001214bool
1215operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1216{
1217 return __x.base() <= __y.base();
1218}
1219
Marshall Clow3f013892016-07-18 13:19:00 +00001220#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001221template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:26 +00001222inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001223auto
1224operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1225-> decltype(__x.base() - __y.base())
1226{
1227 return __x.base() - __y.base();
1228}
1229#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230template <class _Iter1, class _Iter2>
1231inline _LIBCPP_INLINE_VISIBILITY
1232typename move_iterator<_Iter1>::difference_type
1233operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1234{
1235 return __x.base() - __y.base();
1236}
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001237#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238
1239template <class _Iter>
Marshall Clowf333bee2016-11-02 15:30:26 +00001240inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241move_iterator<_Iter>
1242operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1243{
1244 return move_iterator<_Iter>(__x.base() + __n);
1245}
1246
1247template <class _Iter>
Marshall Clowf333bee2016-11-02 15:30:26 +00001248inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001249move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:03 +00001250make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001251{
1252 return move_iterator<_Iter>(__i);
1253}
1254
1255// __wrap_iter
1256
1257template <class _Iter> class __wrap_iter;
1258
1259template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001260_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001261bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001262operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263
1264template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001265_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001267operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268
1269template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001270_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001272operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273
1274template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001275_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001276bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001277operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278
1279template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001280_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001281bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001282operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283
1284template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001285_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001287operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288
Marshall Clow3f013892016-07-18 13:19:00 +00001289#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001290template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001291_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001292auto
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001293operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001294-> decltype(__x.base() - __y.base());
1295#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001296template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:16 +00001297_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298typename __wrap_iter<_Iter1>::difference_type
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001299operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001300#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001301
1302template <class _Iter>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001303_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001304__wrap_iter<_Iter>
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001305operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306
Howard Hinnant33be35e2012-09-14 00:39:16 +00001307template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1308template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1309template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1310template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001311
Eric Fiselier2c8aa052016-12-28 05:35:32 +00001312#if _LIBCPP_DEBUG_LEVEL < 2
1313
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314template <class _Tp>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001315_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316typename enable_if
1317<
Howard Hinnant1468b662010-11-19 22:17:28 +00001318 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319 _Tp*
1320>::type
1321__unwrap_iter(__wrap_iter<_Tp*>);
1322
Eric Fiselier2c8aa052016-12-28 05:35:32 +00001323#else
1324
1325template <class _Tp>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001326inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Eric Fiselier2c8aa052016-12-28 05:35:32 +00001327typename enable_if
1328<
1329 is_trivially_copy_assignable<_Tp>::value,
1330 __wrap_iter<_Tp*>
1331>::type
1332__unwrap_iter(__wrap_iter<_Tp*> __i);
1333
1334#endif
1335
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336template <class _Iter>
1337class __wrap_iter
1338{
1339public:
1340 typedef _Iter iterator_type;
1341 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1342 typedef typename iterator_traits<iterator_type>::value_type value_type;
1343 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1344 typedef typename iterator_traits<iterator_type>::pointer pointer;
1345 typedef typename iterator_traits<iterator_type>::reference reference;
1346private:
1347 iterator_type __i;
1348public:
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001349 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow0f164c92013-08-07 20:48:48 +00001350#if _LIBCPP_STD_VER > 11
1351 : __i{}
1352#endif
Howard Hinnant7608b4a2011-09-16 19:52:23 +00001353 {
1354#if _LIBCPP_DEBUG_LEVEL >= 2
1355 __get_db()->__insert_i(this);
1356#endif
1357 }
Marshall Clowc005c7e2018-07-13 16:35:26 +00001358 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1359 __wrap_iter(const __wrap_iter<_Up>& __u,
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001360 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Marshall Clowc005c7e2018-07-13 16:35:26 +00001361 : __i(__u.base())
Howard Hinnant7a563db2011-09-14 18:33:51 +00001362 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001363#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001364 __get_db()->__iterator_copy(this, &__u);
1365#endif
1366 }
Howard Hinnantabe26282011-09-16 17:29:17 +00001367#if _LIBCPP_DEBUG_LEVEL >= 2
Marshall Clowc005c7e2018-07-13 16:35:26 +00001368 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant7a563db2011-09-14 18:33:51 +00001369 __wrap_iter(const __wrap_iter& __x)
1370 : __i(__x.base())
1371 {
1372 __get_db()->__iterator_copy(this, &__x);
1373 }
Marshall Clowc005c7e2018-07-13 16:35:26 +00001374 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant7a563db2011-09-14 18:33:51 +00001375 __wrap_iter& operator=(const __wrap_iter& __x)
1376 {
1377 if (this != &__x)
1378 {
1379 __get_db()->__iterator_copy(this, &__x);
1380 __i = __x.__i;
1381 }
1382 return *this;
1383 }
Marshall Clowc005c7e2018-07-13 16:35:26 +00001384 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant7a563db2011-09-14 18:33:51 +00001385 ~__wrap_iter()
1386 {
1387 __get_db()->__erase_i(this);
1388 }
1389#endif
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001390 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001391 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001392#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001393 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1394 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001395#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001396 return *__i;
1397 }
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001398 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001399 {
1400#if _LIBCPP_DEBUG_LEVEL >= 2
1401 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1402 "Attempted to dereference a non-dereferenceable iterator");
1403#endif
Marshall Clowdca800c2016-04-11 03:54:53 +00001404 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001405 }
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001406 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001407 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001408#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001409 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1410 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001411#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001412 ++__i;
1413 return *this;
1414 }
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001415 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001416 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clowd7d3d8b2018-07-14 03:06:11 +00001417
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001418 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001419 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001420#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001421 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1422 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:17 +00001423#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001424 --__i;
1425 return *this;
1426 }
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001427 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001428 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001429 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001430 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001431 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001432 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001433#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001434 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1435 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001436#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001437 __i += __n;
1438 return *this;
1439 }
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001440 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001441 {return *this + (-__n);}
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001442 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001443 {*this += -__n; return *this;}
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001444 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +00001445 {
Howard Hinnantabe26282011-09-16 17:29:17 +00001446#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001447 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1448 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:17 +00001449#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001450 return __i[__n];
1451 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001453 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001454
1455private:
Howard Hinnantabe26282011-09-16 17:29:17 +00001456#if _LIBCPP_DEBUG_LEVEL >= 2
Marshall Clowc005c7e2018-07-13 16:35:26 +00001457 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant7a563db2011-09-14 18:33:51 +00001458 {
1459 __get_db()->__insert_ic(this, __p);
1460 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001461#else
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001462 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:51 +00001463#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001464
1465 template <class _Up> friend class __wrap_iter;
1466 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierc3589a82017-01-04 23:56:00 +00001467 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowb3c66aa2019-02-27 00:32:16 +00001468 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469
1470 template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001471 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472 bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001473 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001474
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475 template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001476 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477 bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001478 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001479
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001480 template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001481 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001482 bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001483 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001484
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485 template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001486 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001488 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001489
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001490 template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001491 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001492 bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001493 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001494
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495 template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001496 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001497 bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001498 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001499
Marshall Clow3f013892016-07-18 13:19:00 +00001500#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001501 template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001502 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001503 auto
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001504 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001505 -> decltype(__x.base() - __y.base());
1506#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507 template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001508 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509 typename __wrap_iter<_Iter1>::difference_type
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001510 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001511#endif
Howard Hinnant324bb032010-08-22 00:02:43 +00001512
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513 template <class _Iter1>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001514 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515 __wrap_iter<_Iter1>
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001516 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517
Howard Hinnant99968442011-11-29 18:15:50 +00001518 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:50 +00001520 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001521 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1522
Eric Fiselier2c8aa052016-12-28 05:35:32 +00001523#if _LIBCPP_DEBUG_LEVEL < 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001524 template <class _Tp>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001525 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526 typename enable_if
1527 <
Howard Hinnant1468b662010-11-19 22:17:28 +00001528 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529 _Tp*
1530 >::type
1531 __unwrap_iter(__wrap_iter<_Tp*>);
Eric Fiselier2c8aa052016-12-28 05:35:32 +00001532#else
1533 template <class _Tp>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001534 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Eric Fiselier2c8aa052016-12-28 05:35:32 +00001535 typename enable_if
1536 <
1537 is_trivially_copy_assignable<_Tp>::value,
1538 __wrap_iter<_Tp*>
1539 >::type
1540 __unwrap_iter(__wrap_iter<_Tp*> __i);
1541#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542};
1543
1544template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001545inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001546bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001547operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548{
1549 return __x.base() == __y.base();
1550}
1551
1552template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001553inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001555operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001556{
Howard Hinnantabe26282011-09-16 17:29:17 +00001557#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001558 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001559 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001560#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001561 return __x.base() < __y.base();
1562}
1563
1564template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001565inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001566bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001567operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001568{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001569 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001570}
1571
1572template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001573inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001574bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001575operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001577 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578}
1579
1580template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001581inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001583operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001584{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001585 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586}
1587
1588template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001589inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001591operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001592{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001593 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001594}
1595
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001596template <class _Iter1>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001597inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001598bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001599operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001600{
1601 return !(__x == __y);
1602}
1603
1604template <class _Iter1>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001605inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001606bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001607operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001608{
1609 return __y < __x;
1610}
1611
1612template <class _Iter1>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001613inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001614bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001615operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001616{
1617 return !(__x < __y);
1618}
1619
1620template <class _Iter1>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001621inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001622bool
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001623operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnant95c0e9f2012-10-02 19:45:42 +00001624{
1625 return !(__y < __x);
1626}
1627
Marshall Clow3f013892016-07-18 13:19:00 +00001628#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001629template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001630inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001631auto
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001632operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001633-> decltype(__x.base() - __y.base())
1634{
1635#if _LIBCPP_DEBUG_LEVEL >= 2
1636 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1637 "Attempted to subtract incompatible iterators");
1638#endif
1639 return __x.base() - __y.base();
1640}
1641#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642template <class _Iter1, class _Iter2>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001643inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644typename __wrap_iter<_Iter1>::difference_type
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001645operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646{
Howard Hinnantabe26282011-09-16 17:29:17 +00001647#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:35 +00001648 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:51 +00001649 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:17 +00001650#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651 return __x.base() - __y.base();
1652}
Marshall Clowdf4a22d2016-07-08 16:54:47 +00001653#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001654
1655template <class _Iter>
Marshall Clowc005c7e2018-07-13 16:35:26 +00001656inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001657__wrap_iter<_Iter>
1658operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiseliereb2e3972019-03-18 21:50:12 +00001659 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001661 __x += __n;
1662 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663}
1664
Marshall Clowdf9db312016-01-13 21:54:34 +00001665template <class _Iter>
1666struct __libcpp_is_trivial_iterator
Marshall Clowf333bee2016-11-02 15:30:26 +00001667 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
Louis Dionnec30e2d92019-05-29 16:01:36 +00001668
Marshall Clowdf9db312016-01-13 21:54:34 +00001669template <class _Iter>
1670struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
Marshall Clowf333bee2016-11-02 15:30:26 +00001671 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clowdf9db312016-01-13 21:54:34 +00001672
1673template <class _Iter>
1674struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
Marshall Clowf333bee2016-11-02 15:30:26 +00001675 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clowdf9db312016-01-13 21:54:34 +00001676
1677template <class _Iter>
1678struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
Marshall Clowf333bee2016-11-02 15:30:26 +00001679 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clowdf9db312016-01-13 21:54:34 +00001680
1681
Marshall Clow6daf5342013-12-02 03:24:33 +00001682template <class _Tp, size_t _Np>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001683_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001684_Tp*
1685begin(_Tp (&__array)[_Np])
1686{
1687 return __array;
1688}
1689
1690template <class _Tp, size_t _Np>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001691_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:33 +00001692_Tp*
1693end(_Tp (&__array)[_Np])
1694{
1695 return __array + _Np;
1696}
1697
Eric Fiselier4e3e15a2016-09-25 03:34:28 +00001698#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow1c398692013-12-11 19:32:32 +00001699
Howard Hinnant99968442011-11-29 18:15:50 +00001700template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001701_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702auto
Howard Hinnant99968442011-11-29 18:15:50 +00001703begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704{
1705 return __c.begin();
1706}
1707
Howard Hinnant99968442011-11-29 18:15:50 +00001708template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001709_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001710auto
Howard Hinnant99968442011-11-29 18:15:50 +00001711begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001712{
1713 return __c.begin();
1714}
1715
Howard Hinnant99968442011-11-29 18:15:50 +00001716template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001717_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718auto
Howard Hinnant99968442011-11-29 18:15:50 +00001719end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720{
1721 return __c.end();
1722}
1723
Howard Hinnant99968442011-11-29 18:15:50 +00001724template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001725_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726auto
Howard Hinnant99968442011-11-29 18:15:50 +00001727end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001728{
1729 return __c.end();
1730}
1731
Marshall Clow09da3c02013-08-30 01:17:07 +00001732#if _LIBCPP_STD_VER > 11
1733
Marshall Clow6daf5342013-12-02 03:24:33 +00001734template <class _Tp, size_t _Np>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001735_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:33 +00001736reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1737{
1738 return reverse_iterator<_Tp*>(__array + _Np);
1739}
1740
1741template <class _Tp, size_t _Np>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001742_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:33 +00001743reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1744{
1745 return reverse_iterator<_Tp*>(__array);
1746}
1747
1748template <class _Ep>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001749_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:33 +00001750reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1751{
1752 return reverse_iterator<const _Ep*>(__il.end());
1753}
1754
1755template <class _Ep>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001756_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:33 +00001757reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1758{
1759 return reverse_iterator<const _Ep*>(__il.begin());
1760}
1761
Marshall Clow09da3c02013-08-30 01:17:07 +00001762template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001763_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow02e94f82016-08-10 20:04:46 +00001764auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clow09da3c02013-08-30 01:17:07 +00001765{
Marshall Clow02e94f82016-08-10 20:04:46 +00001766 return _VSTD::begin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001767}
1768
1769template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001770_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow02e94f82016-08-10 20:04:46 +00001771auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clow09da3c02013-08-30 01:17:07 +00001772{
Marshall Clow02e94f82016-08-10 20:04:46 +00001773 return _VSTD::end(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001774}
1775
1776template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001777_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:07 +00001778auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1779{
1780 return __c.rbegin();
1781}
1782
1783template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001784_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:07 +00001785auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1786{
1787 return __c.rbegin();
1788}
1789
1790template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001791_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:07 +00001792auto rend(_Cp& __c) -> decltype(__c.rend())
1793{
1794 return __c.rend();
1795}
1796
1797template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001798_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:07 +00001799auto rend(const _Cp& __c) -> decltype(__c.rend())
1800{
1801 return __c.rend();
1802}
1803
1804template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001805_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow02e94f82016-08-10 20:04:46 +00001806auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clow09da3c02013-08-30 01:17:07 +00001807{
Marshall Clow02e94f82016-08-10 20:04:46 +00001808 return _VSTD::rbegin(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001809}
1810
1811template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001812_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow02e94f82016-08-10 20:04:46 +00001813auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clow09da3c02013-08-30 01:17:07 +00001814{
Marshall Clow02e94f82016-08-10 20:04:46 +00001815 return _VSTD::rend(__c);
Marshall Clow09da3c02013-08-30 01:17:07 +00001816}
1817
1818#endif
1819
1820
Eric Fiselier4e3e15a2016-09-25 03:34:28 +00001821#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822
Howard Hinnant99968442011-11-29 18:15:50 +00001823template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001824_LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001825typename _Cp::iterator
1826begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001827{
1828 return __c.begin();
1829}
1830
Howard Hinnant99968442011-11-29 18:15:50 +00001831template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001832_LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001833typename _Cp::const_iterator
1834begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835{
1836 return __c.begin();
1837}
1838
Howard Hinnant99968442011-11-29 18:15:50 +00001839template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001840_LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001841typename _Cp::iterator
1842end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001843{
1844 return __c.end();
1845}
1846
Howard Hinnant99968442011-11-29 18:15:50 +00001847template <class _Cp>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001848_LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001849typename _Cp::const_iterator
1850end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001851{
1852 return __c.end();
1853}
1854
Eric Fiselier4e3e15a2016-09-25 03:34:28 +00001855#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856
Marshall Clow03c67912014-11-19 19:43:23 +00001857#if _LIBCPP_STD_VER > 14
Marshall Clow4bf7f4c2017-11-16 17:55:41 +00001858
1859// #if _LIBCPP_STD_VER > 11
1860// template <>
1861// struct _LIBCPP_TEMPLATE_VIS plus<void>
1862// {
1863// template <class _T1, class _T2>
1864// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1865// auto operator()(_T1&& __t, _T2&& __u) const
1866// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1867// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1868// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1869// typedef void is_transparent;
1870// };
1871// #endif
1872
Marshall Clow35e462d2015-02-11 16:14:01 +00001873template <class _Cont>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001874_LIBCPP_INLINE_VISIBILITY
Marshall Clow4bf7f4c2017-11-16 17:55:41 +00001875constexpr auto size(const _Cont& __c)
1876_NOEXCEPT_(noexcept(__c.size()))
1877-> decltype (__c.size())
1878{ return __c.size(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001879
Marshall Clow35e462d2015-02-11 16:14:01 +00001880template <class _Tp, size_t _Sz>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001881_LIBCPP_INLINE_VISIBILITY
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001882constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clow03c67912014-11-19 19:43:23 +00001883
Marshall Clowdd2ae122019-02-27 02:58:56 +00001884#if _LIBCPP_STD_VER > 17
1885template <class _Cont>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001886_LIBCPP_INLINE_VISIBILITY
Marshall Clowdd2ae122019-02-27 02:58:56 +00001887constexpr auto ssize(const _Cont& __c)
1888_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1889-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1890{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1891
1892template <class _Tp, ptrdiff_t _Sz>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001893_LIBCPP_INLINE_VISIBILITY
Marshall Clowdd2ae122019-02-27 02:58:56 +00001894constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1895#endif
1896
Marshall Clow35e462d2015-02-11 16:14:01 +00001897template <class _Cont>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001898_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow4bf7f4c2017-11-16 17:55:41 +00001899constexpr auto empty(const _Cont& __c)
1900_NOEXCEPT_(noexcept(__c.empty()))
1901-> decltype (__c.empty())
1902{ return __c.empty(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001903
Marshall Clow35e462d2015-02-11 16:14:01 +00001904template <class _Tp, size_t _Sz>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001905_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00001906constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clow03c67912014-11-19 19:43:23 +00001907
1908template <class _Ep>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001909_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow03c67912014-11-19 19:43:23 +00001910constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1911
Marshall Clow35e462d2015-02-11 16:14:01 +00001912template <class _Cont> constexpr
Marshall Clow4542e7b2019-02-27 03:25:43 +00001913_LIBCPP_INLINE_VISIBILITY
Marshall Clow4bf7f4c2017-11-16 17:55:41 +00001914auto data(_Cont& __c)
1915_NOEXCEPT_(noexcept(__c.data()))
1916-> decltype (__c.data())
1917{ return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001918
Marshall Clow35e462d2015-02-11 16:14:01 +00001919template <class _Cont> constexpr
Marshall Clow4542e7b2019-02-27 03:25:43 +00001920_LIBCPP_INLINE_VISIBILITY
Marshall Clow4bf7f4c2017-11-16 17:55:41 +00001921auto data(const _Cont& __c)
1922_NOEXCEPT_(noexcept(__c.data()))
Louis Dionnec30e2d92019-05-29 16:01:36 +00001923-> decltype (__c.data())
Marshall Clow4bf7f4c2017-11-16 17:55:41 +00001924{ return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:23 +00001925
Marshall Clow35e462d2015-02-11 16:14:01 +00001926template <class _Tp, size_t _Sz>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001927_LIBCPP_INLINE_VISIBILITY
Marshall Clow35e462d2015-02-11 16:14:01 +00001928constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clow03c67912014-11-19 19:43:23 +00001929
1930template <class _Ep>
Marshall Clow4542e7b2019-02-27 03:25:43 +00001931_LIBCPP_INLINE_VISIBILITY
Marshall Clow03c67912014-11-19 19:43:23 +00001932constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1933#endif
1934
1935
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001936_LIBCPP_END_NAMESPACE_STD
1937
1938#endif // _LIBCPP_ITERATOR