blob: b8f657085c6bb96592507a6eecf3df09667d16d2 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===-------------------------- iterator ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
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
40template<class T>
41struct iterator_traits<const T*>
42{
43 typedef ptrdiff_t difference_type;
44 typedef T value_type;
45 typedef const T* pointer;
46 typedef const T& reference;
47 typedef random_access_iterator_tag iterator_category;
48};
49
50template<class Category, class T, class Distance = ptrdiff_t,
51 class Pointer = T*, class Reference = T&>
52struct iterator
53{
54 typedef T value_type;
55 typedef Distance difference_type;
56 typedef Pointer pointer;
57 typedef Reference reference;
58 typedef Category iterator_category;
59};
60
61struct input_iterator_tag {};
62struct output_iterator_tag {};
63struct forward_iterator_tag : public input_iterator_tag {};
64struct bidirectional_iterator_tag : public forward_iterator_tag {};
65struct random_access_iterator_tag : public bidirectional_iterator_tag {};
66
67// extension: second argument not conforming to C++03
68template <class InputIterator>
69void advance(InputIterator& i,
70 typename iterator_traits<InputIterator>::difference_type n);
71
72template <class InputIterator>
73typename iterator_traits<InputIterator>::difference_type
74distance(InputIterator first, InputIterator last);
75
76template <class Iterator>
77class reverse_iterator
78 : public iterator<typename iterator_traits<Iterator>::iterator_category,
79 typename iterator_traits<Iterator>::value_type,
80 typename iterator_traits<Iterator>::difference_type,
81 typename iterator_traits<Iterator>::pointer,
82 typename iterator_traits<Iterator>::reference>
83{
84protected:
85 Iterator current;
86public:
87 typedef Iterator iterator_type;
88 typedef typename iterator_traits<Iterator>::difference_type difference_type;
89 typedef typename iterator_traits<Iterator>::reference reference;
90 typedef typename iterator_traits<Iterator>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:4391
Marshall Clow4414a6a2016-10-19 15:12:5092 constexpr reverse_iterator();
93 constexpr explicit reverse_iterator(Iterator x);
94 template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
95 template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
96 constexpr Iterator base() const;
97 constexpr reference operator*() const;
98 constexpr pointer operator->() const;
99 constexpr reverse_iterator& operator++();
100 constexpr reverse_iterator operator++(int);
101 constexpr reverse_iterator& operator--();
102 constexpr reverse_iterator operator--(int);
103 constexpr reverse_iterator operator+ (difference_type n) const;
104 constexpr reverse_iterator& operator+=(difference_type n);
105 constexpr reverse_iterator operator- (difference_type n) const;
106 constexpr reverse_iterator& operator-=(difference_type n);
107 constexpr reference operator[](difference_type n) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16108};
109
110template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50111constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16112operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
113
114template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50115constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16116operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
117
118template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50119constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16120operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
121
122template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50123constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16124operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
125
126template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50127constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16128operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
129
130template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50131constexpr bool // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16132operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
133
134template <class Iterator1, class Iterator2>
Marshall Clow4414a6a2016-10-19 15:12:50135constexpr auto
Marshall Clowdf4a22d2016-07-08 16:54:47136operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
Marshall Clow4414a6a2016-10-19 15:12:50137-> decltype(__y.base() - __x.base()); // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16138
139template <class Iterator>
Marshall Clow4414a6a2016-10-19 15:12:50140constexpr reverse_iterator<Iterator>
141operator+(typename reverse_iterator<Iterator>::difference_type n,
142 const reverse_iterator<Iterator>& x); // constexpr in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16143
Marshall Clow4414a6a2016-10-19 15:12:50144template <class Iterator>
145constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
Marshall Clowff137e92014-03-03 01:24:04146
Howard Hinnantbc8d3f92010-05-11 19:42:16147template <class Container>
148class back_insert_iterator
149{
150protected:
151 Container* container;
152public:
153 typedef Container container_type;
154 typedef void value_type;
155 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50156 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16157 typedef void pointer;
158
159 explicit back_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27160 back_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16161 back_insert_iterator& operator*();
162 back_insert_iterator& operator++();
163 back_insert_iterator operator++(int);
164};
165
166template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
167
168template <class Container>
169class front_insert_iterator
170{
171protected:
172 Container* container;
173public:
174 typedef Container container_type;
175 typedef void value_type;
176 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50177 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16178 typedef void pointer;
179
180 explicit front_insert_iterator(Container& x);
Howard Hinnant45f57172010-09-14 20:26:27181 front_insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16182 front_insert_iterator& operator*();
183 front_insert_iterator& operator++();
184 front_insert_iterator operator++(int);
185};
186
187template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
188
189template <class Container>
190class insert_iterator
191{
192protected:
193 Container* container;
194 typename Container::iterator iter;
195public:
196 typedef Container container_type;
197 typedef void value_type;
198 typedef void difference_type;
Eric Fiselierc848cef2016-06-30 04:40:50199 typedef void reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16200 typedef void pointer;
201
202 insert_iterator(Container& x, typename Container::iterator i);
Howard Hinnant45f57172010-09-14 20:26:27203 insert_iterator& operator=(const typename Container::value_type& value);
Howard Hinnantbc8d3f92010-05-11 19:42:16204 insert_iterator& operator*();
205 insert_iterator& operator++();
206 insert_iterator& operator++(int);
207};
208
209template <class Container, class Iterator>
210insert_iterator<Container> inserter(Container& x, Iterator i);
211
Marshall Clowdf4a22d2016-07-08 16:54:47212template <class Iterator>
213class move_iterator {
214public:
215 typedef Iterator iterator_type;
216 typedef typename iterator_traits<Iterator>::difference_type difference_type;
217 typedef Iterator pointer;
218 typedef typename iterator_traits<Iterator>::value_type value_type;
219 typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
220 typedef value_type&& reference;
221
Marshall Clowf333bee2016-11-02 15:30:26222 constexpr move_iterator(); // all the constexprs are in C++17
223 constexpr explicit move_iterator(Iterator i);
224 template <class U>
225 constexpr move_iterator(const move_iterator<U>& u);
226 template <class U>
227 constexpr move_iterator& operator=(const move_iterator<U>& u);
228 constexpr iterator_type base() const;
229 constexpr reference operator*() const;
230 constexpr pointer operator->() const;
231 constexpr move_iterator& operator++();
232 constexpr move_iterator operator++(int);
233 constexpr move_iterator& operator--();
234 constexpr move_iterator operator--(int);
235 constexpr move_iterator operator+(difference_type n) const;
236 constexpr move_iterator& operator+=(difference_type n);
237 constexpr move_iterator operator-(difference_type n) const;
238 constexpr move_iterator& operator-=(difference_type n);
239 constexpr unspecified operator[](difference_type n) const;
Marshall Clowdf4a22d2016-07-08 16:54:47240private:
241 Iterator current; // exposition only
242};
243
244template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26245constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47246operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
247
248template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26249constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47250operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
251
252template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26253constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47254operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
255
256template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26257constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47258operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
259
260template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26261constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47262operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
263
264template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26265constexpr bool // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47266operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
267
268template <class Iterator1, class Iterator2>
Marshall Clowf333bee2016-11-02 15:30:26269constexpr auto // constexpr in C++17
Marshall Clowdf4a22d2016-07-08 16:54:47270operator-(const move_iterator<Iterator1>& x,
271 const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
272
273template <class Iterator>
Marshall Clowf333bee2016-11-02 15:30:26274constexpr move_iterator<Iterator> operator+( // constexpr in C++17
275 typename move_iterator<Iterator>::difference_type n,
276 const move_iterator<Iterator>& x);
Marshall Clowdf4a22d2016-07-08 16:54:47277
Marshall Clowf333bee2016-11-02 15:30:26278template <class Iterator> // constexpr in C++17
279constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
Marshall Clowdf4a22d2016-07-08 16:54:47280
281
Howard Hinnantbc8d3f92010-05-11 19:42:16282template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
283class istream_iterator
284 : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
285{
286public:
287 typedef charT char_type;
288 typedef traits traits_type;
289 typedef basic_istream<charT,traits> istream_type;
290
Marshall Clowe9d03062015-04-16 21:36:54291 constexpr istream_iterator();
Howard Hinnantbc8d3f92010-05-11 19:42:16292 istream_iterator(istream_type& s);
293 istream_iterator(const istream_iterator& x);
294 ~istream_iterator();
295
296 const T& operator*() const;
297 const T* operator->() const;
298 istream_iterator& operator++();
299 istream_iterator operator++(int);
300};
301
302template <class T, class charT, class traits, class Distance>
303bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
304 const istream_iterator<T,charT,traits,Distance>& y);
305template <class T, class charT, class traits, class Distance>
306bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
307 const istream_iterator<T,charT,traits,Distance>& y);
308
309template <class T, class charT = char, class traits = char_traits<charT> >
310class ostream_iterator
311 : public iterator<output_iterator_tag, void, void, void ,void>
312{
313public:
314 typedef charT char_type;
315 typedef traits traits_type;
316 typedef basic_ostream<charT,traits> ostream_type;
317
318 ostream_iterator(ostream_type& s);
319 ostream_iterator(ostream_type& s, const charT* delimiter);
320 ostream_iterator(const ostream_iterator& x);
321 ~ostream_iterator();
322 ostream_iterator& operator=(const T& value);
323
324 ostream_iterator& operator*();
325 ostream_iterator& operator++();
326 ostream_iterator& operator++(int);
327};
328
329template<class charT, class traits = char_traits<charT> >
330class istreambuf_iterator
331 : public iterator<input_iterator_tag, charT,
332 typename traits::off_type, unspecified,
333 charT>
334{
335public:
336 typedef charT char_type;
337 typedef traits traits_type;
338 typedef typename traits::int_type int_type;
339 typedef basic_streambuf<charT,traits> streambuf_type;
340 typedef basic_istream<charT,traits> istream_type;
341
Howard Hinnantd06a6402012-07-20 19:36:34342 istreambuf_iterator() noexcept;
343 istreambuf_iterator(istream_type& s) noexcept;
344 istreambuf_iterator(streambuf_type* s) noexcept;
345 istreambuf_iterator(a-private-type) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16346
347 charT operator*() const;
348 pointer operator->() const;
349 istreambuf_iterator& operator++();
350 a-private-type operator++(int);
351
352 bool equal(const istreambuf_iterator& b) const;
353};
354
355template <class charT, class traits>
356bool operator==(const istreambuf_iterator<charT,traits>& a,
357 const istreambuf_iterator<charT,traits>& b);
358template <class charT, class traits>
359bool operator!=(const istreambuf_iterator<charT,traits>& a,
360 const istreambuf_iterator<charT,traits>& b);
361
362template <class charT, class traits = char_traits<charT> >
363class ostreambuf_iterator
364 : public iterator<output_iterator_tag, void, void, void, void>
365{
366public:
367 typedef charT char_type;
368 typedef traits traits_type;
369 typedef basic_streambuf<charT,traits> streambuf_type;
370 typedef basic_ostream<charT,traits> ostream_type;
371
Howard Hinnantd06a6402012-07-20 19:36:34372 ostreambuf_iterator(ostream_type& s) noexcept;
373 ostreambuf_iterator(streambuf_type* s) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16374 ostreambuf_iterator& operator=(charT c);
375 ostreambuf_iterator& operator*();
376 ostreambuf_iterator& operator++();
377 ostreambuf_iterator& operator++(int);
Howard Hinnantd06a6402012-07-20 19:36:34378 bool failed() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16379};
380
Marshall Clowe22af6b2017-01-04 17:58:17381template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
382template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
383template <class C> constexpr auto end(C& c) -> decltype(c.end());
384template <class C> constexpr auto end(const C& c) -> decltype(c.end());
385template <class T, size_t N> constexpr T* begin(T (&array)[N]);
386template <class T, size_t N> constexpr T* end(T (&array)[N]);
Howard Hinnantbc8d3f92010-05-11 19:42:16387
Marshall Clowe22af6b2017-01-04 17:58:17388template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
389template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
390template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
391template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
392template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
393template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
394template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
395template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
396template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
397template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
398template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
399template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
Marshall Clow09da3c02013-08-30 01:17:07400
Marshall Clow03c67912014-11-19 19:43:23401// 24.8, container access:
402template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
403template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
404template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
405template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
406template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
407template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
408template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
409template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
410template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
411
Howard Hinnantbc8d3f92010-05-11 19:42:16412} // std
413
414*/
415
416#include <__config>
Eric Fiselierb3792282016-02-20 00:19:45417#include <iosfwd> // for forward declarations of vector and string.
Marshall Clow02ca8af2014-02-27 02:11:50418#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16419#include <type_traits>
420#include <cstddef>
Marshall Clow09da3c02013-08-30 01:17:07421#include <initializer_list>
Marshall Clowdece7fe2013-03-18 17:45:34422#ifdef __APPLE__
Howard Hinnant537b2fa2012-11-14 21:17:15423#include <Availability.h>
424#endif
425
Eric Fiselierb9536102014-08-10 23:53:08426#include <__debug>
Howard Hinnantbc8d3f92010-05-11 19:42:16427
Howard Hinnant08e17472011-10-17 20:05:10428#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16429#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10430#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16431
432_LIBCPP_BEGIN_NAMESPACE_STD
433
Eric Fiselierc3589a82017-01-04 23:56:00434struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
435struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
436struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
437struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
438struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
Howard Hinnantbc8d3f92010-05-11 19:42:16439
440template <class _Tp>
441struct __has_iterator_category
442{
443private:
Howard Hinnant9c0df142012-10-30 19:06:59444 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16445 template <class _Up> static __two __test(...);
446 template <class _Up> static char __test(typename _Up::iterator_category* = 0);
447public:
448 static const bool value = sizeof(__test<_Tp>(0)) == 1;
449};
450
Marshall Clowa71f9562014-01-03 22:55:49451template <class _Iter, bool> struct __iterator_traits_impl {};
Howard Hinnantbc8d3f92010-05-11 19:42:16452
453template <class _Iter>
Marshall Clowa71f9562014-01-03 22:55:49454struct __iterator_traits_impl<_Iter, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16455{
456 typedef typename _Iter::difference_type difference_type;
457 typedef typename _Iter::value_type value_type;
458 typedef typename _Iter::pointer pointer;
459 typedef typename _Iter::reference reference;
460 typedef typename _Iter::iterator_category iterator_category;
461};
462
463template <class _Iter, bool> struct __iterator_traits {};
464
465template <class _Iter>
466struct __iterator_traits<_Iter, true>
Marshall Clowa71f9562014-01-03 22:55:49467 : __iterator_traits_impl
Howard Hinnantbc8d3f92010-05-11 19:42:16468 <
469 _Iter,
470 is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
471 is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
472 >
473{};
474
475// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
476// exists. Else iterator_traits<Iterator> will be an empty class. This is a
477// conforming extension which allows some programs to compile and behave as
478// the client expects instead of failing at compile time.
479
480template <class _Iter>
Eric Fiselierc3589a82017-01-04 23:56:00481struct _LIBCPP_TEMPLATE_VIS iterator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16482 : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
483
484template<class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00485struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16486{
487 typedef ptrdiff_t difference_type;
488 typedef typename remove_const<_Tp>::type value_type;
489 typedef _Tp* pointer;
490 typedef _Tp& reference;
491 typedef random_access_iterator_tag iterator_category;
492};
493
494template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
495struct __has_iterator_category_convertible_to
496 : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
497{};
498
499template <class _Tp, class _Up>
500struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
501
502template <class _Tp>
503struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
504
505template <class _Tp>
506struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
507
508template <class _Tp>
509struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
510
511template <class _Tp>
512struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
513
Marshall Clowdf9db312016-01-13 21:54:34514template <class _Tp>
515struct __is_exactly_input_iterator
516 : public integral_constant<bool,
Marshall Clowf333bee2016-11-02 15:30:26517 __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
518 !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
Marshall Clowdf9db312016-01-13 21:54:34519
Howard Hinnantbc8d3f92010-05-11 19:42:16520template<class _Category, class _Tp, class _Distance = ptrdiff_t,
521 class _Pointer = _Tp*, class _Reference = _Tp&>
Eric Fiselierc3589a82017-01-04 23:56:00522struct _LIBCPP_TEMPLATE_VIS iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16523{
524 typedef _Tp value_type;
525 typedef _Distance difference_type;
526 typedef _Pointer pointer;
527 typedef _Reference reference;
528 typedef _Category iterator_category;
529};
530
531template <class _InputIter>
532inline _LIBCPP_INLINE_VISIBILITY
533void __advance(_InputIter& __i,
534 typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
535{
536 for (; __n > 0; --__n)
537 ++__i;
538}
539
540template <class _BiDirIter>
541inline _LIBCPP_INLINE_VISIBILITY
542void __advance(_BiDirIter& __i,
543 typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
544{
545 if (__n >= 0)
546 for (; __n > 0; --__n)
547 ++__i;
548 else
549 for (; __n < 0; ++__n)
550 --__i;
551}
552
553template <class _RandIter>
554inline _LIBCPP_INLINE_VISIBILITY
555void __advance(_RandIter& __i,
556 typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
557{
558 __i += __n;
559}
560
561template <class _InputIter>
562inline _LIBCPP_INLINE_VISIBILITY
563void advance(_InputIter& __i,
564 typename iterator_traits<_InputIter>::difference_type __n)
565{
566 __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
567}
568
569template <class _InputIter>
570inline _LIBCPP_INLINE_VISIBILITY
571typename iterator_traits<_InputIter>::difference_type
572__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
573{
574 typename iterator_traits<_InputIter>::difference_type __r(0);
575 for (; __first != __last; ++__first)
576 ++__r;
577 return __r;
578}
579
580template <class _RandIter>
581inline _LIBCPP_INLINE_VISIBILITY
582typename iterator_traits<_RandIter>::difference_type
583__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
584{
585 return __last - __first;
586}
587
588template <class _InputIter>
589inline _LIBCPP_INLINE_VISIBILITY
590typename iterator_traits<_InputIter>::difference_type
591distance(_InputIter __first, _InputIter __last)
592{
593 return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
594}
595
Marshall Clowe9ef9882015-11-07 17:48:49596template <class _InputIter>
Howard Hinnant82894812010-09-22 16:48:34597inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe9ef9882015-11-07 17:48:49598_InputIter
599next(_InputIter __x,
600 typename iterator_traits<_InputIter>::difference_type __n = 1,
601 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0)
Howard Hinnantbc8d3f92010-05-11 19:42:16602{
Howard Hinnant0949eed2011-06-30 21:18:19603 _VSTD::advance(__x, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16604 return __x;
605}
606
607template <class _BidiretionalIter>
Howard Hinnant82894812010-09-22 16:48:34608inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16609_BidiretionalIter
610prev(_BidiretionalIter __x,
611 typename iterator_traits<_BidiretionalIter>::difference_type __n = 1,
612 typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0)
613{
Howard Hinnant0949eed2011-06-30 21:18:19614 _VSTD::advance(__x, -__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16615 return __x;
616}
617
618template <class _Iter>
Eric Fiselierc3589a82017-01-04 23:56:00619class _LIBCPP_TEMPLATE_VIS reverse_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16620 : public iterator<typename iterator_traits<_Iter>::iterator_category,
621 typename iterator_traits<_Iter>::value_type,
622 typename iterator_traits<_Iter>::difference_type,
623 typename iterator_traits<_Iter>::pointer,
624 typename iterator_traits<_Iter>::reference>
625{
Marshall Clow668a1d82014-03-11 22:05:31626private:
Marshall Clow4414a6a2016-10-19 15:12:50627 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
Marshall Clow5a8e27b2014-03-12 01:19:36628protected:
629 _Iter current;
Howard Hinnantbc8d3f92010-05-11 19:42:16630public:
631 typedef _Iter iterator_type;
632 typedef typename iterator_traits<_Iter>::difference_type difference_type;
633 typedef typename iterator_traits<_Iter>::reference reference;
634 typedef typename iterator_traits<_Iter>::pointer pointer;
Howard Hinnant324bb032010-08-22 00:02:43635
Marshall Clow4414a6a2016-10-19 15:12:50636 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
637 reverse_iterator() : __t(), current() {}
638 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
639 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
640 template <class _Up>
641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
642 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
643 template <class _Up>
644 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
645 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
646 { __t = current = __u.base(); return *this; }
647 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
648 _Iter base() const {return current;}
649 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
650 reference operator*() const {_Iter __tmp = current; return *--__tmp;}
651 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
652 pointer operator->() const {return _VSTD::addressof(operator*());}
653 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
654 reverse_iterator& operator++() {--current; return *this;}
655 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
656 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
657 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
658 reverse_iterator& operator--() {++current; return *this;}
659 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
660 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
661 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
662 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
663 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
664 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
665 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
666 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
667 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
668 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
669 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
670 reference operator[](difference_type __n) const {return *(*this + __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16671};
672
673template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50674inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16675bool
676operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
677{
678 return __x.base() == __y.base();
679}
680
681template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50682inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16683bool
684operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
685{
686 return __x.base() > __y.base();
687}
688
689template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50690inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16691bool
692operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
693{
694 return __x.base() != __y.base();
695}
696
697template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50698inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16699bool
700operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
701{
702 return __x.base() < __y.base();
703}
704
705template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50706inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16707bool
708operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
709{
710 return __x.base() <= __y.base();
711}
712
713template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50714inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16715bool
716operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
717{
718 return __x.base() >= __y.base();
719}
720
Marshall Clow3f013892016-07-18 13:19:00721#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:47722template <class _Iter1, class _Iter2>
Marshall Clow4414a6a2016-10-19 15:12:50723inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowdf4a22d2016-07-08 16:54:47724auto
725operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
726-> decltype(__y.base() - __x.base())
727{
728 return __y.base() - __x.base();
729}
730#else
Howard Hinnantbc8d3f92010-05-11 19:42:16731template <class _Iter1, class _Iter2>
732inline _LIBCPP_INLINE_VISIBILITY
733typename reverse_iterator<_Iter1>::difference_type
734operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
735{
736 return __y.base() - __x.base();
737}
Marshall Clowdf4a22d2016-07-08 16:54:47738#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16739
740template <class _Iter>
Marshall Clow4414a6a2016-10-19 15:12:50741inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:16742reverse_iterator<_Iter>
743operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
744{
745 return reverse_iterator<_Iter>(__x.base() - __n);
746}
747
Marshall Clowff137e92014-03-03 01:24:04748#if _LIBCPP_STD_VER > 11
749template <class _Iter>
Marshall Clow4414a6a2016-10-19 15:12:50750inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowff137e92014-03-03 01:24:04751reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
752{
753 return reverse_iterator<_Iter>(__i);
754}
755#endif
756
Howard Hinnantbc8d3f92010-05-11 19:42:16757template <class _Container>
Eric Fiselierc3589a82017-01-04 23:56:00758class _LIBCPP_TEMPLATE_VIS back_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16759 : public iterator<output_iterator_tag,
760 void,
761 void,
762 void,
Eric Fiselierc848cef2016-06-30 04:40:50763 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16764{
765protected:
766 _Container* container;
767public:
768 typedef _Container container_type;
769
Marshall Clow53c0e722014-03-03 19:20:40770 _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45771 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
772 {container->push_back(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19773#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45774 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
775 {container->push_back(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19776#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16777 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
778 _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
779 _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
780};
781
782template <class _Container>
783inline _LIBCPP_INLINE_VISIBILITY
784back_insert_iterator<_Container>
785back_inserter(_Container& __x)
786{
787 return back_insert_iterator<_Container>(__x);
788}
789
790template <class _Container>
Eric Fiselierc3589a82017-01-04 23:56:00791class _LIBCPP_TEMPLATE_VIS front_insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16792 : public iterator<output_iterator_tag,
793 void,
794 void,
795 void,
Eric Fiselierc848cef2016-06-30 04:40:50796 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16797{
798protected:
799 _Container* container;
800public:
801 typedef _Container container_type;
802
Marshall Clow53c0e722014-03-03 19:20:40803 _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
Howard Hinnant78b68282011-10-22 20:59:45804 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
805 {container->push_front(__value_); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19806#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45807 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
808 {container->push_front(_VSTD::move(__value_)); return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19809#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16810 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
811 _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
812 _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
813};
814
815template <class _Container>
816inline _LIBCPP_INLINE_VISIBILITY
817front_insert_iterator<_Container>
818front_inserter(_Container& __x)
819{
820 return front_insert_iterator<_Container>(__x);
821}
822
823template <class _Container>
Eric Fiselierc3589a82017-01-04 23:56:00824class _LIBCPP_TEMPLATE_VIS insert_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16825 : public iterator<output_iterator_tag,
826 void,
827 void,
828 void,
Eric Fiselierc848cef2016-06-30 04:40:50829 void>
Howard Hinnantbc8d3f92010-05-11 19:42:16830{
831protected:
832 _Container* container;
833 typename _Container::iterator iter;
834public:
835 typedef _Container container_type;
836
837 _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
Marshall Clow53c0e722014-03-03 19:20:40838 : container(_VSTD::addressof(__x)), iter(__i) {}
Howard Hinnant78b68282011-10-22 20:59:45839 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
840 {iter = container->insert(iter, __value_); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19841#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant78b68282011-10-22 20:59:45842 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
843 {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
Howard Hinnant73d21a42010-09-04 23:28:19844#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16845 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
846 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
847 _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
848};
849
850template <class _Container>
851inline _LIBCPP_INLINE_VISIBILITY
852insert_iterator<_Container>
853inserter(_Container& __x, typename _Container::iterator __i)
854{
855 return insert_iterator<_Container>(__x, __i);
856}
857
858template <class _Tp, class _CharT = char,
859 class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Eric Fiselierc3589a82017-01-04 23:56:00860class _LIBCPP_TEMPLATE_VIS istream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16861 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
862{
863public:
864 typedef _CharT char_type;
865 typedef _Traits traits_type;
866 typedef basic_istream<_CharT,_Traits> istream_type;
867private:
868 istream_type* __in_stream_;
869 _Tp __value_;
870public:
Marshall Clowe9d03062015-04-16 21:36:54871 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
Marshall Clowd8fc1ec2016-05-17 17:44:40872 _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
Howard Hinnantbc8d3f92010-05-11 19:42:16873 {
874 if (!(*__in_stream_ >> __value_))
875 __in_stream_ = 0;
876 }
877
878 _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
Marshall Clowd8fc1ec2016-05-17 17:44:40879 _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
Howard Hinnantbc8d3f92010-05-11 19:42:16880 _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
881 {
882 if (!(*__in_stream_ >> __value_))
883 __in_stream_ = 0;
884 return *this;
885 }
886 _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
887 {istream_iterator __t(*this); ++(*this); return __t;}
888
889 friend _LIBCPP_INLINE_VISIBILITY
890 bool operator==(const istream_iterator& __x, const istream_iterator& __y)
891 {return __x.__in_stream_ == __y.__in_stream_;}
892
893 friend _LIBCPP_INLINE_VISIBILITY
894 bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
895 {return !(__x == __y);}
896};
897
898template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
Eric Fiselierc3589a82017-01-04 23:56:00899class _LIBCPP_TEMPLATE_VIS ostream_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16900 : public iterator<output_iterator_tag, void, void, void, void>
901{
902public:
903 typedef _CharT char_type;
904 typedef _Traits traits_type;
905 typedef basic_ostream<_CharT,_Traits> ostream_type;
906private:
907 ostream_type* __out_stream_;
908 const char_type* __delim_;
909public:
Marshall Clowb6361282016-10-12 16:13:48910 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
Marshall Clowd8fc1ec2016-05-17 17:44:40911 : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
Marshall Clowb6361282016-10-12 16:13:48912 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
Marshall Clowd8fc1ec2016-05-17 17:44:40913 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
Howard Hinnant78b68282011-10-22 20:59:45914 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16915 {
Howard Hinnant78b68282011-10-22 20:59:45916 *__out_stream_ << __value_;
Howard Hinnantbc8d3f92010-05-11 19:42:16917 if (__delim_)
918 *__out_stream_ << __delim_;
919 return *this;
920 }
921
922 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
923 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
924 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
925};
926
927template<class _CharT, class _Traits>
Eric Fiselierc3589a82017-01-04 23:56:00928class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16929 : public iterator<input_iterator_tag, _CharT,
930 typename _Traits::off_type, _CharT*,
931 _CharT>
932{
933public:
934 typedef _CharT char_type;
935 typedef _Traits traits_type;
936 typedef typename _Traits::int_type int_type;
937 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
938 typedef basic_istream<_CharT,_Traits> istream_type;
939private:
Howard Hinnant984f10f2012-11-16 22:17:23940 mutable streambuf_type* __sbuf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16941
942 class __proxy
943 {
944 char_type __keep_;
945 streambuf_type* __sbuf_;
946 _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
947 : __keep_(__c), __sbuf_(__s) {}
948 friend class istreambuf_iterator;
949 public:
950 _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
951 };
952
Howard Hinnant82894812010-09-22 16:48:34953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant984f10f2012-11-16 22:17:23954 bool __test_for_eof() const
Howard Hinnantbc8d3f92010-05-11 19:42:16955 {
956 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
957 __sbuf_ = 0;
Howard Hinnant984f10f2012-11-16 22:17:23958 return __sbuf_ == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16959 }
960public:
Howard Hinnant984f10f2012-11-16 22:17:23961 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
Howard Hinnantd06a6402012-07-20 19:36:34962 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42963 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:34964 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantd1a74792012-12-29 17:45:42965 : __sbuf_(__s) {}
Howard Hinnantd06a6402012-07-20 19:36:34966 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16967 : __sbuf_(__p.__sbuf_) {}
968
Howard Hinnantec3773c2011-12-01 20:21:04969 _LIBCPP_INLINE_VISIBILITY char_type operator*() const
970 {return static_cast<char_type>(__sbuf_->sgetc());}
Howard Hinnantbc8d3f92010-05-11 19:42:16971 _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;}
972 _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
973 {
Howard Hinnant984f10f2012-11-16 22:17:23974 __sbuf_->sbumpc();
Howard Hinnantbc8d3f92010-05-11 19:42:16975 return *this;
976 }
977 _LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
978 {
Howard Hinnant984f10f2012-11-16 22:17:23979 return __proxy(__sbuf_->sbumpc(), __sbuf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16980 }
981
982 _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
Howard Hinnant984f10f2012-11-16 22:17:23983 {return __test_for_eof() == __b.__test_for_eof();}
Howard Hinnantbc8d3f92010-05-11 19:42:16984};
985
986template <class _CharT, class _Traits>
987inline _LIBCPP_INLINE_VISIBILITY
988bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
989 const istreambuf_iterator<_CharT,_Traits>& __b)
990 {return __a.equal(__b);}
991
992template <class _CharT, class _Traits>
993inline _LIBCPP_INLINE_VISIBILITY
994bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
995 const istreambuf_iterator<_CharT,_Traits>& __b)
996 {return !__a.equal(__b);}
997
998template <class _CharT, class _Traits>
Eric Fiselierc3589a82017-01-04 23:56:00999class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:161000 : public iterator<output_iterator_tag, void, void, void, void>
1001{
1002public:
1003 typedef _CharT char_type;
1004 typedef _Traits traits_type;
1005 typedef basic_streambuf<_CharT,_Traits> streambuf_type;
1006 typedef basic_ostream<_CharT,_Traits> ostream_type;
1007private:
1008 streambuf_type* __sbuf_;
1009public:
Howard Hinnantd06a6402012-07-20 19:36:341010 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161011 : __sbuf_(__s.rdbuf()) {}
Howard Hinnantd06a6402012-07-20 19:36:341012 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161013 : __sbuf_(__s) {}
1014 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
1015 {
1016 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1017 __sbuf_ = 0;
1018 return *this;
1019 }
1020 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
1021 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
1022 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
Howard Hinnantd06a6402012-07-20 19:36:341023 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
Howard Hinnanta585de62012-09-19 19:14:151024
Howard Hinnant537b2fa2012-11-14 21:17:151025#if !defined(__APPLE__) || \
1026 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1027 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1028
Howard Hinnanta585de62012-09-19 19:14:151029 template <class _Ch, class _Tr>
1030 friend
1031 _LIBCPP_HIDDEN
1032 ostreambuf_iterator<_Ch, _Tr>
1033 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
1034 const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
1035 ios_base& __iob, _Ch __fl);
Howard Hinnant537b2fa2012-11-14 21:17:151036#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161037};
1038
1039template <class _Iter>
Eric Fiselierc3589a82017-01-04 23:56:001040class _LIBCPP_TEMPLATE_VIS move_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:161041{
1042private:
1043 _Iter __i;
1044public:
1045 typedef _Iter iterator_type;
1046 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1047 typedef typename iterator_traits<iterator_type>::value_type value_type;
1048 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
Marshall Clowdca800c2016-04-11 03:54:531049 typedef iterator_type pointer;
Howard Hinnant73d21a42010-09-04 23:28:191050#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Eric Fiselierdf46b782016-04-22 00:49:121051 typedef typename iterator_traits<iterator_type>::reference __reference;
1052 typedef typename conditional<
1053 is_reference<__reference>::value,
1054 typename remove_reference<__reference>::type&&,
1055 __reference
1056 >::type reference;
Howard Hinnantbc8d3f92010-05-11 19:42:161057#else
1058 typedef typename iterator_traits<iterator_type>::reference reference;
1059#endif
Howard Hinnant324bb032010-08-22 00:02:431060
Marshall Clowf333bee2016-11-02 15:30:261061 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1062 move_iterator() : __i() {}
1063 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1064 explicit move_iterator(_Iter __x) : __i(__x) {}
1065 template <class _Up>
1066 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1067 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1068 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1069 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1070 reference operator*() const { return static_cast<reference>(*__i); }
1071 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1072 pointer operator->() const { return __i;}
1073 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1074 move_iterator& operator++() {++__i; return *this;}
1075 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1076 move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1077 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1078 move_iterator& operator--() {--__i; return *this;}
1079 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1080 move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1081 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1082 move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1083 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1084 move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1085 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1086 move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
1087 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1088 move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1089 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1090 reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
Howard Hinnantbc8d3f92010-05-11 19:42:161091};
1092
1093template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261094inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161095bool
1096operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1097{
1098 return __x.base() == __y.base();
1099}
1100
1101template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261102inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161103bool
1104operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1105{
1106 return __x.base() < __y.base();
1107}
1108
1109template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261110inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161111bool
1112operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1113{
1114 return __x.base() != __y.base();
1115}
1116
1117template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261118inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161119bool
1120operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1121{
1122 return __x.base() > __y.base();
1123}
1124
1125template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261126inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161127bool
1128operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1129{
1130 return __x.base() >= __y.base();
1131}
1132
1133template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261134inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161135bool
1136operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1137{
1138 return __x.base() <= __y.base();
1139}
1140
Marshall Clow3f013892016-07-18 13:19:001141#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:471142template <class _Iter1, class _Iter2>
Marshall Clowf333bee2016-11-02 15:30:261143inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clowdf4a22d2016-07-08 16:54:471144auto
1145operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1146-> decltype(__x.base() - __y.base())
1147{
1148 return __x.base() - __y.base();
1149}
1150#else
Howard Hinnantbc8d3f92010-05-11 19:42:161151template <class _Iter1, class _Iter2>
1152inline _LIBCPP_INLINE_VISIBILITY
1153typename move_iterator<_Iter1>::difference_type
1154operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1155{
1156 return __x.base() - __y.base();
1157}
Marshall Clowdf4a22d2016-07-08 16:54:471158#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161159
1160template <class _Iter>
Marshall Clowf333bee2016-11-02 15:30:261161inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161162move_iterator<_Iter>
1163operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
1164{
1165 return move_iterator<_Iter>(__x.base() + __n);
1166}
1167
1168template <class _Iter>
Marshall Clowf333bee2016-11-02 15:30:261169inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161170move_iterator<_Iter>
Marshall Clowaf746512013-08-27 13:03:031171make_move_iterator(_Iter __i)
Howard Hinnantbc8d3f92010-05-11 19:42:161172{
1173 return move_iterator<_Iter>(__i);
1174}
1175
1176// __wrap_iter
1177
1178template <class _Iter> class __wrap_iter;
1179
1180template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161181_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161182bool
Eric Fiselier2c8aa052016-12-28 05:35:321183operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161184
1185template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161186_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161187bool
Eric Fiselier2c8aa052016-12-28 05:35:321188operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161189
1190template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161191_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161192bool
Eric Fiselier2c8aa052016-12-28 05:35:321193operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161194
1195template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161196_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161197bool
Eric Fiselier2c8aa052016-12-28 05:35:321198operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161199
1200template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161201_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161202bool
Eric Fiselier2c8aa052016-12-28 05:35:321203operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161204
1205template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161206_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161207bool
Eric Fiselier2c8aa052016-12-28 05:35:321208operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161209
Marshall Clow3f013892016-07-18 13:19:001210#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:471211template <class _Iter1, class _Iter2>
1212_LIBCPP_INLINE_VISIBILITY
1213auto
Eric Fiselier2c8aa052016-12-28 05:35:321214operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Marshall Clowdf4a22d2016-07-08 16:54:471215-> decltype(__x.base() - __y.base());
1216#else
Howard Hinnantbc8d3f92010-05-11 19:42:161217template <class _Iter1, class _Iter2>
Howard Hinnant33be35e2012-09-14 00:39:161218_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161219typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier2c8aa052016-12-28 05:35:321220operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Marshall Clowdf4a22d2016-07-08 16:54:471221#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161222
1223template <class _Iter>
Howard Hinnant33be35e2012-09-14 00:39:161224_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161225__wrap_iter<_Iter>
Eric Fiselier2c8aa052016-12-28 05:35:321226operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161227
Howard Hinnant33be35e2012-09-14 00:39:161228template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1229template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1230template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1231template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
Howard Hinnantbc8d3f92010-05-11 19:42:161232
Eric Fiselier2c8aa052016-12-28 05:35:321233#if _LIBCPP_DEBUG_LEVEL < 2
1234
Howard Hinnantbc8d3f92010-05-11 19:42:161235template <class _Tp>
Howard Hinnant33be35e2012-09-14 00:39:161236_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161237typename enable_if
1238<
Howard Hinnant1468b662010-11-19 22:17:281239 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161240 _Tp*
1241>::type
1242__unwrap_iter(__wrap_iter<_Tp*>);
1243
Eric Fiselier2c8aa052016-12-28 05:35:321244#else
1245
1246template <class _Tp>
1247inline _LIBCPP_INLINE_VISIBILITY
1248typename enable_if
1249<
1250 is_trivially_copy_assignable<_Tp>::value,
1251 __wrap_iter<_Tp*>
1252>::type
1253__unwrap_iter(__wrap_iter<_Tp*> __i);
1254
1255#endif
1256
Howard Hinnantbc8d3f92010-05-11 19:42:161257template <class _Iter>
1258class __wrap_iter
1259{
1260public:
1261 typedef _Iter iterator_type;
1262 typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1263 typedef typename iterator_traits<iterator_type>::value_type value_type;
1264 typedef typename iterator_traits<iterator_type>::difference_type difference_type;
1265 typedef typename iterator_traits<iterator_type>::pointer pointer;
1266 typedef typename iterator_traits<iterator_type>::reference reference;
1267private:
1268 iterator_type __i;
1269public:
Eric Fiselier2c8aa052016-12-28 05:35:321270 _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT_DEBUG
Marshall Clow0f164c92013-08-07 20:48:481271#if _LIBCPP_STD_VER > 11
1272 : __i{}
1273#endif
Howard Hinnant7608b4a2011-09-16 19:52:231274 {
1275#if _LIBCPP_DEBUG_LEVEL >= 2
1276 __get_db()->__insert_i(this);
1277#endif
1278 }
Howard Hinnantbc8d3f92010-05-11 19:42:161279 template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
Eric Fiselier2c8aa052016-12-28 05:35:321280 typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511281 : __i(__u.base())
1282 {
Howard Hinnantabe26282011-09-16 17:29:171283#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511284 __get_db()->__iterator_copy(this, &__u);
1285#endif
1286 }
Howard Hinnantabe26282011-09-16 17:29:171287#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511288 _LIBCPP_INLINE_VISIBILITY
1289 __wrap_iter(const __wrap_iter& __x)
1290 : __i(__x.base())
1291 {
1292 __get_db()->__iterator_copy(this, &__x);
1293 }
1294 _LIBCPP_INLINE_VISIBILITY
1295 __wrap_iter& operator=(const __wrap_iter& __x)
1296 {
1297 if (this != &__x)
1298 {
1299 __get_db()->__iterator_copy(this, &__x);
1300 __i = __x.__i;
1301 }
1302 return *this;
1303 }
1304 _LIBCPP_INLINE_VISIBILITY
1305 ~__wrap_iter()
1306 {
1307 __get_db()->__erase_i(this);
1308 }
1309#endif
Eric Fiselier2c8aa052016-12-28 05:35:321310 _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511311 {
Howard Hinnantabe26282011-09-16 17:29:171312#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511313 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1314 "Attempted to dereference a non-dereferenceable iterator");
Howard Hinnantabe26282011-09-16 17:29:171315#endif
Howard Hinnant7a563db2011-09-14 18:33:511316 return *__i;
1317 }
Eric Fiselier2c8aa052016-12-28 05:35:321318 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT_DEBUG
Howard Hinnant2c39cbe2013-06-27 19:35:321319 {
1320#if _LIBCPP_DEBUG_LEVEL >= 2
1321 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1322 "Attempted to dereference a non-dereferenceable iterator");
1323#endif
Marshall Clowdca800c2016-04-11 03:54:531324 return (pointer)_VSTD::addressof(*__i);
Howard Hinnant2c39cbe2013-06-27 19:35:321325 }
Eric Fiselier2c8aa052016-12-28 05:35:321326 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511327 {
Howard Hinnantabe26282011-09-16 17:29:171328#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511329 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1330 "Attempted to increment non-incrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:171331#endif
Howard Hinnant7a563db2011-09-14 18:33:511332 ++__i;
1333 return *this;
1334 }
Eric Fiselier2c8aa052016-12-28 05:35:321335 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511336 {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
Eric Fiselier2c8aa052016-12-28 05:35:321337 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511338 {
Howard Hinnantabe26282011-09-16 17:29:171339#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511340 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1341 "Attempted to decrement non-decrementable iterator");
Howard Hinnantabe26282011-09-16 17:29:171342#endif
Howard Hinnant7a563db2011-09-14 18:33:511343 --__i;
1344 return *this;
1345 }
Eric Fiselier2c8aa052016-12-28 05:35:321346 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511347 {__wrap_iter __tmp(*this); --(*this); return __tmp;}
Eric Fiselier2c8aa052016-12-28 05:35:321348 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511349 {__wrap_iter __w(*this); __w += __n; return __w;}
Eric Fiselier2c8aa052016-12-28 05:35:321350 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511351 {
Howard Hinnantabe26282011-09-16 17:29:171352#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511353 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1354 "Attempted to add/subtract iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:171355#endif
Howard Hinnant7a563db2011-09-14 18:33:511356 __i += __n;
1357 return *this;
1358 }
Eric Fiselier2c8aa052016-12-28 05:35:321359 _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511360 {return *this + (-__n);}
Eric Fiselier2c8aa052016-12-28 05:35:321361 _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511362 {*this += -__n; return *this;}
Eric Fiselier2c8aa052016-12-28 05:35:321363 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT_DEBUG
Howard Hinnant7a563db2011-09-14 18:33:511364 {
Howard Hinnantabe26282011-09-16 17:29:171365#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511366 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1367 "Attempted to subscript iterator outside of valid range");
Howard Hinnantabe26282011-09-16 17:29:171368#endif
Howard Hinnant7a563db2011-09-14 18:33:511369 return __i[__n];
1370 }
Howard Hinnantbc8d3f92010-05-11 19:42:161371
Eric Fiselier2c8aa052016-12-28 05:35:321372 _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT_DEBUG {return __i;}
Howard Hinnantbc8d3f92010-05-11 19:42:161373
1374private:
Howard Hinnantabe26282011-09-16 17:29:171375#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511376 _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1377 {
1378 __get_db()->__insert_ic(this, __p);
1379 }
Howard Hinnant499cea12013-08-23 17:37:051380#else
Eric Fiselier2c8aa052016-12-28 05:35:321381 _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {}
Howard Hinnant7a563db2011-09-14 18:33:511382#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161383
1384 template <class _Up> friend class __wrap_iter;
1385 template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
Eric Fiselierc3589a82017-01-04 23:56:001386 template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
Howard Hinnantbc8d3f92010-05-11 19:42:161387
1388 template <class _Iter1, class _Iter2>
1389 friend
1390 bool
Eric Fiselier2c8aa052016-12-28 05:35:321391 operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431392
Howard Hinnantbc8d3f92010-05-11 19:42:161393 template <class _Iter1, class _Iter2>
1394 friend
1395 bool
Eric Fiselier2c8aa052016-12-28 05:35:321396 operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431397
Howard Hinnantbc8d3f92010-05-11 19:42:161398 template <class _Iter1, class _Iter2>
1399 friend
1400 bool
Eric Fiselier2c8aa052016-12-28 05:35:321401 operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431402
Howard Hinnantbc8d3f92010-05-11 19:42:161403 template <class _Iter1, class _Iter2>
1404 friend
1405 bool
Eric Fiselier2c8aa052016-12-28 05:35:321406 operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431407
Howard Hinnantbc8d3f92010-05-11 19:42:161408 template <class _Iter1, class _Iter2>
1409 friend
1410 bool
Eric Fiselier2c8aa052016-12-28 05:35:321411 operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431412
Howard Hinnantbc8d3f92010-05-11 19:42:161413 template <class _Iter1, class _Iter2>
1414 friend
1415 bool
Eric Fiselier2c8aa052016-12-28 05:35:321416 operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Howard Hinnant324bb032010-08-22 00:02:431417
Marshall Clow3f013892016-07-18 13:19:001418#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:471419 template <class _Iter1, class _Iter2>
1420 friend
1421 auto
Eric Fiselier2c8aa052016-12-28 05:35:321422 operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Marshall Clowdf4a22d2016-07-08 16:54:471423 -> decltype(__x.base() - __y.base());
1424#else
Howard Hinnantbc8d3f92010-05-11 19:42:161425 template <class _Iter1, class _Iter2>
1426 friend
1427 typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier2c8aa052016-12-28 05:35:321428 operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
Marshall Clowdf4a22d2016-07-08 16:54:471429#endif
Howard Hinnant324bb032010-08-22 00:02:431430
Howard Hinnantbc8d3f92010-05-11 19:42:161431 template <class _Iter1>
1432 friend
1433 __wrap_iter<_Iter1>
Eric Fiselier2c8aa052016-12-28 05:35:321434 operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG;
Howard Hinnantbc8d3f92010-05-11 19:42:161435
Howard Hinnant99968442011-11-29 18:15:501436 template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:161437 template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
Howard Hinnant99968442011-11-29 18:15:501438 template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
Howard Hinnantbc8d3f92010-05-11 19:42:161439 template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
1440
Eric Fiselier2c8aa052016-12-28 05:35:321441#if _LIBCPP_DEBUG_LEVEL < 2
Howard Hinnantbc8d3f92010-05-11 19:42:161442 template <class _Tp>
1443 friend
1444 typename enable_if
1445 <
Howard Hinnant1468b662010-11-19 22:17:281446 is_trivially_copy_assignable<_Tp>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161447 _Tp*
1448 >::type
1449 __unwrap_iter(__wrap_iter<_Tp*>);
Eric Fiselier2c8aa052016-12-28 05:35:321450#else
1451 template <class _Tp>
1452 inline _LIBCPP_INLINE_VISIBILITY
1453 typename enable_if
1454 <
1455 is_trivially_copy_assignable<_Tp>::value,
1456 __wrap_iter<_Tp*>
1457 >::type
1458 __unwrap_iter(__wrap_iter<_Tp*> __i);
1459#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161460};
1461
1462template <class _Iter1, class _Iter2>
1463inline _LIBCPP_INLINE_VISIBILITY
1464bool
Eric Fiselier2c8aa052016-12-28 05:35:321465operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161466{
1467 return __x.base() == __y.base();
1468}
1469
1470template <class _Iter1, class _Iter2>
1471inline _LIBCPP_INLINE_VISIBILITY
1472bool
Eric Fiselier2c8aa052016-12-28 05:35:321473operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161474{
Howard Hinnantabe26282011-09-16 17:29:171475#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:351476 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:511477 "Attempted to compare incomparable iterators");
Howard Hinnantabe26282011-09-16 17:29:171478#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161479 return __x.base() < __y.base();
1480}
1481
1482template <class _Iter1, class _Iter2>
1483inline _LIBCPP_INLINE_VISIBILITY
1484bool
Eric Fiselier2c8aa052016-12-28 05:35:321485operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161486{
Howard Hinnant7a563db2011-09-14 18:33:511487 return !(__x == __y);
Howard Hinnantbc8d3f92010-05-11 19:42:161488}
1489
1490template <class _Iter1, class _Iter2>
1491inline _LIBCPP_INLINE_VISIBILITY
1492bool
Eric Fiselier2c8aa052016-12-28 05:35:321493operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161494{
Howard Hinnant7a563db2011-09-14 18:33:511495 return __y < __x;
Howard Hinnantbc8d3f92010-05-11 19:42:161496}
1497
1498template <class _Iter1, class _Iter2>
1499inline _LIBCPP_INLINE_VISIBILITY
1500bool
Eric Fiselier2c8aa052016-12-28 05:35:321501operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161502{
Howard Hinnant7a563db2011-09-14 18:33:511503 return !(__x < __y);
Howard Hinnantbc8d3f92010-05-11 19:42:161504}
1505
1506template <class _Iter1, class _Iter2>
1507inline _LIBCPP_INLINE_VISIBILITY
1508bool
Eric Fiselier2c8aa052016-12-28 05:35:321509operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161510{
Howard Hinnant7a563db2011-09-14 18:33:511511 return !(__y < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161512}
1513
Howard Hinnant95c0e9f2012-10-02 19:45:421514template <class _Iter1>
1515inline _LIBCPP_INLINE_VISIBILITY
1516bool
Eric Fiselier2c8aa052016-12-28 05:35:321517operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:421518{
1519 return !(__x == __y);
1520}
1521
1522template <class _Iter1>
1523inline _LIBCPP_INLINE_VISIBILITY
1524bool
Eric Fiselier2c8aa052016-12-28 05:35:321525operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:421526{
1527 return __y < __x;
1528}
1529
1530template <class _Iter1>
1531inline _LIBCPP_INLINE_VISIBILITY
1532bool
Eric Fiselier2c8aa052016-12-28 05:35:321533operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:421534{
1535 return !(__x < __y);
1536}
1537
1538template <class _Iter1>
1539inline _LIBCPP_INLINE_VISIBILITY
1540bool
Eric Fiselier2c8aa052016-12-28 05:35:321541operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
Howard Hinnant95c0e9f2012-10-02 19:45:421542{
1543 return !(__y < __x);
1544}
1545
Marshall Clow3f013892016-07-18 13:19:001546#ifndef _LIBCPP_CXX03_LANG
Marshall Clowdf4a22d2016-07-08 16:54:471547template <class _Iter1, class _Iter2>
1548inline _LIBCPP_INLINE_VISIBILITY
1549auto
Eric Fiselier2c8aa052016-12-28 05:35:321550operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Marshall Clowdf4a22d2016-07-08 16:54:471551-> decltype(__x.base() - __y.base())
1552{
1553#if _LIBCPP_DEBUG_LEVEL >= 2
1554 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1555 "Attempted to subtract incompatible iterators");
1556#endif
1557 return __x.base() - __y.base();
1558}
1559#else
Howard Hinnantbc8d3f92010-05-11 19:42:161560template <class _Iter1, class _Iter2>
1561inline _LIBCPP_INLINE_VISIBILITY
1562typename __wrap_iter<_Iter1>::difference_type
Eric Fiselier2c8aa052016-12-28 05:35:321563operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161564{
Howard Hinnantabe26282011-09-16 17:29:171565#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant8b00e6c2013-08-02 00:26:351566 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
Howard Hinnant7a563db2011-09-14 18:33:511567 "Attempted to subtract incompatible iterators");
Howard Hinnantabe26282011-09-16 17:29:171568#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161569 return __x.base() - __y.base();
1570}
Marshall Clowdf4a22d2016-07-08 16:54:471571#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161572
1573template <class _Iter>
1574inline _LIBCPP_INLINE_VISIBILITY
1575__wrap_iter<_Iter>
1576operator+(typename __wrap_iter<_Iter>::difference_type __n,
Eric Fiselier2c8aa052016-12-28 05:35:321577 __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:161578{
Howard Hinnant7a563db2011-09-14 18:33:511579 __x += __n;
1580 return __x;
Howard Hinnantbc8d3f92010-05-11 19:42:161581}
1582
Marshall Clowdf9db312016-01-13 21:54:341583template <class _Iter>
1584struct __libcpp_is_trivial_iterator
Marshall Clowf333bee2016-11-02 15:30:261585 : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
1586
Marshall Clowdf9db312016-01-13 21:54:341587template <class _Iter>
1588struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
Marshall Clowf333bee2016-11-02 15:30:261589 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clowdf9db312016-01-13 21:54:341590
1591template <class _Iter>
1592struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
Marshall Clowf333bee2016-11-02 15:30:261593 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clowdf9db312016-01-13 21:54:341594
1595template <class _Iter>
1596struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
Marshall Clowf333bee2016-11-02 15:30:261597 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
Marshall Clowdf9db312016-01-13 21:54:341598
1599
Marshall Clow6daf5342013-12-02 03:24:331600template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:301601inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:331602_Tp*
1603begin(_Tp (&__array)[_Np])
1604{
1605 return __array;
1606}
1607
1608template <class _Tp, size_t _Np>
Marshall Clow9dacb2f2014-02-19 17:53:301609inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow6daf5342013-12-02 03:24:331610_Tp*
1611end(_Tp (&__array)[_Np])
1612{
1613 return __array + _Np;
1614}
1615
Eric Fiselier4e3e15a2016-09-25 03:34:281616#if !defined(_LIBCPP_CXX03_LANG)
Marshall Clow1c398692013-12-11 19:32:321617
Howard Hinnant99968442011-11-29 18:15:501618template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171619inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161620auto
Howard Hinnant99968442011-11-29 18:15:501621begin(_Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:161622{
1623 return __c.begin();
1624}
1625
Howard Hinnant99968442011-11-29 18:15:501626template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171627inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161628auto
Howard Hinnant99968442011-11-29 18:15:501629begin(const _Cp& __c) -> decltype(__c.begin())
Howard Hinnantbc8d3f92010-05-11 19:42:161630{
1631 return __c.begin();
1632}
1633
Howard Hinnant99968442011-11-29 18:15:501634template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171635inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161636auto
Howard Hinnant99968442011-11-29 18:15:501637end(_Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:161638{
1639 return __c.end();
1640}
1641
Howard Hinnant99968442011-11-29 18:15:501642template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171643inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Howard Hinnantbc8d3f92010-05-11 19:42:161644auto
Howard Hinnant99968442011-11-29 18:15:501645end(const _Cp& __c) -> decltype(__c.end())
Howard Hinnantbc8d3f92010-05-11 19:42:161646{
1647 return __c.end();
1648}
1649
Marshall Clow09da3c02013-08-30 01:17:071650#if _LIBCPP_STD_VER > 11
1651
Marshall Clow6daf5342013-12-02 03:24:331652template <class _Tp, size_t _Np>
Marshall Clowe22af6b2017-01-04 17:58:171653inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:331654reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
1655{
1656 return reverse_iterator<_Tp*>(__array + _Np);
1657}
1658
1659template <class _Tp, size_t _Np>
Marshall Clowe22af6b2017-01-04 17:58:171660inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:331661reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
1662{
1663 return reverse_iterator<_Tp*>(__array);
1664}
1665
1666template <class _Ep>
Marshall Clowe22af6b2017-01-04 17:58:171667inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:331668reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
1669{
1670 return reverse_iterator<const _Ep*>(__il.end());
1671}
1672
1673template <class _Ep>
Marshall Clowe22af6b2017-01-04 17:58:171674inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow6daf5342013-12-02 03:24:331675reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
1676{
1677 return reverse_iterator<const _Ep*>(__il.begin());
1678}
1679
Marshall Clow09da3c02013-08-30 01:17:071680template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:301681inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow02e94f82016-08-10 20:04:461682auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
Marshall Clow09da3c02013-08-30 01:17:071683{
Marshall Clow02e94f82016-08-10 20:04:461684 return _VSTD::begin(__c);
Marshall Clow09da3c02013-08-30 01:17:071685}
1686
1687template <class _Cp>
Marshall Clow9dacb2f2014-02-19 17:53:301688inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clow02e94f82016-08-10 20:04:461689auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
Marshall Clow09da3c02013-08-30 01:17:071690{
Marshall Clow02e94f82016-08-10 20:04:461691 return _VSTD::end(__c);
Marshall Clow09da3c02013-08-30 01:17:071692}
1693
1694template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171695inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:071696auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
1697{
1698 return __c.rbegin();
1699}
1700
1701template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171702inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:071703auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
1704{
1705 return __c.rbegin();
1706}
1707
1708template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171709inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:071710auto rend(_Cp& __c) -> decltype(__c.rend())
1711{
1712 return __c.rend();
1713}
1714
1715template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171716inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow09da3c02013-08-30 01:17:071717auto rend(const _Cp& __c) -> decltype(__c.rend())
1718{
1719 return __c.rend();
1720}
1721
1722template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171723inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow02e94f82016-08-10 20:04:461724auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
Marshall Clow09da3c02013-08-30 01:17:071725{
Marshall Clow02e94f82016-08-10 20:04:461726 return _VSTD::rbegin(__c);
Marshall Clow09da3c02013-08-30 01:17:071727}
1728
1729template <class _Cp>
Marshall Clowe22af6b2017-01-04 17:58:171730inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
Marshall Clow02e94f82016-08-10 20:04:461731auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
Marshall Clow09da3c02013-08-30 01:17:071732{
Marshall Clow02e94f82016-08-10 20:04:461733 return _VSTD::rend(__c);
Marshall Clow09da3c02013-08-30 01:17:071734}
1735
1736#endif
1737
1738
Eric Fiselier4e3e15a2016-09-25 03:34:281739#else // defined(_LIBCPP_CXX03_LANG)
Howard Hinnantbc8d3f92010-05-11 19:42:161740
Howard Hinnant99968442011-11-29 18:15:501741template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:341742inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501743typename _Cp::iterator
1744begin(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:161745{
1746 return __c.begin();
1747}
1748
Howard Hinnant99968442011-11-29 18:15:501749template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:341750inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501751typename _Cp::const_iterator
1752begin(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:161753{
1754 return __c.begin();
1755}
1756
Howard Hinnant99968442011-11-29 18:15:501757template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:341758inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501759typename _Cp::iterator
1760end(_Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:161761{
1762 return __c.end();
1763}
1764
Howard Hinnant99968442011-11-29 18:15:501765template <class _Cp>
Howard Hinnant82894812010-09-22 16:48:341766inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501767typename _Cp::const_iterator
1768end(const _Cp& __c)
Howard Hinnantbc8d3f92010-05-11 19:42:161769{
1770 return __c.end();
1771}
1772
Eric Fiselier4e3e15a2016-09-25 03:34:281773#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantbc8d3f92010-05-11 19:42:161774
Marshall Clow03c67912014-11-19 19:43:231775#if _LIBCPP_STD_VER > 14
Marshall Clow35e462d2015-02-11 16:14:011776template <class _Cont>
1777constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); }
Marshall Clow03c67912014-11-19 19:43:231778
Marshall Clow35e462d2015-02-11 16:14:011779template <class _Tp, size_t _Sz>
Eric Fiselier0e5ebbc2016-12-23 23:37:521780constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
Marshall Clow03c67912014-11-19 19:43:231781
Marshall Clow35e462d2015-02-11 16:14:011782template <class _Cont>
1783constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); }
Marshall Clow03c67912014-11-19 19:43:231784
Marshall Clow35e462d2015-02-11 16:14:011785template <class _Tp, size_t _Sz>
Eric Fiselier0e5ebbc2016-12-23 23:37:521786constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
Marshall Clow03c67912014-11-19 19:43:231787
1788template <class _Ep>
1789constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1790
Marshall Clow35e462d2015-02-11 16:14:011791template <class _Cont> constexpr
1792auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:231793
Marshall Clow35e462d2015-02-11 16:14:011794template <class _Cont> constexpr
1795auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); }
Marshall Clow03c67912014-11-19 19:43:231796
Marshall Clow35e462d2015-02-11 16:14:011797template <class _Tp, size_t _Sz>
1798constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
Marshall Clow03c67912014-11-19 19:43:231799
1800template <class _Ep>
1801constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1802#endif
1803
1804
Howard Hinnantbc8d3f92010-05-11 19:42:161805_LIBCPP_END_NAMESPACE_STD
1806
1807#endif // _LIBCPP_ITERATOR