llvm-project
744 строки · 31.4 Кб
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ITERATOR
11#define _LIBCPP_ITERATOR
12
13/*
14iterator synopsis
15
16#include <concepts>
17
18namespace std
19{
20template<class> struct incrementable_traits; // since C++20
21template<class T>
22using iter_difference_t = see below; // since C++20
23
24template<class> struct indirectly_readable_traits; // since C++20
25template<class T>
26using iter_value_t = see below; // since C++20
27
28template<class Iterator>
29struct iterator_traits;
30
31template<class T>
32requires is_object_v<T> // since C++20
33struct iterator_traits<T*>;
34
35template<dereferenceable T>
36using iter_reference_t = decltype(*declval<T&>());
37
38namespace ranges::inline unspecified {
39inline constexpr unspecified iter_move = unspecified; // since C++20, nodiscard as an extension
40}}
41
42template<dereferenceable T>
43requires ...
44using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // since C++20
45
46// [iterator.concepts], iterator concepts
47// [iterator.concept.readable], concept indirectly_readable
48template<class In>
49concept indirectly_readable = see below; // since C++20
50
51template<indirectly_readable T>
52using iter_common_reference_t =
53common_reference_t<iter_reference_t<T>, iter_value_t<T>&>; // since C++20
54
55// [iterator.concept.writable], concept indirectly_writable
56template<class Out, class T>
57concept indirectly_writable = see below; // since C++20
58
59// [iterator.concept.winc], concept weakly_incrementable
60template<class I>
61concept weakly_incrementable = see below; // since C++20
62
63// [iterator.concept.inc], concept incrementable
64template<class I>
65concept incrementable = see below; // since C++20
66
67// [iterator.concept.iterator], concept input_or_output_iterator
68template<class I>
69concept input_or_output_iterator = see below; // since C++20
70
71// [iterator.concept.sentinel], concept sentinel_for
72template<class S, class I>
73concept sentinel_for = see below; // since C++20
74
75// [iterator.concept.sizedsentinel], concept sized_sentinel_for
76template<class S, class I>
77inline constexpr bool disable_sized_sentinel_for = false;
78
79template<class S, class I>
80concept sized_sentinel_for = see below;
81
82// [iterator.concept.input], concept input_iterator
83template<class I>
84concept input_iterator = see below; // since C++20
85
86// [iterator.concept.output], concept output_iterator
87template<class I, class T>
88concept output_iterator = see below; // since C++20
89
90// [iterator.concept.forward], concept forward_iterator
91template<class I>
92concept forward_iterator = see below; // since C++20
93
94// [iterator.concept.bidir], concept bidirectional_iterator
95template<class I>
96concept bidirectional_iterator = see below; // since C++20
97
98// [iterator.concept.random.access], concept random_access_iterator
99template<class I>
100concept random_access_iterator = see below; // since C++20
101
102// [indirectcallable]
103// [indirectcallable.indirectinvocable]
104template<class F, class I>
105concept indirectly_unary_invocable = see below; // since C++20
106
107template<class F, class I>
108concept indirectly_regular_unary_invocable = see below; // since C++20
109
110template<class F, class I>
111concept indirect_unary_predicate = see below; // since C++20
112
113template<class F, class I1, class I2>
114concept indirect_binary_predicate = see below; // since C++20
115
116template<class F, class I1, class I2 = I1>
117concept indirect_equivalence_relation = see below; // since C++20
118
119template<class F, class I1, class I2 = I1>
120concept indirect_strict_weak_order = see below; // since C++20
121
122template<class F, class... Is>
123using indirect_result_t = see below; // since C++20
124
125// [projected], projected
126template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
127struct projected; // since C++20
128
129template<weakly_incrementable I, indirectly_regular_unary_invocable<I> Proj>
130struct incrementable_traits<projected<I, Proj>>; // since C++20
131
132// [alg.req.ind.move], concept indirectly_movable
133template<class In, class Out>
134concept indirectly_movable = see below; // since C++20
135
136template<class In, class Out>
137concept indirectly_movable_storable = see below; // since C++20
138
139// [alg.req.ind.copy], concept indirectly_copyable
140template<class In, class Out>
141concept indirectly_copyable = see below; // since C++20
142
143template<class In, class Out>
144concept indirectly_copyable_storable = see below; // since C++20
145
146// [alg.req.ind.swap], concept indirectly_swappable
147template<class I1, class I2 = I1>
148concept indirectly_swappable = see below; // since C++20
149
150template<class I1, class I2, class R, class P1 = identity,
151class P2 = identity>
152concept indirectly_comparable =
153indirect_binary_predicate<R, projected<I1, P1>, projected<I2, P2>>; // since C++20
154
155// [alg.req.permutable], concept permutable
156template<class I>
157concept permutable = see below; // since C++20
158
159// [alg.req.mergeable], concept mergeable
160template<class I1, class I2, class Out,
161class R = ranges::less, class P1 = identity, class P2 = identity>
162concept mergeable = see below; // since C++20
163
164// [alg.req.sortable], concept sortable
165template<class I, class R = ranges::less, class P = identity>
166concept sortable = see below; // since C++20
167
168template<input_or_output_iterator I, sentinel_for<I> S>
169requires (!same_as<I, S> && copyable<I>)
170class common_iterator; // since C++20
171
172template<class Category, class T, class Distance = ptrdiff_t,
173class Pointer = T*, class Reference = T&>
174struct iterator // deprecated in C++17
175{
176typedef T value_type;
177typedef Distance difference_type;
178typedef Pointer pointer;
179typedef Reference reference;
180typedef Category iterator_category;
181};
182
183struct input_iterator_tag {};
184struct output_iterator_tag {};
185struct forward_iterator_tag : public input_iterator_tag {};
186struct bidirectional_iterator_tag : public forward_iterator_tag {};
187struct random_access_iterator_tag : public bidirectional_iterator_tag {};
188struct contiguous_iterator_tag : public random_access_iterator_tag {};
189
190// 27.4.3, iterator operations
191template <class InputIterator, class Distance> // constexpr in C++17
192constexpr void advance(InputIterator& i, Distance n);
193
194template <class InputIterator> // constexpr in C++17
195constexpr typename iterator_traits<InputIterator>::difference_type
196distance(InputIterator first, InputIterator last);
197
198template <class InputIterator> // constexpr in C++17
199constexpr InputIterator next(InputIterator x,
200typename iterator_traits<InputIterator>::difference_type n = 1);
201
202template <class BidirectionalIterator> // constexpr in C++17
203constexpr BidirectionalIterator prev(BidirectionalIterator x,
204typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
205
206// [range.iter.ops], range iterator operations
207namespace ranges {
208// [range.iter.op.advance], ranges::advance
209template<input_or_output_iterator I>
210constexpr void advance(I& i, iter_difference_t<I> n); // since C++20
211template<input_or_output_iterator I, sentinel_for<I> S>
212constexpr void advance(I& i, S bound); // since C++20
213template<input_or_output_iterator I, sentinel_for<I> S>
214constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound); // since C++20
215}
216
217template <class Iterator>
218class reverse_iterator
219: public iterator<typename iterator_traits<Iterator>::iterator_category, // until C++17
220typename iterator_traits<Iterator>::value_type,
221typename iterator_traits<Iterator>::difference_type,
222typename iterator_traits<Iterator>::pointer,
223typename iterator_traits<Iterator>::reference>
224{
225protected:
226Iterator current;
227public:
228using iterator_type = Iterator;
229using iterator_concept = see below; // since C++20
230using iterator_category = typename iterator_traits<Iterator>::iterator_category; // since C++17, until C++20
231using iterator_category = see below; // since C++20
232using value_type = typename iterator_traits<Iterator>::value_type; // since C++17, until C++20
233using value_type = iter_value_t<Iterator>; // since C++20
234using difference_type = typename iterator_traits<Iterator>::difference_type; // until C++20
235using difference_type = iter_difference_t<Iterator>; // since C++20
236using pointer = typename iterator_traits<Iterator>::pointer;
237using reference = typename iterator_traits<Iterator>::reference; // until C++20
238using reference = iter_reference_t<Iterator>; // since C++20
239
240constexpr reverse_iterator();
241constexpr explicit reverse_iterator(Iterator x);
242template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
243template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
244constexpr Iterator base() const;
245constexpr reference operator*() const;
246constexpr pointer operator->() const; // until C++20
247constexpr pointer operator->() const requires see below; // since C++20
248constexpr reverse_iterator& operator++();
249constexpr reverse_iterator operator++(int);
250constexpr reverse_iterator& operator--();
251constexpr reverse_iterator operator--(int);
252constexpr reverse_iterator operator+ (difference_type n) const;
253constexpr reverse_iterator& operator+=(difference_type n);
254constexpr reverse_iterator operator- (difference_type n) const;
255constexpr reverse_iterator& operator-=(difference_type n);
256constexpr unspecified operator[](difference_type n) const;
257
258friend constexpr iter_rvalue_reference_t<Iterator>
259iter_move(const reverse_iterator& i) noexcept(see below);
260template<indirectly_swappable<Iterator> Iterator2>
261friend constexpr void
262iter_swap(const reverse_iterator& x,
263const reverse_iterator<Iterator2>& y) noexcept(see below);
264};
265
266template <class Iterator1, class Iterator2>
267constexpr bool // constexpr in C++17
268operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
269
270template <class Iterator1, class Iterator2>
271constexpr bool // constexpr in C++17
272operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
273
274template <class Iterator1, class Iterator2>
275constexpr bool // constexpr in C++17
276operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
277
278template <class Iterator1, class Iterator2>
279constexpr bool // constexpr in C++17
280operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
281
282template <class Iterator1, class Iterator2>
283constexpr bool // constexpr in C++17
284operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
285
286template <class Iterator1, class Iterator2>
287constexpr bool // constexpr in C++17
288operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
289
290template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
291constexpr compare_three_way_result_t<Iterator1, Iterator2>
292operator<=>(const reverse_iterator<Iterator1>& x,
293const reverse_iterator<Iterator2>& y);
294
295template <class Iterator1, class Iterator2>
296constexpr auto
297operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
298-> decltype(__y.base() - __x.base()); // constexpr in C++17
299
300template <class Iterator>
301constexpr reverse_iterator<Iterator>
302operator+(typename reverse_iterator<Iterator>::difference_type n,
303const reverse_iterator<Iterator>& x); // constexpr in C++17
304
305template <class Iterator>
306constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
307
308template<class Iterator1, class Iterator2>
309requires (!sized_sentinel_for<Iterator1, Iterator2>)
310inline constexpr bool disable_sized_sentinel_for<reverse_iterator<Iterator1>,
311reverse_iterator<Iterator2>> = true;
312
313template <class Container>
314class back_insert_iterator
315: public iterator<output_iterator_tag, void, void, void, void> // until C++17
316{
317protected:
318Container* container;
319public:
320typedef Container container_type;
321typedef void value_type;
322typedef void difference_type; // until C++20
323typedef ptrdiff_t difference_type; // since C++20
324typedef void reference;
325typedef void pointer;
326
327explicit back_insert_iterator(Container& x); // constexpr in C++20
328back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
329back_insert_iterator& operator*(); // constexpr in C++20
330back_insert_iterator& operator++(); // constexpr in C++20
331back_insert_iterator operator++(int); // constexpr in C++20
332};
333
334template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20
335
336template <class Container>
337class front_insert_iterator
338: public iterator<output_iterator_tag, void, void, void, void> // until C++17
339{
340protected:
341Container* container;
342public:
343typedef Container container_type;
344typedef void value_type;
345typedef void difference_type; // until C++20
346typedef ptrdiff_t difference_type; // since C++20
347typedef void reference;
348typedef void pointer;
349
350explicit front_insert_iterator(Container& x); // constexpr in C++20
351front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
352front_insert_iterator& operator*(); // constexpr in C++20
353front_insert_iterator& operator++(); // constexpr in C++20
354front_insert_iterator operator++(int); // constexpr in C++20
355};
356
357template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20
358
359template <class Container>
360class insert_iterator
361: public iterator<output_iterator_tag, void, void, void, void> // until C++17
362{
363protected:
364Container* container;
365typename Container::iterator iter;
366public:
367typedef Container container_type;
368typedef void value_type;
369typedef void difference_type; // until C++20
370typedef ptrdiff_t difference_type; // since C++20
371typedef void reference;
372typedef void pointer;
373
374insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20
375insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20
376insert_iterator& operator*(); // constexpr in C++20
377insert_iterator& operator++(); // constexpr in C++20
378insert_iterator& operator++(int); // constexpr in C++20
379};
380
381template <class Container>
382insert_iterator<Container> inserter(Container& x, typename Container::iterator i); // until C++20
383template <class Container>
384constexpr insert_iterator<Container> inserter(Container& x, ranges::iterator_t<Container> i); // since C++20
385
386template <class Iterator>
387class move_iterator {
388public:
389using iterator_type = Iterator;
390using iterator_concept = see below; // From C++20
391using iterator_category = see below; // not always present starting from C++20
392using value_type = iter_value_t<Iterator>; // Until C++20, iterator_traits<Iterator>::value_type
393using difference_type = iter_difference_t<Iterator>; // Until C++20, iterator_traits<Iterator>::difference_type;
394using pointer = Iterator;
395using reference = iter_rvalue_reference_t<Iterator>; // Until C++20, value_type&&
396
397constexpr move_iterator(); // all the constexprs are in C++17
398constexpr explicit move_iterator(Iterator i);
399template <class U>
400constexpr move_iterator(const move_iterator<U>& u);
401template <class U>
402constexpr move_iterator& operator=(const move_iterator<U>& u);
403
404constexpr iterator_type base() const; // Until C++20
405constexpr const Iterator& base() const & noexcept; // From C++20
406constexpr Iterator base() &&; // From C++20
407
408constexpr reference operator*() const;
409constexpr pointer operator->() const; // Deprecated in C++20
410constexpr move_iterator& operator++();
411constexpr auto operator++(int); // Return type was move_iterator until C++20
412constexpr move_iterator& operator--();
413constexpr move_iterator operator--(int);
414constexpr move_iterator operator+(difference_type n) const;
415constexpr move_iterator& operator+=(difference_type n);
416constexpr move_iterator operator-(difference_type n) const;
417constexpr move_iterator& operator-=(difference_type n);
418constexpr reference operator[](difference_type n) const; // Return type unspecified until C++20
419
420template<sentinel_for<Iterator> S>
421friend constexpr bool
422operator==(const move_iterator& x, const move_sentinel<S>& y); // Since C++20
423template<sized_sentinel_for<Iterator> S>
424friend constexpr iter_difference_t<Iterator>
425operator-(const move_sentinel<S>& x, const move_iterator& y); // Since C++20
426template<sized_sentinel_for<Iterator> S>
427friend constexpr iter_difference_t<Iterator>
428operator-(const move_iterator& x, const move_sentinel<S>& y); // Since C++20
429friend constexpr iter_rvalue_reference_t<Iterator>
430iter_move(const move_iterator& i)
431noexcept(noexcept(ranges::iter_move(i.current))); // Since C++20
432template<indirectly_swappable<Iterator> Iterator2>
433friend constexpr void
434iter_swap(const move_iterator& x, const move_iterator<Iterator2>& y)
435noexcept(noexcept(ranges::iter_swap(x.current, y.current))); // Since C++20
436
437private:
438Iterator current; // exposition only
439};
440
441template <class Iterator1, class Iterator2>
442constexpr bool // constexpr in C++17
443operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
444
445template <class Iterator1, class Iterator2>
446constexpr bool // constexpr in C++17
447operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
448
449template <class Iterator1, class Iterator2>
450constexpr bool // constexpr in C++17
451operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
452
453template <class Iterator1, class Iterator2>
454constexpr bool // constexpr in C++17
455operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
456
457template <class Iterator1, class Iterator2>
458constexpr bool // constexpr in C++17
459operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
460
461template <class Iterator1, class Iterator2>
462constexpr bool // constexpr in C++17
463operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
464
465template <class Iterator1, class Iterator2>
466constexpr auto // constexpr in C++17
467operator-(const move_iterator<Iterator1>& x,
468const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
469
470template <class Iterator>
471constexpr move_iterator<Iterator> operator+( // constexpr in C++17
472typename move_iterator<Iterator>::difference_type n,
473const move_iterator<Iterator>& x);
474
475template <class Iterator> // constexpr in C++17
476constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
477
478template<class Iterator1, class Iterator2>
479requires (!sized_sentinel_for<Iterator1, Iterator2>)
480inline constexpr bool disable_sized_sentinel_for<move_iterator<Iterator1>, // since C++20
481move_iterator<Iterator2>> = true;
482
483template<semiregular S>
484class move_sentinel {
485public:
486constexpr move_sentinel();
487constexpr explicit move_sentinel(S s);
488template<class S2>
489requires convertible_to<const S2&, S>
490constexpr move_sentinel(const move_sentinel<S2>& s);
491template<class S2>
492requires assignable_from<S&, const S2&>
493constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
494
495constexpr S base() const;
496private:
497S last; // exposition only
498};
499
500// [default.sentinel], default sentinel
501struct default_sentinel_t;
502inline constexpr default_sentinel_t default_sentinel{};
503
504// [iterators.counted], counted iterators
505template<input_or_output_iterator I> class counted_iterator;
506
507template<input_iterator I>
508requires see below
509struct iterator_traits<counted_iterator<I>>;
510
511// [unreachable.sentinel], unreachable sentinel
512struct unreachable_sentinel_t;
513inline constexpr unreachable_sentinel_t unreachable_sentinel{};
514
515template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
516class istream_iterator
517: public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17
518{
519public:
520typedef input_iterator_tag iterator_category;
521typedef T value_type;
522typedef Distance difference_type;
523typedef const T* pointer;
524typedef const T& reference;
525
526typedef charT char_type;
527typedef traits traits_type;
528typedef basic_istream<charT, traits> istream_type;
529
530istream_iterator(); // constexpr since C++11
531constexpr istream_iterator(default_sentinel_t); // since C++20
532istream_iterator(istream_type& s);
533istream_iterator(const istream_iterator& x);
534~istream_iterator();
535
536const T& operator*() const;
537const T* operator->() const;
538istream_iterator& operator++();
539istream_iterator operator++(int);
540friend bool operator==(const istream_iterator& i, default_sentinel_t); // since C++20
541};
542
543template <class T, class charT, class traits, class Distance>
544bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
545const istream_iterator<T,charT,traits,Distance>& y);
546template <class T, class charT, class traits, class Distance>
547bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
548const istream_iterator<T,charT,traits,Distance>& y); // until C++20
549
550template <class T, class charT = char, class traits = char_traits<charT> >
551class ostream_iterator
552: public iterator<output_iterator_tag, void, void, void, void> // until C++17
553{
554public:
555typedef output_iterator_tag iterator_category;
556typedef void value_type;
557typedef void difference_type; // until C++20
558typedef ptrdiff_t difference_type; // since C++20
559typedef void pointer;
560typedef void reference;
561
562typedef charT char_type;
563typedef traits traits_type;
564typedef basic_ostream<charT,traits> ostream_type;
565
566ostream_iterator(ostream_type& s);
567ostream_iterator(ostream_type& s, const charT* delimiter);
568ostream_iterator(const ostream_iterator& x);
569~ostream_iterator();
570ostream_iterator& operator=(const T& value);
571
572ostream_iterator& operator*();
573ostream_iterator& operator++();
574ostream_iterator& operator++(int);
575};
576
577template<class charT, class traits = char_traits<charT> >
578class istreambuf_iterator
579: public iterator<input_iterator_tag, charT, traits::off_type, unspecified, charT> // until C++17
580{
581public:
582typedef input_iterator_tag iterator_category;
583typedef charT value_type;
584typedef traits::off_type difference_type;
585typedef unspecified pointer;
586typedef charT reference;
587
588typedef charT char_type;
589typedef traits traits_type;
590typedef traits::int_type int_type;
591typedef basic_streambuf<charT, traits> streambuf_type;
592typedef basic_istream<charT, traits> istream_type;
593
594istreambuf_iterator() noexcept; // constexpr since C++11
595constexpr istreambuf_iterator(default_sentinel_t) noexcept; // since C++20
596istreambuf_iterator(istream_type& s) noexcept;
597istreambuf_iterator(streambuf_type* s) noexcept;
598istreambuf_iterator(a-private-type) noexcept;
599
600charT operator*() const;
601pointer operator->() const;
602istreambuf_iterator& operator++();
603a-private-type operator++(int);
604
605bool equal(const istreambuf_iterator& b) const;
606friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s); // since C++20
607};
608
609template <class charT, class traits>
610bool operator==(const istreambuf_iterator<charT,traits>& a,
611const istreambuf_iterator<charT,traits>& b);
612template <class charT, class traits>
613bool operator!=(const istreambuf_iterator<charT,traits>& a,
614const istreambuf_iterator<charT,traits>& b); // until C++20
615
616template <class charT, class traits = char_traits<charT> >
617class ostreambuf_iterator
618: public iterator<output_iterator_tag, void, void, void, void> // until C++17
619{
620public:
621typedef output_iterator_tag iterator_category;
622typedef void value_type;
623typedef void difference_type; // until C++20
624typedef ptrdiff_t difference_type; // since C++20
625typedef void pointer;
626typedef void reference;
627
628typedef charT char_type;
629typedef traits traits_type;
630typedef basic_streambuf<charT, traits> streambuf_type;
631typedef basic_ostream<charT, traits> ostream_type;
632
633ostreambuf_iterator(ostream_type& s) noexcept;
634ostreambuf_iterator(streambuf_type* s) noexcept;
635ostreambuf_iterator& operator=(charT c);
636ostreambuf_iterator& operator*();
637ostreambuf_iterator& operator++();
638ostreambuf_iterator& operator++(int);
639bool failed() const noexcept;
640};
641
642template <class C> constexpr auto begin(C& c) -> decltype(c.begin()); // constexpr since C++17
643template <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); // constexpr since C++17
644template <class C> constexpr auto end(C& c) -> decltype(c.end()); // constexpr since C++17
645template <class C> constexpr auto end(const C& c) -> decltype(c.end()); // constexpr since C++17
646template <class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
647template <class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
648
649template <class C> constexpr auto cbegin(const C& c) noexcept(see-below) -> decltype(std::begin(c)); // C++14
650template <class C> constexpr auto cend(const C& c) noexcept(see-below) -> decltype(std::end(c)); // C++14
651template <class C> constexpr auto rbegin(C& c) -> decltype(c.rbegin()); // C++14, constexpr since C++17
652template <class C> constexpr auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14, constexpr since C++17
653template <class C> constexpr auto rend(C& c) -> decltype(c.rend()); // C++14, constexpr since C++17
654template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14, constexpr since C++17
655template <class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14, constexpr since C++17
656template <class E> constexpr reverse_iterator<const E*> rend(initializer_list<E> il); // C++14, constexpr since C++17
657template <class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&array)[N]); // C++14, constexpr since C++17
658template <class T, size_t N> constexpr reverse_iterator<T*> rend(T (&array)[N]); // C++14, constexpr since C++17
659template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14, constexpr since C++17
660template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14, constexpr since C++17
661
662// 24.8, container access:
663template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
664template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
665
666template <class C> constexpr auto ssize(const C& c)
667-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
668template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
669
670template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
671template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
672template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
673template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
674template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
675template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
676template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
677
678} // std
679
680*/
681
682#include <__config>
683#include <__iterator/access.h>
684#include <__iterator/advance.h>
685#include <__iterator/back_insert_iterator.h>
686#include <__iterator/bounded_iter.h>
687#include <__iterator/common_iterator.h>
688#include <__iterator/concepts.h>
689#include <__iterator/counted_iterator.h>
690#include <__iterator/data.h>
691#include <__iterator/default_sentinel.h>
692#include <__iterator/distance.h>
693#include <__iterator/empty.h>
694#include <__iterator/erase_if_container.h>
695#include <__iterator/front_insert_iterator.h>
696#include <__iterator/incrementable_traits.h>
697#include <__iterator/indirectly_comparable.h>
698#include <__iterator/insert_iterator.h>
699#include <__iterator/istream_iterator.h>
700#include <__iterator/istreambuf_iterator.h>
701#include <__iterator/iter_move.h>
702#include <__iterator/iter_swap.h>
703#include <__iterator/iterator.h>
704#include <__iterator/iterator_traits.h>
705#include <__iterator/mergeable.h>
706#include <__iterator/move_iterator.h>
707#include <__iterator/move_sentinel.h>
708#include <__iterator/next.h>
709#include <__iterator/ostream_iterator.h>
710#include <__iterator/ostreambuf_iterator.h>
711#include <__iterator/permutable.h>
712#include <__iterator/prev.h>
713#include <__iterator/projected.h>
714#include <__iterator/readable_traits.h>
715#include <__iterator/reverse_access.h>
716#include <__iterator/reverse_iterator.h>
717#include <__iterator/size.h>
718#include <__iterator/sortable.h>
719#include <__iterator/unreachable_sentinel.h>
720#include <__iterator/wrap_iter.h>
721#include <__memory/addressof.h>
722#include <__memory/pointer_traits.h>
723#include <version>
724
725// standard-mandated includes
726
727// [iterator.synopsis]
728#include <compare>
729#include <concepts>
730
731#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
732# pragma GCC system_header
733#endif
734
735#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
736# include <cstdlib>
737# include <exception>
738# include <new>
739# include <type_traits>
740# include <typeinfo>
741# include <utility>
742#endif
743
744#endif // _LIBCPP_ITERATOR
745