blob: 13329e1473d39ecd10a09da7e9b9c2d9556676b7 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ITERATOR
11#define _LIBCPP_ITERATOR
12
13/*
14 iterator synopsis
15
16namespace std
17{
18
19template<class Iterator>
20struct iterator_traits
21{
22 typedef typename Iterator::difference_type difference_type;
23 typedef typename Iterator::value_type value_type;
24 typedef typename Iterator::pointer pointer;
25 typedef typename Iterator::reference reference;
26 typedef typename Iterator::iterator_category iterator_category;
27};
28
29template<class T>
30struct iterator_traits<T*>
31{
32 typedef ptrdiff_t difference_type;
33 typedef T value_type;
34 typedef T* pointer;
35 typedef T& reference;
36 typedef random_access_iterator_tag iterator_category;
37};
38
Howard Hinnantc51e1022010-05-11 19:42:16 +000039template<class Category, class T, class Distance = ptrdiff_t,
40 class Pointer = T*, class Reference = T&>
41struct iterator
42{
43 typedef T value_type;
44 typedef Distance difference_type;
45 typedef Pointer pointer;
46 typedef Reference reference;
47 typedef Category iterator_category;
48};
49
50struct input_iterator_tag {};
51struct output_iterator_tag {};
52struct forward_iterator_tag : public input_iterator_tag {};
53struct bidirectional_iterator_tag : public forward_iterator_tag {};
54struct random_access_iterator_tag : public bidirectional_iterator_tag {};
55
Marshall Clow75468e72017-05-17 18:51:36 +000056// 27.4.3, iterator operations
Howard Hinnantc51e1022010-05-11 19:42:16 +000057// extension: second argument not conforming to C++03
Marshall Clow75468e72017-05-17 18:51:36 +000058template <class InputIterator> // constexpr in C++17
59 constexpr void advance(InputIterator& i,
Howard Hinnantc51e1022010-05-11 19:42:16 +000060 typename iterator_traits<InputIterator>::difference_type n);
61
Marshall Clow75468e72017-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 Dionne173f29e2019-05-29 16:01:36 +000072 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +000089
Marshall Clow5ace5542016-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 Hinnantc51e1022010-05-11 19:42:16 +0000106};
107
108template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000109constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
111
112template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000113constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
115
116template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000117constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000118operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
119
120template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000121constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000122operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
123
124template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000125constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
127
128template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000129constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000130operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
131
132template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000133constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000134operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000135-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136
137template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000138constexpr reverse_iterator<Iterator>
Louis Dionne173f29e2019-05-29 16:01:36 +0000139operator+(typename reverse_iterator<Iterator>::difference_type n,
Marshall Clow5ace5542016-10-19 15:12:50 +0000140 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000141
Marshall Clow5ace5542016-10-19 15:12:50 +0000142template <class Iterator>
143constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000144
Howard Hinnantc51e1022010-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 Fiselier9aeea872016-06-30 04:40:50 +0000154 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155 typedef void pointer;
156
157 explicit back_insert_iterator(Container& x);
Howard Hinnant60e95c62010-09-14 20:26:27 +0000158 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantc51e1022010-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 Fiselier9aeea872016-06-30 04:40:50 +0000175 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176 typedef void pointer;
177
178 explicit front_insert_iterator(Container& x);
Howard Hinnant60e95c62010-09-14 20:26:27 +0000179 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantc51e1022010-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 Fiselier9aeea872016-06-30 04:40:50 +0000197 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 typedef void pointer;
199
200 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant60e95c62010-09-14 20:26:27 +0000201 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantc51e1022010-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 Clowf8fec4e2016-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 Dionne173f29e2019-05-29 16:01:36 +0000219
Marshall Clowb5f99122016-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 Dionne173f29e2019-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 Clowb5f99122016-11-02 15:30:26 +0000237 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000238private:
239 Iterator current; // exposition only
240};
241
242template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000243constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000244operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
245
246template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000247constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000248operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
249
250template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000251constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000252operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
253
254template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000255constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000256operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
257
258template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000259constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000260operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
261
262template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000263constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000264operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
265
266template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000267constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-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 Clowb5f99122016-11-02 15:30:26 +0000272constexpr move_iterator<Iterator> operator+( // constexpr in C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000273 typename move_iterator<Iterator>::difference_type n,
Marshall Clowb5f99122016-11-02 15:30:26 +0000274 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000275
Marshall Clowb5f99122016-11-02 15:30:26 +0000276template <class Iterator> // constexpr in C++17
277constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000278
279
Howard Hinnantc51e1022010-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 Clow0735e4e2015-04-16 21:36:54 +0000289 constexpr istream_iterator();
Howard Hinnantc51e1022010-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 Hinnant011138d2012-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 Hinnantc51e1022010-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 Hinnant011138d2012-07-20 19:36:34 +0000370 ostreambuf_iterator(ostream_type& s) noexcept;
371 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-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 Hinnant011138d2012-07-20 19:36:34 +0000376 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377};
378
Marshall Clow99ba0022017-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 Hinnantc51e1022010-05-11 19:42:16 +0000385
Marshall Clow99ba0022017-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 Clowb278e9c2013-08-30 01:17:07 +0000398
Marshall Clowef357272014-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 Clow3c5363e2019-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 Clowef357272014-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 Hinnantc51e1022010-05-11 19:42:16 +0000415} // std
416
417*/
418
419#include <__config>
Eric Fiselier876c6862016-02-20 00:19:45 +0000420#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow3dc05502014-02-27 02:11:50 +0000421#include <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422#include <type_traits>
423#include <cstddef>
Marshall Clowb278e9c2013-08-30 01:17:07 +0000424#include <initializer_list>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000425#include <version>
Marshall Clowdde4bfe2013-03-18 17:45:34 +0000426#ifdef __APPLE__
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000427#include <Availability.h>
428#endif
429
Eric Fiselier14b6de92014-08-10 23:53:08 +0000430#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000432#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000434#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000435
436_LIBCPP_BEGIN_NAMESPACE_STD
Eric Fiselier7b2a34f2019-11-16 20:24:39 -0500437template <class _Iter>
438struct _LIBCPP_TEMPLATE_VIS iterator_traits;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000440struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
441struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
442struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
443struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
444struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
Eric Fiselier30005a92019-11-16 20:12:48 -0500445#if _LIBCPP_STD_VER > 17
446// TODO(EricWF) contiguous_iterator_tag is provided as an extension prior to
447// C++20 to allow optimizations for users providing wrapped iterator types.
448struct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag: public random_access_iterator_tag { };
449#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450
Eric Fiselier7b2a34f2019-11-16 20:24:39 -0500451template <class _Iter>
452struct __iter_traits_cache {
453 using type = _If<
454 __is_primary_template<iterator_traits<_Iter> >::value,
455 _Iter,
456 iterator_traits<_Iter>
457 >;
458};
459template <class _Iter>
460using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type;
461
462struct __iter_concept_concept_test {
463 template <class _Iter>
464 using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept;
465};
466struct __iter_concept_category_test {
467 template <class _Iter>
468 using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category;
469};
470struct __iter_concept_random_fallback {
471 template <class _Iter>
472 using _Apply = _EnableIf<
473 __is_primary_template<iterator_traits<_Iter> >::value,
474 random_access_iterator_tag
475 >;
476};
477
478template <class _Iter, class _Tester> struct __test_iter_concept
479 : _IsValidExpansion<_Tester::template _Apply, _Iter>,
480 _Tester
481{
482};
483
484template <class _Iter>
485struct __iter_concept_cache {
486 using type = _Or<
487 __test_iter_concept<_Iter, __iter_concept_concept_test>,
488 __test_iter_concept<_Iter, __iter_concept_category_test>,
489 __test_iter_concept<_Iter, __iter_concept_random_fallback>
490 >;
491};
492
493template <class _Iter>
494using _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
495
496
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497template <class _Tp>
Marshall Clow50abbe42018-11-13 05:33:31 +0000498struct __has_iterator_typedefs
499{
500private:
501 struct __two {char __lx; char __lxx;};
502 template <class _Up> static __two __test(...);
503 template <class _Up> static char __test(typename std::__void_t<typename _Up::iterator_category>::type* = 0,
504 typename std::__void_t<typename _Up::difference_type>::type* = 0,
505 typename std::__void_t<typename _Up::value_type>::type* = 0,
506 typename std::__void_t<typename _Up::reference>::type* = 0,
507 typename std::__void_t<typename _Up::pointer>::type* = 0
508 );
509public:
510 static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1;
511};
512
513
514template <class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515struct __has_iterator_category
516{
517private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000518 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519 template <class _Up> static __two __test(...);
520 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
521public:
522 static const bool value = sizeof(__test<_Tp>(0)) == 1;
523};
524
Marshall Clow75533b02014-01-03 22:55:49 +0000525template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526
527template <class _Iter>
Marshall Clow75533b02014-01-03 22:55:49 +0000528struct __iterator_traits_impl<_Iter, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529{
530 typedef typename _Iter::difference_type difference_type;
531 typedef typename _Iter::value_type value_type;
532 typedef typename _Iter::pointer pointer;
533 typedef typename _Iter::reference reference;
534 typedef typename _Iter::iterator_category iterator_category;
535};
536
537template <class _Iter, bool> struct __iterator_traits {};
538
539template <class _Iter>
540struct __iterator_traits<_Iter, true>
Marshall Clow75533b02014-01-03 22:55:49 +0000541 : __iterator_traits_impl
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542 <
543 _Iter,
544 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
545 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
546 >
547{};
548
549// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
550// exists. Else iterator_traits<Iterator> will be an empty class. This is a
551// conforming extension which allows some programs to compile and behave as
552// the client expects instead of failing at compile time.
553
554template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000555struct _LIBCPP_TEMPLATE_VIS iterator_traits
Eric Fiselier7b2a34f2019-11-16 20:24:39 -0500556 : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {
557
558 using __primary_template = iterator_traits;
559};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560
561template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000562struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563{
564 typedef ptrdiff_t difference_type;
Marshall Clow56d53522017-11-14 00:03:10 +0000565 typedef typename remove_cv<_Tp>::type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566 typedef _Tp* pointer;
567 typedef _Tp& reference;
568 typedef random_access_iterator_tag iterator_category;
Eric Fiselier30005a92019-11-16 20:12:48 -0500569#if _LIBCPP_STD_VER > 17
570 typedef contiguous_iterator_tag iterator_concept;
571#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572};
573
574template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
575struct __has_iterator_category_convertible_to
576 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
577{};
578
579template <class _Tp, class _Up>
580struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
581
582template <class _Tp>
583struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
584
585template <class _Tp>
586struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
587
588template <class _Tp>
589struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
590
591template <class _Tp>
592struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
593
Eric Fiselier30005a92019-11-16 20:12:48 -0500594#if _LIBCPP_STD_VER > 17
595template <class _Tp>
596struct __is_contiguous_iterator : public __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag> {};
597#endif
598
Marshall Clow039b2f02016-01-13 21:54:34 +0000599template <class _Tp>
600struct __is_exactly_input_iterator
Louis Dionne173f29e2019-05-29 16:01:36 +0000601 : public integral_constant<bool,
602 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
Marshall Clowb5f99122016-11-02 15:30:26 +0000603 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
Marshall Clow039b2f02016-01-13 21:54:34 +0000604
Louis Dionned23a5f22019-06-20 19:32:00 +0000605#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
606template<class _InputIterator>
607using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
608
609template<class _InputIterator>
610using __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
611
612template<class _InputIterator>
613using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
614
615template<class _InputIterator>
616using __iter_to_alloc_type = pair<
617 add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
618 typename iterator_traits<_InputIterator>::value_type::second_type>;
619#endif
620
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621template<class _Category, class _Tp, class _Distance = ptrdiff_t,
622 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000623struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624{
625 typedef _Tp value_type;
626 typedef _Distance difference_type;
627 typedef _Pointer pointer;
628 typedef _Reference reference;
629 typedef _Category iterator_category;
630};
631
632template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000633inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634void __advance(_InputIter& __i,
635 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
636{
637 for (; __n > 0; --__n)
638 ++__i;
639}
640
641template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000642inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643void __advance(_BiDirIter& __i,
644 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
645{
646 if (__n >= 0)
647 for (; __n > 0; --__n)
648 ++__i;
649 else
650 for (; __n < 0; ++__n)
651 --__i;
652}
653
654template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000655inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656void __advance(_RandIter& __i,
657 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
658{
659 __i += __n;
660}
661
662template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000663inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664void advance(_InputIter& __i,
665 typename iterator_traits<_InputIter>::difference_type __n)
666{
Marshall Clow3d435212019-03-22 22:32:20 +0000667 _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value,
668 "Attempt to advance(it, -n) on a non-bidi iterator");
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
670}
671
672template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000673inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674typename iterator_traits<_InputIter>::difference_type
675__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
676{
677 typename iterator_traits<_InputIter>::difference_type __r(0);
678 for (; __first != __last; ++__first)
679 ++__r;
680 return __r;
681}
682
683template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000684inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685typename iterator_traits<_RandIter>::difference_type
686__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
687{
688 return __last - __first;
689}
690
691template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000692inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693typename iterator_traits<_InputIter>::difference_type
694distance(_InputIter __first, _InputIter __last)
695{
696 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
697}
698
Marshall Clow990c70d2015-11-07 17:48:49 +0000699template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000700inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000701typename enable_if
702<
Louis Dionne173f29e2019-05-29 16:01:36 +0000703 __is_input_iterator<_InputIter>::value,
Rachel Craik2048d822017-07-24 22:17:05 +0000704 _InputIter
705>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000706next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000707 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000708{
Marshall Clow3d435212019-03-22 22:32:20 +0000709 _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value,
710 "Attempt to next(it, -n) on a non-bidi iterator");
711
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000712 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 return __x;
714}
715
Marshall Clow3d435212019-03-22 22:32:20 +0000716template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000717inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000718typename enable_if
719<
Louis Dionne173f29e2019-05-29 16:01:36 +0000720 __is_input_iterator<_InputIter>::value,
Marshall Clow3d435212019-03-22 22:32:20 +0000721 _InputIter
Rachel Craik2048d822017-07-24 22:17:05 +0000722>::type
Marshall Clow3d435212019-03-22 22:32:20 +0000723prev(_InputIter __x,
724 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725{
Marshall Clow3d435212019-03-22 22:32:20 +0000726 _LIBCPP_ASSERT(__n <= 0 || __is_bidirectional_iterator<_InputIter>::value,
727 "Attempt to prev(it, +n) on a non-bidi iterator");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000728 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729 return __x;
730}
731
Eric Fiselier883af112017-04-13 02:54:13 +0000732
733template <class _Tp, class = void>
734struct __is_stashing_iterator : false_type {};
735
736template <class _Tp>
737struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
738 : true_type {};
739
Howard Hinnantc51e1022010-05-11 19:42:16 +0000740template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000741class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742 : public iterator<typename iterator_traits<_Iter>::iterator_category,
743 typename iterator_traits<_Iter>::value_type,
744 typename iterator_traits<_Iter>::difference_type,
745 typename iterator_traits<_Iter>::pointer,
746 typename iterator_traits<_Iter>::reference>
747{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000748private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000749 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000750
751 static_assert(!__is_stashing_iterator<_Iter>::value,
752 "The specified iterator type cannot be used with reverse_iterator; "
753 "Using stashing iterators with reverse_iterator causes undefined behavior");
754
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000755protected:
756 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757public:
758 typedef _Iter iterator_type;
759 typedef typename iterator_traits<_Iter>::difference_type difference_type;
760 typedef typename iterator_traits<_Iter>::reference reference;
761 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000762
Marshall Clow5ace5542016-10-19 15:12:50 +0000763 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
764 reverse_iterator() : __t(), current() {}
765 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
766 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
767 template <class _Up>
768 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
769 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
770 template <class _Up>
771 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
772 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
773 { __t = current = __u.base(); return *this; }
774 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
775 _Iter base() const {return current;}
776 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
777 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
778 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
779 pointer operator->() const {return _VSTD::addressof(operator*());}
780 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
781 reverse_iterator& operator++() {--current; return *this;}
782 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
783 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
784 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
785 reverse_iterator& operator--() {++current; return *this;}
786 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
787 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
788 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
789 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
790 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
791 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
792 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
793 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
794 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
795 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
796 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
797 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798};
799
800template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000801inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802bool
803operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
804{
805 return __x.base() == __y.base();
806}
807
808template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000809inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810bool
811operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
812{
813 return __x.base() > __y.base();
814}
815
816template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000817inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818bool
819operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
820{
821 return __x.base() != __y.base();
822}
823
824template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000825inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826bool
827operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
828{
829 return __x.base() < __y.base();
830}
831
832template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000833inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834bool
835operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
836{
837 return __x.base() <= __y.base();
838}
839
840template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000841inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842bool
843operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
844{
845 return __x.base() >= __y.base();
846}
847
Marshall Clow476d3f42016-07-18 13:19:00 +0000848#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000849template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000850inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000851auto
852operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
853-> decltype(__y.base() - __x.base())
854{
855 return __y.base() - __x.base();
856}
857#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858template <class _Iter1, class _Iter2>
859inline _LIBCPP_INLINE_VISIBILITY
860typename reverse_iterator<_Iter1>::difference_type
861operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
862{
863 return __y.base() - __x.base();
864}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000865#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866
867template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000868inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869reverse_iterator<_Iter>
870operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
871{
872 return reverse_iterator<_Iter>(__x.base() - __n);
873}
874
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000875#if _LIBCPP_STD_VER > 11
876template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000877inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000878reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
879{
880 return reverse_iterator<_Iter>(__i);
881}
882#endif
883
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000885class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 : public iterator<output_iterator_tag,
887 void,
888 void,
889 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000890 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891{
892protected:
893 _Container* container;
894public:
895 typedef _Container container_type;
896
Marshall Clowcef31682014-03-03 19:20:40 +0000897 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000898 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
899 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000900#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf074022011-10-22 20:59:45 +0000901 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
902 {container->push_back(_VSTD::move(__value_)); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000903#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
905 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
906 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
907};
908
909template <class _Container>
910inline _LIBCPP_INLINE_VISIBILITY
911back_insert_iterator<_Container>
912back_inserter(_Container& __x)
913{
914 return back_insert_iterator<_Container>(__x);
915}
916
917template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000918class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919 : public iterator<output_iterator_tag,
920 void,
921 void,
922 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000923 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924{
925protected:
926 _Container* container;
927public:
928 typedef _Container container_type;
929
Marshall Clowcef31682014-03-03 19:20:40 +0000930 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000931 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
932 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000933#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf074022011-10-22 20:59:45 +0000934 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
935 {container->push_front(_VSTD::move(__value_)); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000936#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
938 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
939 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
940};
941
942template <class _Container>
943inline _LIBCPP_INLINE_VISIBILITY
944front_insert_iterator<_Container>
945front_inserter(_Container& __x)
946{
947 return front_insert_iterator<_Container>(__x);
948}
949
950template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000951class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952 : public iterator<output_iterator_tag,
953 void,
954 void,
955 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000956 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000957{
958protected:
959 _Container* container;
960 typename _Container::iterator iter;
961public:
962 typedef _Container container_type;
963
964 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000965 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000966 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
967 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000968#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf074022011-10-22 20:59:45 +0000969 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
970 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000971#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
973 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
974 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
975};
976
977template <class _Container>
978inline _LIBCPP_INLINE_VISIBILITY
979insert_iterator<_Container>
980inserter(_Container& __x, typename _Container::iterator __i)
981{
982 return insert_iterator<_Container>(__x, __i);
983}
984
985template <class _Tp, class _CharT = char,
986 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000987class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
989{
990public:
991 typedef _CharT char_type;
992 typedef _Traits traits_type;
993 typedef basic_istream<_CharT,_Traits> istream_type;
994private:
995 istream_type* __in_stream_;
996 _Tp __value_;
997public:
Marshall Clow0735e4e2015-04-16 21:36:54 +0000998 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000999 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000 {
1001 if (!(*__in_stream_ >> __value_))
1002 __in_stream_ = 0;
1003 }
1004
1005 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +00001006 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
1008 {
1009 if (!(*__in_stream_ >> __value_))
1010 __in_stream_ = 0;
1011 return *this;
1012 }
1013 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
1014 {istream_iterator __t(*this); ++(*this); return __t;}
1015
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001016 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001018 bool
1019 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
1020 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001021
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001022 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001024 bool
1025 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
1026 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027};
1028
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +00001029template <class _Tp, class _CharT, class _Traits, class _Distance>
1030inline _LIBCPP_INLINE_VISIBILITY
1031bool
1032operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
1033 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
1034{
1035 return __x.__in_stream_ == __y.__in_stream_;
1036}
1037
1038template <class _Tp, class _CharT, class _Traits, class _Distance>
1039inline _LIBCPP_INLINE_VISIBILITY
1040bool
1041operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
1042 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
1043{
1044 return !(__x == __y);
1045}
1046
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001048class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049 : public iterator<output_iterator_tag, void, void, void, void>
1050{
1051public:
1052 typedef _CharT char_type;
1053 typedef _Traits traits_type;
1054 typedef basic_ostream<_CharT,_Traits> ostream_type;
1055private:
1056 ostream_type* __out_stream_;
1057 const char_type* __delim_;
1058public:
Marshall Clow27a89512016-10-12 16:13:48 +00001059 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +00001060 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
Marshall Clow27a89512016-10-12 16:13:48 +00001061 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +00001062 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +00001063 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064 {
Howard Hinnantbf074022011-10-22 20:59:45 +00001065 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 if (__delim_)
1067 *__out_stream_ << __delim_;
1068 return *this;
1069 }
1070
1071 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
1072 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
1073 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
1074};
1075
1076template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001077class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078 : public iterator<input_iterator_tag, _CharT,
1079 typename _Traits::off_type, _CharT*,
1080 _CharT>
1081{
1082public:
1083 typedef _CharT char_type;
1084 typedef _Traits traits_type;
1085 typedef typename _Traits::int_type int_type;
1086 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1087 typedef basic_istream<_CharT,_Traits> istream_type;
1088private:
Howard Hinnant3e57b272012-11-16 22:17:23 +00001089 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090
1091 class __proxy
1092 {
1093 char_type __keep_;
1094 streambuf_type* __sbuf_;
1095 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
1096 : __keep_(__c), __sbuf_(__s) {}
1097 friend class istreambuf_iterator;
1098 public:
1099 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
1100 };
1101
Howard Hinnant756c69b2010-09-22 16:48:34 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +00001103 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104 {
1105 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
1106 __sbuf_ = 0;
Howard Hinnant3e57b272012-11-16 22:17:23 +00001107 return __sbuf_ == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108 }
1109public:
Howard Hinnant3e57b272012-11-16 22:17:23 +00001110 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001111 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001112 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001113 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001114 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001115 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 : __sbuf_(__p.__sbuf_) {}
1117
Howard Hinnant28b24882011-12-01 20:21:04 +00001118 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1119 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1121 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001122 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123 return *this;
1124 }
1125 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1126 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001127 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128 }
1129
1130 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001131 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132};
1133
1134template <class _CharT, class _Traits>
1135inline _LIBCPP_INLINE_VISIBILITY
1136bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1137 const istreambuf_iterator<_CharT,_Traits>& __b)
1138 {return __a.equal(__b);}
1139
1140template <class _CharT, class _Traits>
1141inline _LIBCPP_INLINE_VISIBILITY
1142bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1143 const istreambuf_iterator<_CharT,_Traits>& __b)
1144 {return !__a.equal(__b);}
1145
1146template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001147class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001148 : public iterator<output_iterator_tag, void, void, void, void>
1149{
1150public:
1151 typedef _CharT char_type;
1152 typedef _Traits traits_type;
1153 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1154 typedef basic_ostream<_CharT,_Traits> ostream_type;
1155private:
1156 streambuf_type* __sbuf_;
1157public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001158 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001160 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001161 : __sbuf_(__s) {}
1162 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1163 {
1164 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1165 __sbuf_ = 0;
1166 return *this;
1167 }
1168 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1169 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1170 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnant011138d2012-07-20 19:36:34 +00001171 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnant97955172012-09-19 19:14:15 +00001172
1173 template <class _Ch, class _Tr>
1174 friend
1175 _LIBCPP_HIDDEN
1176 ostreambuf_iterator<_Ch, _Tr>
1177 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1178 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1179 ios_base& __iob, _Ch __fl);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180};
1181
1182template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001183class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001184{
1185private:
1186 _Iter __i;
1187public:
1188 typedef _Iter iterator_type;
1189 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1190 typedef typename iterator_traits<iterator_type>::value_type value_type;
1191 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001192 typedef iterator_type pointer;
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001193#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001194 typedef typename iterator_traits<iterator_type>::reference __reference;
1195 typedef typename conditional<
1196 is_reference<__reference>::value,
1197 typename remove_reference<__reference>::type&&,
1198 __reference
1199 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200#else
1201 typedef typename iterator_traits<iterator_type>::reference reference;
1202#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001203
Marshall Clowb5f99122016-11-02 15:30:26 +00001204 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1205 move_iterator() : __i() {}
1206 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1207 explicit move_iterator(_Iter __x) : __i(__x) {}
1208 template <class _Up>
1209 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1210 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1211 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
Louis Dionne173f29e2019-05-29 16:01:36 +00001212 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb5f99122016-11-02 15:30:26 +00001213 reference operator*() const { return static_cast<reference>(*__i); }
1214 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1215 pointer operator->() const { return __i;}
1216 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1217 move_iterator& operator++() {++__i; return *this;}
1218 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1219 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1220 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1221 move_iterator& operator--() {--__i; return *this;}
1222 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1223 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1225 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1226 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1227 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1228 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1229 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1230 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1231 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1232 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1233 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234};
1235
1236template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001237inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238bool
1239operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1240{
1241 return __x.base() == __y.base();
1242}
1243
1244template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001245inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001246bool
1247operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1248{
1249 return __x.base() < __y.base();
1250}
1251
1252template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001253inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254bool
1255operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1256{
1257 return __x.base() != __y.base();
1258}
1259
1260template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001261inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262bool
1263operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1264{
1265 return __x.base() > __y.base();
1266}
1267
1268template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001269inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270bool
1271operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1272{
1273 return __x.base() >= __y.base();
1274}
1275
1276template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001277inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278bool
1279operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1280{
1281 return __x.base() <= __y.base();
1282}
1283
Marshall Clow476d3f42016-07-18 13:19:00 +00001284#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001285template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001286inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001287auto
1288operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1289-> decltype(__x.base() - __y.base())
1290{
1291 return __x.base() - __y.base();
1292}
1293#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294template <class _Iter1, class _Iter2>
1295inline _LIBCPP_INLINE_VISIBILITY
1296typename move_iterator<_Iter1>::difference_type
1297operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1298{
1299 return __x.base() - __y.base();
1300}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001301#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001302
1303template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001304inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305move_iterator<_Iter>
1306operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1307{
1308 return move_iterator<_Iter>(__x.base() + __n);
1309}
1310
1311template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001312inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001314make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315{
1316 return move_iterator<_Iter>(__i);
1317}
1318
1319// __wrap_iter
1320
1321template <class _Iter> class __wrap_iter;
1322
1323template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001324_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001326operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001327
1328template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001329_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001330bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001331operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001332
1333template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001334_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001335bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001336operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001337
1338template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001339_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001341operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001342
1343template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001344_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001345bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001346operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001347
1348template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001349_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001351operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352
Marshall Clow476d3f42016-07-18 13:19:00 +00001353#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001354template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001355_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001356auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001357operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001358-> decltype(__x.base() - __y.base());
1359#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001361_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001362typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001363operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001364#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001365
1366template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001367_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368__wrap_iter<_Iter>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001369operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370
Louis Dionne65b433b2019-11-06 12:02:41 +00001371template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
1372template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
Howard Hinnanta54386e2012-09-14 00:39:16 +00001373template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1374template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375
Eric Fiselier38badb82016-12-28 05:35:32 +00001376#if _LIBCPP_DEBUG_LEVEL < 2
1377
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378template <class _Tp>
Marshall Clowae4f8312018-07-13 16:35:26 +00001379_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380typename enable_if
1381<
Howard Hinnanta9a897e2010-11-19 22:17:28 +00001382 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001383 _Tp*
1384>::type
1385__unwrap_iter(__wrap_iter<_Tp*>);
1386
Eric Fiselier38badb82016-12-28 05:35:32 +00001387#else
1388
1389template <class _Tp>
Marshall Clowae4f8312018-07-13 16:35:26 +00001390inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Eric Fiselier38badb82016-12-28 05:35:32 +00001391typename enable_if
1392<
1393 is_trivially_copy_assignable<_Tp>::value,
1394 __wrap_iter<_Tp*>
1395>::type
1396__unwrap_iter(__wrap_iter<_Tp*> __i);
1397
1398#endif
1399
Howard Hinnantc51e1022010-05-11 19:42:16 +00001400template <class _Iter>
1401class __wrap_iter
1402{
1403public:
1404 typedef _Iter iterator_type;
1405 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1406 typedef typename iterator_traits<iterator_type>::value_type value_type;
1407 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1408 typedef typename iterator_traits<iterator_type>::pointer pointer;
1409 typedef typename iterator_traits<iterator_type>::reference reference;
1410private:
1411 iterator_type __i;
1412public:
Eric Fiselier873b8d32019-03-18 21:50:12 +00001413 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001414#if _LIBCPP_STD_VER > 11
1415 : __i{}
1416#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001417 {
1418#if _LIBCPP_DEBUG_LEVEL >= 2
1419 __get_db()->__insert_i(this);
1420#endif
1421 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001422 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1423 __wrap_iter(const __wrap_iter<_Up>& __u,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001424 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
Marshall Clowae4f8312018-07-13 16:35:26 +00001425 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001426 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001427#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001428 __get_db()->__iterator_copy(this, &__u);
1429#endif
1430 }
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001431#if _LIBCPP_DEBUG_LEVEL >= 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001432 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001433 __wrap_iter(const __wrap_iter& __x)
1434 : __i(__x.base())
1435 {
1436 __get_db()->__iterator_copy(this, &__x);
1437 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001438 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001439 __wrap_iter& operator=(const __wrap_iter& __x)
1440 {
1441 if (this != &__x)
1442 {
1443 __get_db()->__iterator_copy(this, &__x);
1444 __i = __x.__i;
1445 }
1446 return *this;
1447 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001448 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001449 ~__wrap_iter()
1450 {
1451 __get_db()->__erase_i(this);
1452 }
1453#endif
Eric Fiselier873b8d32019-03-18 21:50:12 +00001454 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001455 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001456#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001457 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1458 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001459#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001460 return *__i;
1461 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001462 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
Howard Hinnant76053d72013-06-27 19:35:32 +00001463 {
1464#if _LIBCPP_DEBUG_LEVEL >= 2
1465 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1466 "Attempted to dereference a non-dereferenceable iterator");
1467#endif
Marshall Clowd85a0562016-04-11 03:54:53 +00001468 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001469 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001470 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001471 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001472#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001473 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1474 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001475#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001476 ++__i;
1477 return *this;
1478 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001479 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001480 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001481
Eric Fiselier873b8d32019-03-18 21:50:12 +00001482 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001483 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001484#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001485 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1486 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001487#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001488 --__i;
1489 return *this;
1490 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001491 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001492 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001493 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001494 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001495 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001496 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001497#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001498 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1499 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001500#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001501 __i += __n;
1502 return *this;
1503 }
Eric Fiselier873b8d32019-03-18 21:50:12 +00001504 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001505 {return *this + (-__n);}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001506 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001507 {*this += -__n; return *this;}
Eric Fiselier873b8d32019-03-18 21:50:12 +00001508 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
Howard Hinnant27e0e772011-09-14 18:33:51 +00001509 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001510#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001511 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1512 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001513#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001514 return __i[__n];
1515 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516
Eric Fiselier873b8d32019-03-18 21:50:12 +00001517 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518
1519private:
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001520#if _LIBCPP_DEBUG_LEVEL >= 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001521 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001522 {
1523 __get_db()->__insert_ic(this, __p);
1524 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001525#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001526 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001527#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528
1529 template <class _Up> friend class __wrap_iter;
1530 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001531 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowcd6d8802019-02-27 00:32:16 +00001532 template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001533
1534 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001535 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001536 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001537 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001538
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001540 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001541 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001542 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001543
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001545 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001547 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001548
Howard Hinnantc51e1022010-05-11 19:42:16 +00001549 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001550 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001552 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001553
Howard Hinnantc51e1022010-05-11 19:42:16 +00001554 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001555 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001556 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001557 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001558
Howard Hinnantc51e1022010-05-11 19:42:16 +00001559 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001560 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561 bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001562 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001563
Marshall Clow476d3f42016-07-18 13:19:00 +00001564#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001565 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001566 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001567 auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001568 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001569 -> decltype(__x.base() - __y.base());
1570#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001572 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001574 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001575#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001576
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001578 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001579 __wrap_iter<_Iter1>
Eric Fiselier873b8d32019-03-18 21:50:12 +00001580 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581
Louis Dionne65b433b2019-11-06 12:02:41 +00001582 template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op);
1583 template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnantc834c512011-11-29 18:15:50 +00001584 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001585 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1586
Eric Fiselier38badb82016-12-28 05:35:32 +00001587#if _LIBCPP_DEBUG_LEVEL < 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001588 template <class _Tp>
Marshall Clowae4f8312018-07-13 16:35:26 +00001589 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590 typename enable_if
1591 <
Howard Hinnanta9a897e2010-11-19 22:17:28 +00001592 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001593 _Tp*
1594 >::type
1595 __unwrap_iter(__wrap_iter<_Tp*>);
Eric Fiselier38badb82016-12-28 05:35:32 +00001596#else
1597 template <class _Tp>
Marshall Clowae4f8312018-07-13 16:35:26 +00001598 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Eric Fiselier38badb82016-12-28 05:35:32 +00001599 typename enable_if
1600 <
1601 is_trivially_copy_assignable<_Tp>::value,
1602 __wrap_iter<_Tp*>
1603 >::type
1604 __unwrap_iter(__wrap_iter<_Tp*> __i);
1605#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001606};
1607
1608template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001609inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001610bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001611operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001612{
1613 return __x.base() == __y.base();
1614}
1615
1616template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001617inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001619operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620{
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001621#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001622 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001623 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001624#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625 return __x.base() < __y.base();
1626}
1627
1628template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001629inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001630bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001631operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001632{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001633 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001634}
1635
1636template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001637inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001638bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001639operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001641 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642}
1643
1644template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001645inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001646bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001647operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001648{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001649 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001650}
1651
1652template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001653inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001654bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001655operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001656{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001657 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658}
1659
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001660template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001661inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001662bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001663operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001664{
1665 return !(__x == __y);
1666}
1667
1668template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001669inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001670bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001671operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001672{
1673 return __y < __x;
1674}
1675
1676template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001677inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001678bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001679operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001680{
1681 return !(__x < __y);
1682}
1683
1684template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001685inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001686bool
Eric Fiselier873b8d32019-03-18 21:50:12 +00001687operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001688{
1689 return !(__y < __x);
1690}
1691
Marshall Clow476d3f42016-07-18 13:19:00 +00001692#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001693template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001694inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001695auto
Eric Fiselier873b8d32019-03-18 21:50:12 +00001696operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001697-> decltype(__x.base() - __y.base())
1698{
1699#if _LIBCPP_DEBUG_LEVEL >= 2
1700 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1701 "Attempted to subtract incompatible iterators");
1702#endif
1703 return __x.base() - __y.base();
1704}
1705#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001706template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001707inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001708typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier873b8d32019-03-18 21:50:12 +00001709operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001710{
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001711#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001712 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001713 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001714#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001715 return __x.base() - __y.base();
1716}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001717#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001718
1719template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001720inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001721__wrap_iter<_Iter>
1722operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier873b8d32019-03-18 21:50:12 +00001723 __wrap_iter<_Iter> __x) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001724{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001725 __x += __n;
1726 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001727}
1728
Marshall Clow039b2f02016-01-13 21:54:34 +00001729template <class _Iter>
1730struct __libcpp_is_trivial_iterator
Marshall Clowb5f99122016-11-02 15:30:26 +00001731 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
Louis Dionne173f29e2019-05-29 16:01:36 +00001732
Marshall Clow039b2f02016-01-13 21:54:34 +00001733template <class _Iter>
1734struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001735 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001736
1737template <class _Iter>
1738struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001739 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001740
1741template <class _Iter>
1742struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001743 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001744
1745
Marshall Clow8411ebf2013-12-02 03:24:33 +00001746template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001747_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001748_Tp*
1749begin(_Tp (&__array)[_Np])
1750{
1751 return __array;
1752}
1753
1754template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001755_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001756_Tp*
1757end(_Tp (&__array)[_Np])
1758{
1759 return __array + _Np;
1760}
1761
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001762#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001763
Howard Hinnantc834c512011-11-29 18:15:50 +00001764template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001765_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001766auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001767begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001768{
1769 return __c.begin();
1770}
1771
Howard Hinnantc834c512011-11-29 18:15:50 +00001772template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001773_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001774auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001775begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776{
1777 return __c.begin();
1778}
1779
Howard Hinnantc834c512011-11-29 18:15:50 +00001780template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001781_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001782auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001783end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001784{
1785 return __c.end();
1786}
1787
Howard Hinnantc834c512011-11-29 18:15:50 +00001788template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001789_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001790auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001791end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001792{
1793 return __c.end();
1794}
1795
Marshall Clowb278e9c2013-08-30 01:17:07 +00001796#if _LIBCPP_STD_VER > 11
1797
Marshall Clow8411ebf2013-12-02 03:24:33 +00001798template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001799_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001800reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1801{
1802 return reverse_iterator<_Tp*>(__array + _Np);
1803}
1804
1805template <class _Tp, size_t _Np>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001806_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001807reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1808{
1809 return reverse_iterator<_Tp*>(__array);
1810}
1811
1812template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001813_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001814reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1815{
1816 return reverse_iterator<const _Ep*>(__il.end());
1817}
1818
1819template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001820_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001821reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1822{
1823 return reverse_iterator<const _Ep*>(__il.begin());
1824}
1825
Marshall Clowb278e9c2013-08-30 01:17:07 +00001826template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001827_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001828auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001829{
Marshall Clow3862f532016-08-10 20:04:46 +00001830 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001831}
1832
1833template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001834_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001835auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001836{
Marshall Clow3862f532016-08-10 20:04:46 +00001837 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001838}
1839
1840template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001841_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001842auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1843{
1844 return __c.rbegin();
1845}
1846
1847template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001848_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001849auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1850{
1851 return __c.rbegin();
1852}
1853
1854template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001855_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001856auto rend(_Cp& __c) -> decltype(__c.rend())
1857{
1858 return __c.rend();
1859}
1860
1861template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001862_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001863auto rend(const _Cp& __c) -> decltype(__c.rend())
1864{
1865 return __c.rend();
1866}
1867
1868template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001869_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001870auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001871{
Marshall Clow3862f532016-08-10 20:04:46 +00001872 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001873}
1874
1875template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001876_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001877auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001878{
Marshall Clow3862f532016-08-10 20:04:46 +00001879 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001880}
1881
1882#endif
1883
1884
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001885#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886
Howard Hinnantc834c512011-11-29 18:15:50 +00001887template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001888_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001889typename _Cp::iterator
1890begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891{
1892 return __c.begin();
1893}
1894
Howard Hinnantc834c512011-11-29 18:15:50 +00001895template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001896_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001897typename _Cp::const_iterator
1898begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001899{
1900 return __c.begin();
1901}
1902
Howard Hinnantc834c512011-11-29 18:15:50 +00001903template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001904_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001905typename _Cp::iterator
1906end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001907{
1908 return __c.end();
1909}
1910
Howard Hinnantc834c512011-11-29 18:15:50 +00001911template <class _Cp>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001912_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001913typename _Cp::const_iterator
1914end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001915{
1916 return __c.end();
1917}
1918
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001919#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001920
Marshall Clowef357272014-11-19 19:43:23 +00001921#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001922
1923// #if _LIBCPP_STD_VER > 11
1924// template <>
1925// struct _LIBCPP_TEMPLATE_VIS plus<void>
1926// {
1927// template <class _T1, class _T2>
1928// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1929// auto operator()(_T1&& __t, _T2&& __u) const
1930// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1931// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1932// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1933// typedef void is_transparent;
1934// };
1935// #endif
1936
Marshall Clowc4b4a342015-02-11 16:14:01 +00001937template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001938_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001939constexpr auto size(const _Cont& __c)
1940_NOEXCEPT_(noexcept(__c.size()))
1941-> decltype (__c.size())
1942{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001943
Marshall Clowc4b4a342015-02-11 16:14:01 +00001944template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001945_LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001946constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001947
Marshall Clow3c5363e2019-02-27 02:58:56 +00001948#if _LIBCPP_STD_VER > 17
1949template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001950_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001951constexpr auto ssize(const _Cont& __c)
1952_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
1953-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
1954{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
1955
1956template <class _Tp, ptrdiff_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001957_LIBCPP_INLINE_VISIBILITY
Marshall Clow3c5363e2019-02-27 02:58:56 +00001958constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1959#endif
1960
Marshall Clowc4b4a342015-02-11 16:14:01 +00001961template <class _Cont>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001962_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001963constexpr auto empty(const _Cont& __c)
1964_NOEXCEPT_(noexcept(__c.empty()))
1965-> decltype (__c.empty())
1966{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001967
Marshall Clowc4b4a342015-02-11 16:14:01 +00001968template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001969_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001970constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001971
1972template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001973_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001974constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1975
Marshall Clowc4b4a342015-02-11 16:14:01 +00001976template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001977_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001978auto data(_Cont& __c)
1979_NOEXCEPT_(noexcept(__c.data()))
1980-> decltype (__c.data())
1981{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001982
Marshall Clowc4b4a342015-02-11 16:14:01 +00001983template <class _Cont> constexpr
Marshall Clow0bd662d2019-02-27 03:25:43 +00001984_LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001985auto data(const _Cont& __c)
1986_NOEXCEPT_(noexcept(__c.data()))
Louis Dionne173f29e2019-05-29 16:01:36 +00001987-> decltype (__c.data())
Marshall Clow344c41d2017-11-16 17:55:41 +00001988{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001989
Marshall Clowc4b4a342015-02-11 16:14:01 +00001990template <class _Tp, size_t _Sz>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001991_LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001992constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001993
1994template <class _Ep>
Marshall Clow0bd662d2019-02-27 03:25:43 +00001995_LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001996constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1997#endif
1998
1999
Howard Hinnantc51e1022010-05-11 19:42:16 +00002000_LIBCPP_END_NAMESPACE_STD
2001
2002#endif // _LIBCPP_ITERATOR