blob: 9415e0b83967d992a926ed1dcbcea0865f0a011a [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_ITERATOR
12#define _LIBCPP_ITERATOR
13
14/*
15 iterator synopsis
16
17namespace std
18{
19
20template<class Iterator>
21struct iterator_traits
22{
23 typedef typename Iterator::difference_type difference_type;
24 typedef typename Iterator::value_type value_type;
25 typedef typename Iterator::pointer pointer;
26 typedef typename Iterator::reference reference;
27 typedef typename Iterator::iterator_category iterator_category;
28};
29
30template<class T>
31struct iterator_traits<T*>
32{
33 typedef ptrdiff_t difference_type;
34 typedef T value_type;
35 typedef T* pointer;
36 typedef T& reference;
37 typedef random_access_iterator_tag iterator_category;
38};
39
Howard Hinnantc51e1022010-05-11 19:42:16 +000040template<class Category, class T, class Distance = ptrdiff_t,
41 class Pointer = T*, class Reference = T&>
42struct iterator
43{
44 typedef T value_type;
45 typedef Distance difference_type;
46 typedef Pointer pointer;
47 typedef Reference reference;
48 typedef Category iterator_category;
49};
50
51struct input_iterator_tag {};
52struct output_iterator_tag {};
53struct forward_iterator_tag : public input_iterator_tag {};
54struct bidirectional_iterator_tag : public forward_iterator_tag {};
55struct random_access_iterator_tag : public bidirectional_iterator_tag {};
56
Marshall Clow75468e72017-05-17 18:51:36 +000057// 27.4.3, iterator operations
Howard Hinnantc51e1022010-05-11 19:42:16 +000058// extension: second argument not conforming to C++03
Marshall Clow75468e72017-05-17 18:51:36 +000059template <class InputIterator> // constexpr in C++17
60 constexpr void advance(InputIterator& i,
Howard Hinnantc51e1022010-05-11 19:42:16 +000061 typename iterator_traits<InputIterator>::difference_type n);
62
Marshall Clow75468e72017-05-17 18:51:36 +000063template <class InputIterator> // constexpr in C++17
64 constexpr typename iterator_traits<InputIterator>::difference_type
65 distance(InputIterator first, InputIterator last);
66
67template <class InputIterator> // constexpr in C++17
68 constexpr InputIterator next(InputIterator x,
69typename iterator_traits<InputIterator>::difference_type n = 1);
70
71template <class BidirectionalIterator> // constexpr in C++17
72 constexpr BidirectionalIterator prev(BidirectionalIterator x,
73 typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +000074
75template <class Iterator>
76class reverse_iterator
77 : public iterator<typename iterator_traits<Iterator>::iterator_category,
78 typename iterator_traits<Iterator>::value_type,
79 typename iterator_traits<Iterator>::difference_type,
80 typename iterator_traits<Iterator>::pointer,
81 typename iterator_traits<Iterator>::reference>
82{
83protected:
84 Iterator current;
85public:
86 typedef Iterator iterator_type;
87 typedef typename iterator_traits<Iterator>::difference_type difference_type;
88 typedef typename iterator_traits<Iterator>::reference reference;
89 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000090
Marshall Clow5ace5542016-10-19 15:12:50 +000091 constexpr reverse_iterator();
92 constexpr explicit reverse_iterator(Iterator x);
93 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
94 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
95 constexpr Iterator base() const;
96 constexpr reference operator*() const;
97 constexpr pointer operator->() const;
98 constexpr reverse_iterator& operator++();
99 constexpr reverse_iterator operator++(int);
100 constexpr reverse_iterator& operator--();
101 constexpr reverse_iterator operator--(int);
102 constexpr reverse_iterator operator+ (difference_type n) const;
103 constexpr reverse_iterator& operator+=(difference_type n);
104 constexpr reverse_iterator operator- (difference_type n) const;
105 constexpr reverse_iterator& operator-=(difference_type n);
106 constexpr reference operator[](difference_type n) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000107};
108
109template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000110constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000111operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
112
113template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000114constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
116
117template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000118constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000119operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
120
121template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000122constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
124
125template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000126constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000127operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
128
129template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000130constexpr bool // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000131operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
132
133template <class Iterator1, class Iterator2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000134constexpr auto
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000135operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow5ace5542016-10-19 15:12:50 +0000136-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137
138template <class Iterator>
Marshall Clow5ace5542016-10-19 15:12:50 +0000139constexpr reverse_iterator<Iterator>
140operator+(typename reverse_iterator<Iterator>::difference_type n,
141 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142
Marshall Clow5ace5542016-10-19 15:12:50 +0000143template <class Iterator>
144constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000145
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146template <class Container>
147class back_insert_iterator
148{
149protected:
150 Container* container;
151public:
152 typedef Container container_type;
153 typedef void value_type;
154 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000155 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156 typedef void pointer;
157
158 explicit back_insert_iterator(Container& x);
Howard Hinnant60e95c62010-09-14 20:26:27 +0000159 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160 back_insert_iterator& operator*();
161 back_insert_iterator& operator++();
162 back_insert_iterator operator++(int);
163};
164
165template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
166
167template <class Container>
168class front_insert_iterator
169{
170protected:
171 Container* container;
172public:
173 typedef Container container_type;
174 typedef void value_type;
175 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000176 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177 typedef void pointer;
178
179 explicit front_insert_iterator(Container& x);
Howard Hinnant60e95c62010-09-14 20:26:27 +0000180 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181 front_insert_iterator& operator*();
182 front_insert_iterator& operator++();
183 front_insert_iterator operator++(int);
184};
185
186template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
187
188template <class Container>
189class insert_iterator
190{
191protected:
192 Container* container;
193 typename Container::iterator iter;
194public:
195 typedef Container container_type;
196 typedef void value_type;
197 typedef void difference_type;
Eric Fiselier9aeea872016-06-30 04:40:50 +0000198 typedef void reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000199 typedef void pointer;
200
201 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant60e95c62010-09-14 20:26:27 +0000202 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203 insert_iterator& operator*();
204 insert_iterator& operator++();
205 insert_iterator& operator++(int);
206};
207
208template <class Container, class Iterator>
209insert_iterator<Container> inserter(Container& x, Iterator i);
210
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000211template <class Iterator>
212class move_iterator {
213public:
214 typedef Iterator iterator_type;
215 typedef typename iterator_traits<Iterator>::difference_type difference_type;
216 typedef Iterator pointer;
217 typedef typename iterator_traits<Iterator>::value_type value_type;
218 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
219 typedef value_type&& reference;
220
Marshall Clowb5f99122016-11-02 15:30:26 +0000221 constexpr move_iterator(); // all the constexprs are in C++17
222 constexpr explicit move_iterator(Iterator i);
223 template <class U>
224 constexpr move_iterator(const move_iterator<U>& u);
225 template <class U>
226 constexpr move_iterator& operator=(const move_iterator<U>& u);
227 constexpr iterator_type base() const;
228 constexpr reference operator*() const;
229 constexpr pointer operator->() const;
230 constexpr move_iterator& operator++();
231 constexpr move_iterator operator++(int);
232 constexpr move_iterator& operator--();
233 constexpr move_iterator operator--(int);
234 constexpr move_iterator operator+(difference_type n) const;
235 constexpr move_iterator& operator+=(difference_type n);
236 constexpr move_iterator operator-(difference_type n) const;
237 constexpr move_iterator& operator-=(difference_type n);
238 constexpr unspecified operator[](difference_type n) const;
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000239private:
240 Iterator current; // exposition only
241};
242
243template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000244constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000245operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
246
247template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000248constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000249operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
250
251template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000252constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000253operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
254
255template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000256constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000257operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
258
259template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000260constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000261operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
262
263template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000264constexpr bool // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000265operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
266
267template <class Iterator1, class Iterator2>
Marshall Clowb5f99122016-11-02 15:30:26 +0000268constexpr auto // constexpr in C++17
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000269operator-(const move_iterator<Iterator1>& x,
270 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
271
272template <class Iterator>
Marshall Clowb5f99122016-11-02 15:30:26 +0000273constexpr move_iterator<Iterator> operator+( // constexpr in C++17
274 typename move_iterator<Iterator>::difference_type n,
275 const move_iterator<Iterator>& x);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000276
Marshall Clowb5f99122016-11-02 15:30:26 +0000277template <class Iterator> // constexpr in C++17
278constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000279
280
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
282class istream_iterator
283 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
284{
285public:
286 typedef charT char_type;
287 typedef traits traits_type;
288 typedef basic_istream<charT,traits> istream_type;
289
Marshall Clow0735e4e2015-04-16 21:36:54 +0000290 constexpr istream_iterator();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291 istream_iterator(istream_type& s);
292 istream_iterator(const istream_iterator& x);
293 ~istream_iterator();
294
295 const T& operator*() const;
296 const T* operator->() const;
297 istream_iterator& operator++();
298 istream_iterator operator++(int);
299};
300
301template <class T, class charT, class traits, class Distance>
302bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
303 const istream_iterator<T,charT,traits,Distance>& y);
304template <class T, class charT, class traits, class Distance>
305bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
306 const istream_iterator<T,charT,traits,Distance>& y);
307
308template <class T, class charT = char, class traits = char_traits<charT> >
309class ostream_iterator
310 : public iterator<output_iterator_tag, void, void, void ,void>
311{
312public:
313 typedef charT char_type;
314 typedef traits traits_type;
315 typedef basic_ostream<charT,traits> ostream_type;
316
317 ostream_iterator(ostream_type& s);
318 ostream_iterator(ostream_type& s, const charT* delimiter);
319 ostream_iterator(const ostream_iterator& x);
320 ~ostream_iterator();
321 ostream_iterator& operator=(const T& value);
322
323 ostream_iterator& operator*();
324 ostream_iterator& operator++();
325 ostream_iterator& operator++(int);
326};
327
328template<class charT, class traits = char_traits<charT> >
329class istreambuf_iterator
330 : public iterator<input_iterator_tag, charT,
331 typename traits::off_type, unspecified,
332 charT>
333{
334public:
335 typedef charT char_type;
336 typedef traits traits_type;
337 typedef typename traits::int_type int_type;
338 typedef basic_streambuf<charT,traits> streambuf_type;
339 typedef basic_istream<charT,traits> istream_type;
340
Howard Hinnant011138d2012-07-20 19:36:34 +0000341 istreambuf_iterator() noexcept;
342 istreambuf_iterator(istream_type& s) noexcept;
343 istreambuf_iterator(streambuf_type* s) noexcept;
344 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345
346 charT operator*() const;
347 pointer operator->() const;
348 istreambuf_iterator& operator++();
349 a-private-type operator++(int);
350
351 bool equal(const istreambuf_iterator& b) const;
352};
353
354template <class charT, class traits>
355bool operator==(const istreambuf_iterator<charT,traits>& a,
356 const istreambuf_iterator<charT,traits>& b);
357template <class charT, class traits>
358bool operator!=(const istreambuf_iterator<charT,traits>& a,
359 const istreambuf_iterator<charT,traits>& b);
360
361template <class charT, class traits = char_traits<charT> >
362class ostreambuf_iterator
363 : public iterator<output_iterator_tag, void, void, void, void>
364{
365public:
366 typedef charT char_type;
367 typedef traits traits_type;
368 typedef basic_streambuf<charT,traits> streambuf_type;
369 typedef basic_ostream<charT,traits> ostream_type;
370
Howard Hinnant011138d2012-07-20 19:36:34 +0000371 ostreambuf_iterator(ostream_type& s) noexcept;
372 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 ostreambuf_iterator& operator=(charT c);
374 ostreambuf_iterator& operator*();
375 ostreambuf_iterator& operator++();
376 ostreambuf_iterator& operator++(int);
Howard Hinnant011138d2012-07-20 19:36:34 +0000377 bool failed() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378};
379
Marshall Clow99ba0022017-01-04 17:58:17 +0000380template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
381template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
382template <class C> constexpr auto end(C& c) -> decltype(c.end());
383template <class C> constexpr auto end(const C& c) -> decltype(c.end());
384template <class T, size_t N> constexpr T* begin(T (&array)[N]);
385template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386
Marshall Clow99ba0022017-01-04 17:58:17 +0000387template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
388template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
389template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
390template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
391template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
392template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
393template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
394template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
395template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
396template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
397template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
398template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clowb278e9c2013-08-30 01:17:07 +0000399
Marshall Clowef357272014-11-19 19:43:23 +0000400// 24.8, container access:
401template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
402template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
403template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
404template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
405template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
406template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
407template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
408template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
409template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
410
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411} // std
412
413*/
414
415#include <__config>
Eric Fiselier876c6862016-02-20 00:19:45 +0000416#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow3dc05502014-02-27 02:11:50 +0000417#include <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000418#include <type_traits>
419#include <cstddef>
Marshall Clowb278e9c2013-08-30 01:17:07 +0000420#include <initializer_list>
Marshall Clowdde4bfe2013-03-18 17:45:34 +0000421#ifdef __APPLE__
Howard Hinnant48fd5d52012-11-14 21:17:15 +0000422#include <Availability.h>
423#endif
424
Eric Fiselier14b6de92014-08-10 23:53:08 +0000425#include <__debug>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000427#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000429#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430
431_LIBCPP_BEGIN_NAMESPACE_STD
432
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000433struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
434struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
435struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
436struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
437struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438
439template <class _Tp>
440struct __has_iterator_category
441{
442private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000443 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444 template <class _Up> static __two __test(...);
445 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
446public:
447 static const bool value = sizeof(__test<_Tp>(0)) == 1;
448};
449
Marshall Clow75533b02014-01-03 22:55:49 +0000450template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451
452template <class _Iter>
Marshall Clow75533b02014-01-03 22:55:49 +0000453struct __iterator_traits_impl<_Iter, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000454{
455 typedef typename _Iter::difference_type difference_type;
456 typedef typename _Iter::value_type value_type;
457 typedef typename _Iter::pointer pointer;
458 typedef typename _Iter::reference reference;
459 typedef typename _Iter::iterator_category iterator_category;
460};
461
462template <class _Iter, bool> struct __iterator_traits {};
463
464template <class _Iter>
465struct __iterator_traits<_Iter, true>
Marshall Clow75533b02014-01-03 22:55:49 +0000466 : __iterator_traits_impl
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467 <
468 _Iter,
469 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
470 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
471 >
472{};
473
474// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
475// exists. Else iterator_traits<Iterator> will be an empty class. This is a
476// conforming extension which allows some programs to compile and behave as
477// the client expects instead of failing at compile time.
478
479template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000480struct _LIBCPP_TEMPLATE_VIS iterator_traits
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
482
483template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000484struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485{
486 typedef ptrdiff_t difference_type;
Marshall Clow56d53522017-11-14 00:03:10 +0000487 typedef typename remove_cv<_Tp>::type value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 typedef _Tp* pointer;
489 typedef _Tp& reference;
490 typedef random_access_iterator_tag iterator_category;
491};
492
493template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
494struct __has_iterator_category_convertible_to
495 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
496{};
497
498template <class _Tp, class _Up>
499struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
500
501template <class _Tp>
502struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
503
504template <class _Tp>
505struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
506
507template <class _Tp>
508struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
509
510template <class _Tp>
511struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
512
Marshall Clow039b2f02016-01-13 21:54:34 +0000513template <class _Tp>
514struct __is_exactly_input_iterator
515 : public integral_constant<bool,
Marshall Clowb5f99122016-11-02 15:30:26 +0000516 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
517 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
Marshall Clow039b2f02016-01-13 21:54:34 +0000518
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519template<class _Category, class _Tp, class _Distance = ptrdiff_t,
520 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000521struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522{
523 typedef _Tp value_type;
524 typedef _Distance difference_type;
525 typedef _Pointer pointer;
526 typedef _Reference reference;
527 typedef _Category iterator_category;
528};
529
530template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000531inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532void __advance(_InputIter& __i,
533 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
534{
535 for (; __n > 0; --__n)
536 ++__i;
537}
538
539template <class _BiDirIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000540inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541void __advance(_BiDirIter& __i,
542 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
543{
544 if (__n >= 0)
545 for (; __n > 0; --__n)
546 ++__i;
547 else
548 for (; __n < 0; ++__n)
549 --__i;
550}
551
552template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000553inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554void __advance(_RandIter& __i,
555 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
556{
557 __i += __n;
558}
559
560template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000561inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562void advance(_InputIter& __i,
563 typename iterator_traits<_InputIter>::difference_type __n)
564{
565 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
566}
567
568template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000569inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570typename iterator_traits<_InputIter>::difference_type
571__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
572{
573 typename iterator_traits<_InputIter>::difference_type __r(0);
574 for (; __first != __last; ++__first)
575 ++__r;
576 return __r;
577}
578
579template <class _RandIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000580inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581typename iterator_traits<_RandIter>::difference_type
582__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
583{
584 return __last - __first;
585}
586
587template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000588inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589typename iterator_traits<_InputIter>::difference_type
590distance(_InputIter __first, _InputIter __last)
591{
592 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
593}
594
Marshall Clow990c70d2015-11-07 17:48:49 +0000595template <class _InputIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000596inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000597typename enable_if
598<
599 __is_input_iterator<_InputIter>::value,
600 _InputIter
601>::type
Marshall Clow990c70d2015-11-07 17:48:49 +0000602next(_InputIter __x,
Rachel Craik2048d822017-07-24 22:17:05 +0000603 typename iterator_traits<_InputIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000605 _VSTD::advance(__x, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606 return __x;
607}
608
Rachel Craik2048d822017-07-24 22:17:05 +0000609template <class _BidirectionalIter>
Marshall Clow75468e72017-05-17 18:51:36 +0000610inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Rachel Craik2048d822017-07-24 22:17:05 +0000611typename enable_if
612<
613 __is_bidirectional_iterator<_BidirectionalIter>::value,
614 _BidirectionalIter
615>::type
616prev(_BidirectionalIter __x,
617 typename iterator_traits<_BidirectionalIter>::difference_type __n = 1)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000619 _VSTD::advance(__x, -__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000620 return __x;
621}
622
Eric Fiselier883af112017-04-13 02:54:13 +0000623
624template <class _Tp, class = void>
625struct __is_stashing_iterator : false_type {};
626
627template <class _Tp>
628struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
629 : true_type {};
630
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000632class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633 : public iterator<typename iterator_traits<_Iter>::iterator_category,
634 typename iterator_traits<_Iter>::value_type,
635 typename iterator_traits<_Iter>::difference_type,
636 typename iterator_traits<_Iter>::pointer,
637 typename iterator_traits<_Iter>::reference>
638{
Marshall Clow0ad029e2014-03-11 22:05:31 +0000639private:
Marshall Clow5ace5542016-10-19 15:12:50 +0000640 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Eric Fiselier883af112017-04-13 02:54:13 +0000641
642 static_assert(!__is_stashing_iterator<_Iter>::value,
643 "The specified iterator type cannot be used with reverse_iterator; "
644 "Using stashing iterators with reverse_iterator causes undefined behavior");
645
Marshall Clow1f61f0a2014-03-12 01:19:36 +0000646protected:
647 _Iter current;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648public:
649 typedef _Iter iterator_type;
650 typedef typename iterator_traits<_Iter>::difference_type difference_type;
651 typedef typename iterator_traits<_Iter>::reference reference;
652 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000653
Marshall Clow5ace5542016-10-19 15:12:50 +0000654 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
655 reverse_iterator() : __t(), current() {}
656 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
657 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
658 template <class _Up>
659 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
660 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
661 template <class _Up>
662 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
663 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
664 { __t = current = __u.base(); return *this; }
665 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
666 _Iter base() const {return current;}
667 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
668 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
669 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
670 pointer operator->() const {return _VSTD::addressof(operator*());}
671 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
672 reverse_iterator& operator++() {--current; return *this;}
673 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
674 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
675 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
676 reverse_iterator& operator--() {++current; return *this;}
677 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
678 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
679 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
680 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
681 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
682 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
683 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
684 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
685 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
686 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
687 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
688 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000689};
690
691template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000692inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693bool
694operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
695{
696 return __x.base() == __y.base();
697}
698
699template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000700inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701bool
702operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
703{
704 return __x.base() > __y.base();
705}
706
707template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000708inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709bool
710operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
711{
712 return __x.base() != __y.base();
713}
714
715template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000716inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717bool
718operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
719{
720 return __x.base() < __y.base();
721}
722
723template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000724inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725bool
726operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
727{
728 return __x.base() <= __y.base();
729}
730
731template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000732inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733bool
734operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
735{
736 return __x.base() >= __y.base();
737}
738
Marshall Clow476d3f42016-07-18 13:19:00 +0000739#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000740template <class _Iter1, class _Iter2>
Marshall Clow5ace5542016-10-19 15:12:50 +0000741inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000742auto
743operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
744-> decltype(__y.base() - __x.base())
745{
746 return __y.base() - __x.base();
747}
748#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749template <class _Iter1, class _Iter2>
750inline _LIBCPP_INLINE_VISIBILITY
751typename reverse_iterator<_Iter1>::difference_type
752operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
753{
754 return __y.base() - __x.base();
755}
Marshall Clowf8fec4e2016-07-08 16:54:47 +0000756#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757
758template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000759inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760reverse_iterator<_Iter>
761operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
762{
763 return reverse_iterator<_Iter>(__x.base() - __n);
764}
765
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000766#if _LIBCPP_STD_VER > 11
767template <class _Iter>
Marshall Clow5ace5542016-10-19 15:12:50 +0000768inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6dbbdc92014-03-03 01:24:04 +0000769reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
770{
771 return reverse_iterator<_Iter>(__i);
772}
773#endif
774
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000776class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777 : public iterator<output_iterator_tag,
778 void,
779 void,
780 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000781 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782{
783protected:
784 _Container* container;
785public:
786 typedef _Container container_type;
787
Marshall Clowcef31682014-03-03 19:20:40 +0000788 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000789 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
790 {container->push_back(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000791#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf074022011-10-22 20:59:45 +0000792 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
793 {container->push_back(_VSTD::move(__value_)); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000794#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
796 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
797 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
798};
799
800template <class _Container>
801inline _LIBCPP_INLINE_VISIBILITY
802back_insert_iterator<_Container>
803back_inserter(_Container& __x)
804{
805 return back_insert_iterator<_Container>(__x);
806}
807
808template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000809class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810 : public iterator<output_iterator_tag,
811 void,
812 void,
813 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000814 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815{
816protected:
817 _Container* container;
818public:
819 typedef _Container container_type;
820
Marshall Clowcef31682014-03-03 19:20:40 +0000821 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000822 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
823 {container->push_front(__value_); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000824#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf074022011-10-22 20:59:45 +0000825 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
826 {container->push_front(_VSTD::move(__value_)); return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000827#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
829 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
830 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
831};
832
833template <class _Container>
834inline _LIBCPP_INLINE_VISIBILITY
835front_insert_iterator<_Container>
836front_inserter(_Container& __x)
837{
838 return front_insert_iterator<_Container>(__x);
839}
840
841template <class _Container>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000842class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843 : public iterator<output_iterator_tag,
844 void,
845 void,
846 void,
Eric Fiselier9aeea872016-06-30 04:40:50 +0000847 void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848{
849protected:
850 _Container* container;
851 typename _Container::iterator iter;
852public:
853 typedef _Container container_type;
854
855 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clowcef31682014-03-03 19:20:40 +0000856 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000857 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
858 {iter = container->insert(iter, __value_); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000859#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf074022011-10-22 20:59:45 +0000860 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
861 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000862#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
864 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
865 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
866};
867
868template <class _Container>
869inline _LIBCPP_INLINE_VISIBILITY
870insert_iterator<_Container>
871inserter(_Container& __x, typename _Container::iterator __i)
872{
873 return insert_iterator<_Container>(__x, __i);
874}
875
876template <class _Tp, class _CharT = char,
877 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000878class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
880{
881public:
882 typedef _CharT char_type;
883 typedef _Traits traits_type;
884 typedef basic_istream<_CharT,_Traits> istream_type;
885private:
886 istream_type* __in_stream_;
887 _Tp __value_;
888public:
Marshall Clow0735e4e2015-04-16 21:36:54 +0000889 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
Marshall Clowb7742702016-05-17 17:44:40 +0000890 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891 {
892 if (!(*__in_stream_ >> __value_))
893 __in_stream_ = 0;
894 }
895
896 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowb7742702016-05-17 17:44:40 +0000897 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
899 {
900 if (!(*__in_stream_ >> __value_))
901 __in_stream_ = 0;
902 return *this;
903 }
904 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
905 {istream_iterator __t(*this); ++(*this); return __t;}
906
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000907 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000909 bool
910 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
911 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000913 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 friend _LIBCPP_INLINE_VISIBILITY
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000915 bool
916 operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
917 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918};
919
Roger Ferrer Ibanezd16858b2017-12-11 13:54:58 +0000920template <class _Tp, class _CharT, class _Traits, class _Distance>
921inline _LIBCPP_INLINE_VISIBILITY
922bool
923operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
924 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
925{
926 return __x.__in_stream_ == __y.__in_stream_;
927}
928
929template <class _Tp, class _CharT, class _Traits, class _Distance>
930inline _LIBCPP_INLINE_VISIBILITY
931bool
932operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
933 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
934{
935 return !(__x == __y);
936}
937
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000939class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940 : public iterator<output_iterator_tag, void, void, void, void>
941{
942public:
943 typedef _CharT char_type;
944 typedef _Traits traits_type;
945 typedef basic_ostream<_CharT,_Traits> ostream_type;
946private:
947 ostream_type* __out_stream_;
948 const char_type* __delim_;
949public:
Marshall Clow27a89512016-10-12 16:13:48 +0000950 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +0000951 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
Marshall Clow27a89512016-10-12 16:13:48 +0000952 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowb7742702016-05-17 17:44:40 +0000953 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnantbf074022011-10-22 20:59:45 +0000954 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955 {
Howard Hinnantbf074022011-10-22 20:59:45 +0000956 *__out_stream_ << __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000957 if (__delim_)
958 *__out_stream_ << __delim_;
959 return *this;
960 }
961
962 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
963 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
964 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
965};
966
967template<class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000968class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969 : public iterator<input_iterator_tag, _CharT,
970 typename _Traits::off_type, _CharT*,
971 _CharT>
972{
973public:
974 typedef _CharT char_type;
975 typedef _Traits traits_type;
976 typedef typename _Traits::int_type int_type;
977 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
978 typedef basic_istream<_CharT,_Traits> istream_type;
979private:
Howard Hinnant3e57b272012-11-16 22:17:23 +0000980 mutable streambuf_type* __sbuf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981
982 class __proxy
983 {
984 char_type __keep_;
985 streambuf_type* __sbuf_;
986 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
987 : __keep_(__c), __sbuf_(__s) {}
988 friend class istreambuf_iterator;
989 public:
990 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
991 };
992
Howard Hinnant756c69b2010-09-22 16:48:34 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e57b272012-11-16 22:17:23 +0000994 bool __test_for_eof() const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995 {
996 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
997 __sbuf_ = 0;
Howard Hinnant3e57b272012-11-16 22:17:23 +0000998 return __sbuf_ == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000999 }
1000public:
Howard Hinnant3e57b272012-11-16 22:17:23 +00001001 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001002 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001003 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001004 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantb9af8d82012-12-29 17:45:42 +00001005 : __sbuf_(__s) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001006 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007 : __sbuf_(__p.__sbuf_) {}
1008
Howard Hinnant28b24882011-12-01 20:21:04 +00001009 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
1010 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
1012 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001013 __sbuf_->sbumpc();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 return *this;
1015 }
1016 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
1017 {
Howard Hinnant3e57b272012-11-16 22:17:23 +00001018 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019 }
1020
1021 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant3e57b272012-11-16 22:17:23 +00001022 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023};
1024
1025template <class _CharT, class _Traits>
1026inline _LIBCPP_INLINE_VISIBILITY
1027bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
1028 const istreambuf_iterator<_CharT,_Traits>& __b)
1029 {return __a.equal(__b);}
1030
1031template <class _CharT, class _Traits>
1032inline _LIBCPP_INLINE_VISIBILITY
1033bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
1034 const istreambuf_iterator<_CharT,_Traits>& __b)
1035 {return !__a.equal(__b);}
1036
1037template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001038class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039 : public iterator<output_iterator_tag, void, void, void, void>
1040{
1041public:
1042 typedef _CharT char_type;
1043 typedef _Traits traits_type;
1044 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1045 typedef basic_ostream<_CharT,_Traits> ostream_type;
1046private:
1047 streambuf_type* __sbuf_;
1048public:
Howard Hinnant011138d2012-07-20 19:36:34 +00001049 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 : __sbuf_(__s.rdbuf()) {}
Howard Hinnant011138d2012-07-20 19:36:34 +00001051 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 : __sbuf_(__s) {}
1053 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1054 {
1055 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1056 __sbuf_ = 0;
1057 return *this;
1058 }
1059 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1060 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1061 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnant011138d2012-07-20 19:36:34 +00001062 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnant97955172012-09-19 19:14:15 +00001063
Howard Hinnant48fd5d52012-11-14 21:17:15 +00001064#if !defined(__APPLE__) || \
1065 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1066 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1067
Howard Hinnant97955172012-09-19 19:14:15 +00001068 template <class _Ch, class _Tr>
1069 friend
1070 _LIBCPP_HIDDEN
1071 ostreambuf_iterator<_Ch, _Tr>
1072 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1073 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1074 ios_base& __iob, _Ch __fl);
Howard Hinnant48fd5d52012-11-14 21:17:15 +00001075#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076};
1077
1078template <class _Iter>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001079class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080{
1081private:
1082 _Iter __i;
1083public:
1084 typedef _Iter iterator_type;
1085 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1086 typedef typename iterator_traits<iterator_type>::value_type value_type;
1087 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowd85a0562016-04-11 03:54:53 +00001088 typedef iterator_type pointer;
Eric Fiselierf07d88c2017-04-19 01:34:08 +00001089#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier57b8e0e2016-04-22 00:49:12 +00001090 typedef typename iterator_traits<iterator_type>::reference __reference;
1091 typedef typename conditional<
1092 is_reference<__reference>::value,
1093 typename remove_reference<__reference>::type&&,
1094 __reference
1095 >::type reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096#else
1097 typedef typename iterator_traits<iterator_type>::reference reference;
1098#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001099
Marshall Clowb5f99122016-11-02 15:30:26 +00001100 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1101 move_iterator() : __i() {}
1102 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1103 explicit move_iterator(_Iter __x) : __i(__x) {}
1104 template <class _Up>
1105 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1106 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1107 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1108 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1109 reference operator*() const { return static_cast<reference>(*__i); }
1110 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1111 pointer operator->() const { return __i;}
1112 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1113 move_iterator& operator++() {++__i; return *this;}
1114 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1115 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1116 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1117 move_iterator& operator--() {--__i; return *this;}
1118 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1119 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1120 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1121 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1122 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1123 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1124 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1125 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1126 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1127 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1128 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1129 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130};
1131
1132template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001133inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134bool
1135operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1136{
1137 return __x.base() == __y.base();
1138}
1139
1140template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001141inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142bool
1143operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1144{
1145 return __x.base() < __y.base();
1146}
1147
1148template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001149inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001150bool
1151operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1152{
1153 return __x.base() != __y.base();
1154}
1155
1156template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001157inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158bool
1159operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1160{
1161 return __x.base() > __y.base();
1162}
1163
1164template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001165inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166bool
1167operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1168{
1169 return __x.base() >= __y.base();
1170}
1171
1172template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001173inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174bool
1175operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1176{
1177 return __x.base() <= __y.base();
1178}
1179
Marshall Clow476d3f42016-07-18 13:19:00 +00001180#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001181template <class _Iter1, class _Iter2>
Marshall Clowb5f99122016-11-02 15:30:26 +00001182inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001183auto
1184operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1185-> decltype(__x.base() - __y.base())
1186{
1187 return __x.base() - __y.base();
1188}
1189#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190template <class _Iter1, class _Iter2>
1191inline _LIBCPP_INLINE_VISIBILITY
1192typename move_iterator<_Iter1>::difference_type
1193operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1194{
1195 return __x.base() - __y.base();
1196}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001197#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198
1199template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001200inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001201move_iterator<_Iter>
1202operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1203{
1204 return move_iterator<_Iter>(__x.base() + __n);
1205}
1206
1207template <class _Iter>
Marshall Clowb5f99122016-11-02 15:30:26 +00001208inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209move_iterator<_Iter>
Marshall Clow84f90cf2013-08-27 13:03:03 +00001210make_move_iterator(_Iter __i)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001211{
1212 return move_iterator<_Iter>(__i);
1213}
1214
1215// __wrap_iter
1216
1217template <class _Iter> class __wrap_iter;
1218
1219template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001220_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001222operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223
1224template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001225_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001226bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001227operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228
1229template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001230_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001232operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233
1234template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001235_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001236bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001237operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238
1239template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001240_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001241bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001242operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001243
1244template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001245_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001246bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001247operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248
Marshall Clow476d3f42016-07-18 13:19:00 +00001249#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001250template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001251_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001252auto
Eric Fiselier38badb82016-12-28 05:35:32 +00001253operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001254-> decltype(__x.base() - __y.base());
1255#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001256template <class _Iter1, class _Iter2>
Howard Hinnanta54386e2012-09-14 00:39:16 +00001257_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier38badb82016-12-28 05:35:32 +00001259operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001260#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001261
1262template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001263_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264__wrap_iter<_Iter>
Eric Fiselier38badb82016-12-28 05:35:32 +00001265operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266
Howard Hinnanta54386e2012-09-14 00:39:16 +00001267template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1268template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1269template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1270template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001271
Eric Fiselier38badb82016-12-28 05:35:32 +00001272#if _LIBCPP_DEBUG_LEVEL < 2
1273
Howard Hinnantc51e1022010-05-11 19:42:16 +00001274template <class _Tp>
Marshall Clowae4f8312018-07-13 16:35:26 +00001275_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001276typename enable_if
1277<
Howard Hinnanta9a897e2010-11-19 22:17:28 +00001278 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001279 _Tp*
1280>::type
1281__unwrap_iter(__wrap_iter<_Tp*>);
1282
Eric Fiselier38badb82016-12-28 05:35:32 +00001283#else
1284
1285template <class _Tp>
Marshall Clowae4f8312018-07-13 16:35:26 +00001286inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Eric Fiselier38badb82016-12-28 05:35:32 +00001287typename enable_if
1288<
1289 is_trivially_copy_assignable<_Tp>::value,
1290 __wrap_iter<_Tp*>
1291>::type
1292__unwrap_iter(__wrap_iter<_Tp*> __i);
1293
1294#endif
1295
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296template <class _Iter>
1297class __wrap_iter
1298{
1299public:
1300 typedef _Iter iterator_type;
1301 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1302 typedef typename iterator_traits<iterator_type>::value_type value_type;
1303 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1304 typedef typename iterator_traits<iterator_type>::pointer pointer;
1305 typedef typename iterator_traits<iterator_type>::reference reference;
1306private:
1307 iterator_type __i;
1308public:
Marshall Clowae4f8312018-07-13 16:35:26 +00001309 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT_DEBUG
Marshall Clow4e7b35b2013-08-07 20:48:48 +00001310#if _LIBCPP_STD_VER > 11
1311 : __i{}
1312#endif
Howard Hinnantc90aa632011-09-16 19:52:23 +00001313 {
1314#if _LIBCPP_DEBUG_LEVEL >= 2
1315 __get_db()->__insert_i(this);
1316#endif
1317 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001318 template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1319 __wrap_iter(const __wrap_iter<_Up>& __u,
1320 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG
1321 : __i(__u.base())
Howard Hinnant27e0e772011-09-14 18:33:51 +00001322 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001323#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001324 __get_db()->__iterator_copy(this, &__u);
1325#endif
1326 }
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001327#if _LIBCPP_DEBUG_LEVEL >= 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001328 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001329 __wrap_iter(const __wrap_iter& __x)
1330 : __i(__x.base())
1331 {
1332 __get_db()->__iterator_copy(this, &__x);
1333 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001334 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001335 __wrap_iter& operator=(const __wrap_iter& __x)
1336 {
1337 if (this != &__x)
1338 {
1339 __get_db()->__iterator_copy(this, &__x);
1340 __i = __x.__i;
1341 }
1342 return *this;
1343 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001344 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001345 ~__wrap_iter()
1346 {
1347 __get_db()->__erase_i(this);
1348 }
1349#endif
Marshall Clowae4f8312018-07-13 16:35:26 +00001350 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001351 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001352#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001353 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1354 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001355#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001356 return *__i;
1357 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001358 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT_DEBUG
Howard Hinnant76053d72013-06-27 19:35:32 +00001359 {
1360#if _LIBCPP_DEBUG_LEVEL >= 2
1361 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1362 "Attempted to dereference a non-dereferenceable iterator");
1363#endif
Marshall Clowd85a0562016-04-11 03:54:53 +00001364 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant76053d72013-06-27 19:35:32 +00001365 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001366 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001367 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001368#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001369 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1370 "Attempted to increment non-incrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001371#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001372 ++__i;
1373 return *this;
1374 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001375 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001376 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Marshall Clow6d553a52018-07-14 03:06:11 +00001377
1378 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001379 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001380#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001381 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1382 "Attempted to decrement non-decrementable iterator");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001383#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001384 --__i;
1385 return *this;
1386 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001387 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001388 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Marshall Clowae4f8312018-07-13 16:35:26 +00001389 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001390 {__wrap_iter __w(*this); __w += __n; return __w;}
Marshall Clowae4f8312018-07-13 16:35:26 +00001391 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001392 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001393#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001394 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1395 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001396#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001397 __i += __n;
1398 return *this;
1399 }
Marshall Clowae4f8312018-07-13 16:35:26 +00001400 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001401 {return *this + (-__n);}
Marshall Clowae4f8312018-07-13 16:35:26 +00001402 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001403 {*this += -__n; return *this;}
Marshall Clowae4f8312018-07-13 16:35:26 +00001404 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT_DEBUG
Howard Hinnant27e0e772011-09-14 18:33:51 +00001405 {
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001406#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant27e0e772011-09-14 18:33:51 +00001407 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1408 "Attempted to subscript iterator outside of valid range");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001409#endif
Howard Hinnant27e0e772011-09-14 18:33:51 +00001410 return __i[__n];
1411 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412
Marshall Clowae4f8312018-07-13 16:35:26 +00001413 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT_DEBUG {return __i;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414
1415private:
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001416#if _LIBCPP_DEBUG_LEVEL >= 2
Marshall Clowae4f8312018-07-13 16:35:26 +00001417 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
Howard Hinnant27e0e772011-09-14 18:33:51 +00001418 {
1419 __get_db()->__insert_ic(this, __p);
1420 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00001421#else
Marshall Clowae4f8312018-07-13 16:35:26 +00001422 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {}
Howard Hinnant27e0e772011-09-14 18:33:51 +00001423#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424
1425 template <class _Up> friend class __wrap_iter;
1426 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001427 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Marshall Clowae4f8312018-07-13 16:35:26 +00001428 template <class _Tp, ptrdiff_t> friend class _LIBCPP_TEMPLATE_VIS span;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001429
1430 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001431 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432 bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001433 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001434
Howard Hinnantc51e1022010-05-11 19:42:16 +00001435 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001436 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437 bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001438 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001439
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001441 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442 bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001443 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001444
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001446 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447 bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001448 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001449
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001451 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001452 bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001453 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001454
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001456 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457 bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001458 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001459
Marshall Clow476d3f42016-07-18 13:19:00 +00001460#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001461 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001462 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001463 auto
Eric Fiselier38badb82016-12-28 05:35:32 +00001464 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001465 -> decltype(__x.base() - __y.base());
1466#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467 template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001468 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001469 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier38badb82016-12-28 05:35:32 +00001470 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001471#endif
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001472
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473 template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001474 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475 __wrap_iter<_Iter1>
Eric Fiselier38badb82016-12-28 05:35:32 +00001476 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001477
Howard Hinnantc834c512011-11-29 18:15:50 +00001478 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnantc834c512011-11-29 18:15:50 +00001480 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001481 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1482
Eric Fiselier38badb82016-12-28 05:35:32 +00001483#if _LIBCPP_DEBUG_LEVEL < 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484 template <class _Tp>
Marshall Clowae4f8312018-07-13 16:35:26 +00001485 _LIBCPP_CONSTEXPR_IF_NODEBUG friend
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486 typename enable_if
1487 <
Howard Hinnanta9a897e2010-11-19 22:17:28 +00001488 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001489 _Tp*
1490 >::type
1491 __unwrap_iter(__wrap_iter<_Tp*>);
Eric Fiselier38badb82016-12-28 05:35:32 +00001492#else
1493 template <class _Tp>
Marshall Clowae4f8312018-07-13 16:35:26 +00001494 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Eric Fiselier38badb82016-12-28 05:35:32 +00001495 typename enable_if
1496 <
1497 is_trivially_copy_assignable<_Tp>::value,
1498 __wrap_iter<_Tp*>
1499 >::type
1500 __unwrap_iter(__wrap_iter<_Tp*> __i);
1501#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502};
1503
1504template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001505inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001507operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508{
1509 return __x.base() == __y.base();
1510}
1511
1512template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001513inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001515operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516{
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001517#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001518 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001519 "Attempted to compare incomparable iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001520#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001521 return __x.base() < __y.base();
1522}
1523
1524template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001525inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001527operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001529 return !(__x == __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001530}
1531
1532template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001533inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001535operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001536{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001537 return __y < __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001538}
1539
1540template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001541inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001542bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001543operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001545 return !(__x < __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546}
1547
1548template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001549inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001551operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001553 return !(__y < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001554}
1555
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001556template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001557inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001558bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001559operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001560{
1561 return !(__x == __y);
1562}
1563
1564template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001565inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001566bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001567operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001568{
1569 return __y < __x;
1570}
1571
1572template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001573inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001574bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001575operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001576{
1577 return !(__x < __y);
1578}
1579
1580template <class _Iter1>
Marshall Clowae4f8312018-07-13 16:35:26 +00001581inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001582bool
Eric Fiselier38badb82016-12-28 05:35:32 +00001583operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnantf78e32c2012-10-02 19:45:42 +00001584{
1585 return !(__y < __x);
1586}
1587
Marshall Clow476d3f42016-07-18 13:19:00 +00001588#ifndef _LIBCPP_CXX03_LANG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001589template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001590inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001591auto
Eric Fiselier38badb82016-12-28 05:35:32 +00001592operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001593-> decltype(__x.base() - __y.base())
1594{
1595#if _LIBCPP_DEBUG_LEVEL >= 2
1596 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1597 "Attempted to subtract incompatible iterators");
1598#endif
1599 return __x.base() - __y.base();
1600}
1601#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602template <class _Iter1, class _Iter2>
Marshall Clowae4f8312018-07-13 16:35:26 +00001603inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier38badb82016-12-28 05:35:32 +00001605operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001606{
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001607#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnante6ff0b62013-08-02 00:26:35 +00001608 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant27e0e772011-09-14 18:33:51 +00001609 "Attempted to subtract incompatible iterators");
Howard Hinnanta47c6d52011-09-16 17:29:17 +00001610#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001611 return __x.base() - __y.base();
1612}
Marshall Clowf8fec4e2016-07-08 16:54:47 +00001613#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001614
1615template <class _Iter>
Marshall Clowae4f8312018-07-13 16:35:26 +00001616inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001617__wrap_iter<_Iter>
1618operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier38badb82016-12-28 05:35:32 +00001619 __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620{
Howard Hinnant27e0e772011-09-14 18:33:51 +00001621 __x += __n;
1622 return __x;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623}
1624
Marshall Clow039b2f02016-01-13 21:54:34 +00001625template <class _Iter>
1626struct __libcpp_is_trivial_iterator
Marshall Clowb5f99122016-11-02 15:30:26 +00001627 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1628
Marshall Clow039b2f02016-01-13 21:54:34 +00001629template <class _Iter>
1630struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001631 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001632
1633template <class _Iter>
1634struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001635 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001636
1637template <class _Iter>
1638struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
Marshall Clowb5f99122016-11-02 15:30:26 +00001639 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clow039b2f02016-01-13 21:54:34 +00001640
1641
Marshall Clow8411ebf2013-12-02 03:24:33 +00001642template <class _Tp, size_t _Np>
Marshall Clowe0ba8862014-02-19 17:53:30 +00001643inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001644_Tp*
1645begin(_Tp (&__array)[_Np])
1646{
1647 return __array;
1648}
1649
1650template <class _Tp, size_t _Np>
Marshall Clowe0ba8862014-02-19 17:53:30 +00001651inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow8411ebf2013-12-02 03:24:33 +00001652_Tp*
1653end(_Tp (&__array)[_Np])
1654{
1655 return __array + _Np;
1656}
1657
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001658#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow037fcb72013-12-11 19:32:32 +00001659
Howard Hinnantc834c512011-11-29 18:15:50 +00001660template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001661inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001662auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001663begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664{
1665 return __c.begin();
1666}
1667
Howard Hinnantc834c512011-11-29 18:15:50 +00001668template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001669inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001670auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001671begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001672{
1673 return __c.begin();
1674}
1675
Howard Hinnantc834c512011-11-29 18:15:50 +00001676template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001677inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001678auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001679end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680{
1681 return __c.end();
1682}
1683
Howard Hinnantc834c512011-11-29 18:15:50 +00001684template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001685inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantc51e1022010-05-11 19:42:16 +00001686auto
Howard Hinnantc834c512011-11-29 18:15:50 +00001687end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688{
1689 return __c.end();
1690}
1691
Marshall Clowb278e9c2013-08-30 01:17:07 +00001692#if _LIBCPP_STD_VER > 11
1693
Marshall Clow8411ebf2013-12-02 03:24:33 +00001694template <class _Tp, size_t _Np>
Marshall Clow99ba0022017-01-04 17:58:17 +00001695inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001696reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1697{
1698 return reverse_iterator<_Tp*>(__array + _Np);
1699}
1700
1701template <class _Tp, size_t _Np>
Marshall Clow99ba0022017-01-04 17:58:17 +00001702inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001703reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1704{
1705 return reverse_iterator<_Tp*>(__array);
1706}
1707
1708template <class _Ep>
Marshall Clow99ba0022017-01-04 17:58:17 +00001709inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001710reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1711{
1712 return reverse_iterator<const _Ep*>(__il.end());
1713}
1714
1715template <class _Ep>
Marshall Clow99ba0022017-01-04 17:58:17 +00001716inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow8411ebf2013-12-02 03:24:33 +00001717reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1718{
1719 return reverse_iterator<const _Ep*>(__il.begin());
1720}
1721
Marshall Clowb278e9c2013-08-30 01:17:07 +00001722template <class _Cp>
Marshall Clowe0ba8862014-02-19 17:53:30 +00001723inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001724auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001725{
Marshall Clow3862f532016-08-10 20:04:46 +00001726 return _VSTD::begin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001727}
1728
1729template <class _Cp>
Marshall Clowe0ba8862014-02-19 17:53:30 +00001730inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow3862f532016-08-10 20:04:46 +00001731auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001732{
Marshall Clow3862f532016-08-10 20:04:46 +00001733 return _VSTD::end(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001734}
1735
1736template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001737inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001738auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1739{
1740 return __c.rbegin();
1741}
1742
1743template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001744inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001745auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1746{
1747 return __c.rbegin();
1748}
1749
1750template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001751inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001752auto rend(_Cp& __c) -> decltype(__c.rend())
1753{
1754 return __c.rend();
1755}
1756
1757template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001758inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowb278e9c2013-08-30 01:17:07 +00001759auto rend(const _Cp& __c) -> decltype(__c.rend())
1760{
1761 return __c.rend();
1762}
1763
1764template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001765inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001766auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001767{
Marshall Clow3862f532016-08-10 20:04:46 +00001768 return _VSTD::rbegin(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001769}
1770
1771template <class _Cp>
Marshall Clow99ba0022017-01-04 17:58:17 +00001772inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow3862f532016-08-10 20:04:46 +00001773auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clowb278e9c2013-08-30 01:17:07 +00001774{
Marshall Clow3862f532016-08-10 20:04:46 +00001775 return _VSTD::rend(__c);
Marshall Clowb278e9c2013-08-30 01:17:07 +00001776}
1777
1778#endif
1779
1780
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001781#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001782
Howard Hinnantc834c512011-11-29 18:15:50 +00001783template <class _Cp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001784inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001785typename _Cp::iterator
1786begin(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001787{
1788 return __c.begin();
1789}
1790
Howard Hinnantc834c512011-11-29 18:15:50 +00001791template <class _Cp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001792inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001793typename _Cp::const_iterator
1794begin(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001795{
1796 return __c.begin();
1797}
1798
Howard Hinnantc834c512011-11-29 18:15:50 +00001799template <class _Cp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001800inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001801typename _Cp::iterator
1802end(_Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001803{
1804 return __c.end();
1805}
1806
Howard Hinnantc834c512011-11-29 18:15:50 +00001807template <class _Cp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001808inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001809typename _Cp::const_iterator
1810end(const _Cp& __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001811{
1812 return __c.end();
1813}
1814
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001815#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001816
Marshall Clowef357272014-11-19 19:43:23 +00001817#if _LIBCPP_STD_VER > 14
Marshall Clow344c41d2017-11-16 17:55:41 +00001818
1819// #if _LIBCPP_STD_VER > 11
1820// template <>
1821// struct _LIBCPP_TEMPLATE_VIS plus<void>
1822// {
1823// template <class _T1, class _T2>
1824// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1825// auto operator()(_T1&& __t, _T2&& __u) const
1826// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1827// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1828// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1829// typedef void is_transparent;
1830// };
1831// #endif
1832
Marshall Clowc4b4a342015-02-11 16:14:01 +00001833template <class _Cont>
Marshall Clowb7db4972017-11-15 20:02:27 +00001834inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001835constexpr auto size(const _Cont& __c)
1836_NOEXCEPT_(noexcept(__c.size()))
1837-> decltype (__c.size())
1838{ return __c.size(); }
Marshall Clowef357272014-11-19 19:43:23 +00001839
Marshall Clowc4b4a342015-02-11 16:14:01 +00001840template <class _Tp, size_t _Sz>
Marshall Clowb7db4972017-11-15 20:02:27 +00001841inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001842constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clowef357272014-11-19 19:43:23 +00001843
Marshall Clowc4b4a342015-02-11 16:14:01 +00001844template <class _Cont>
Marshall Clowb7db4972017-11-15 20:02:27 +00001845_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001846constexpr auto empty(const _Cont& __c)
1847_NOEXCEPT_(noexcept(__c.empty()))
1848-> decltype (__c.empty())
1849{ return __c.empty(); }
Marshall Clowef357272014-11-19 19:43:23 +00001850
Marshall Clowc4b4a342015-02-11 16:14:01 +00001851template <class _Tp, size_t _Sz>
Marshall Clowb7db4972017-11-15 20:02:27 +00001852_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6003c772016-12-23 23:37:52 +00001853constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clowef357272014-11-19 19:43:23 +00001854
1855template <class _Ep>
Marshall Clowb7db4972017-11-15 20:02:27 +00001856_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001857constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1858
Marshall Clowc4b4a342015-02-11 16:14:01 +00001859template <class _Cont> constexpr
Marshall Clowb7db4972017-11-15 20:02:27 +00001860inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001861auto data(_Cont& __c)
1862_NOEXCEPT_(noexcept(__c.data()))
1863-> decltype (__c.data())
1864{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001865
Marshall Clowc4b4a342015-02-11 16:14:01 +00001866template <class _Cont> constexpr
Marshall Clowb7db4972017-11-15 20:02:27 +00001867inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow344c41d2017-11-16 17:55:41 +00001868auto data(const _Cont& __c)
1869_NOEXCEPT_(noexcept(__c.data()))
1870-> decltype (__c.data())
1871{ return __c.data(); }
Marshall Clowef357272014-11-19 19:43:23 +00001872
Marshall Clowc4b4a342015-02-11 16:14:01 +00001873template <class _Tp, size_t _Sz>
Marshall Clowb7db4972017-11-15 20:02:27 +00001874inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowc4b4a342015-02-11 16:14:01 +00001875constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clowef357272014-11-19 19:43:23 +00001876
1877template <class _Ep>
Marshall Clowb7db4972017-11-15 20:02:27 +00001878inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowef357272014-11-19 19:43:23 +00001879constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1880#endif
1881
1882
Howard Hinnantc51e1022010-05-11 19:42:16 +00001883_LIBCPP_END_NAMESPACE_STD
1884
1885#endif // _LIBCPP_ITERATOR